@openclaw/slack 2026.10.5-beta.1 → 2026.10.5-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/node_modules/@slack/bolt/node_modules/@slack/socket-mode/dist/package.json +4 -4
  2. package/node_modules/@slack/bolt/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.d.ts.map +1 -1
  3. package/node_modules/@slack/bolt/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js +9 -17
  4. package/node_modules/@slack/bolt/node_modules/@slack/socket-mode/dist/src/SlackWebSocket.js.map +1 -1
  5. package/node_modules/@slack/bolt/node_modules/@slack/socket-mode/package.json +4 -4
  6. package/node_modules/@slack/bolt/node_modules/@types/node/README.md +2 -2
  7. package/node_modules/@slack/bolt/node_modules/@types/node/crypto.d.ts +2 -2
  8. package/node_modules/@slack/bolt/node_modules/@types/node/dgram.d.ts +1 -1
  9. package/node_modules/@slack/bolt/node_modules/@types/node/package.json +2 -17
  10. package/node_modules/@slack/bolt/node_modules/@types/node/zlib.d.ts +6 -0
  11. package/node_modules/@slack/web-api/node_modules/@types/node/README.md +1 -1
  12. package/node_modules/@slack/web-api/node_modules/@types/node/crypto.d.ts +2 -2
  13. package/node_modules/@slack/web-api/node_modules/@types/node/dgram.d.ts +1 -1
  14. package/node_modules/@slack/web-api/node_modules/@types/node/package.json +2 -2
  15. package/node_modules/@slack/web-api/node_modules/@types/node/zlib.d.ts +6 -0
  16. package/package.json +4 -4
  17. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/LICENSE +0 -21
  18. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/README.md +0 -15
  19. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/assert/strict.d.ts +0 -68
  20. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/assert.d.ts +0 -1077
  21. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/async_hooks.d.ts +0 -711
  22. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/buffer.buffer.d.ts +0 -471
  23. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/buffer.d.ts +0 -1800
  24. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/child_process.d.ts +0 -1361
  25. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/cluster.d.ts +0 -432
  26. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/console.d.ts +0 -93
  27. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/constants.d.ts +0 -14
  28. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/crypto.d.ts +0 -3964
  29. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/dgram.d.ts +0 -652
  30. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/diagnostics_channel.d.ts +0 -794
  31. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/dns/promises.d.ts +0 -497
  32. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/dns.d.ts +0 -876
  33. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/domain.d.ts +0 -150
  34. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/events.d.ts +0 -1008
  35. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ffi.d.ts +0 -500
  36. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/fs/promises.d.ts +0 -1477
  37. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/fs.d.ts +0 -4803
  38. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/globals.d.ts +0 -150
  39. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/globals.typedarray.d.ts +0 -101
  40. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/http.d.ts +0 -2218
  41. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/http2.d.ts +0 -2498
  42. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/https.d.ts +0 -400
  43. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/index.d.ts +0 -116
  44. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/inspector/promises.d.ts +0 -35
  45. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/inspector.d.ts +0 -265
  46. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/inspector.generated.d.ts +0 -4406
  47. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/module.d.ts +0 -726
  48. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/net.d.ts +0 -1074
  49. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/os.d.ts +0 -498
  50. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/package.json +0 -155
  51. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/path/posix.d.ts +0 -8
  52. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/path/win32.d.ts +0 -8
  53. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/path.d.ts +0 -178
  54. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/perf_hooks.d.ts +0 -617
  55. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/process.d.ts +0 -2269
  56. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/punycode.d.ts +0 -89
  57. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/querystring.d.ts +0 -139
  58. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/quic.d.ts +0 -2191
  59. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/readline/promises.d.ts +0 -158
  60. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/readline.d.ts +0 -508
  61. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/repl.d.ts +0 -420
  62. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/sea.d.ts +0 -47
  63. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/sqlite.d.ts +0 -1140
  64. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/stream/consumers.d.ts +0 -114
  65. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/stream/iter.d.ts +0 -449
  66. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/stream/promises.d.ts +0 -211
  67. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/stream/web.d.ts +0 -320
  68. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/stream.d.ts +0 -1806
  69. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/string_decoder.d.ts +0 -27
  70. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/test/reporters.d.ts +0 -60
  71. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/test.d.ts +0 -2558
  72. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/timers/promises.d.ts +0 -93
  73. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/timers.d.ts +0 -149
  74. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/tls.d.ts +0 -1232
  75. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/trace_events.d.ts +0 -103
  76. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +0 -467
  77. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +0 -71
  78. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -36
  79. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ts5.6/index.d.ts +0 -118
  80. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +0 -72
  81. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/ts5.7/index.d.ts +0 -118
  82. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/tty.d.ts +0 -226
  83. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/url.d.ts +0 -556
  84. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/util/types.d.ts +0 -558
  85. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/util.d.ts +0 -1677
  86. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/v8.d.ts +0 -1059
  87. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/vfs.d.ts +0 -211
  88. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/vm.d.ts +0 -1137
  89. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/wasi.d.ts +0 -131
  90. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/abortcontroller.d.ts +0 -59
  91. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/blob.d.ts +0 -23
  92. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/console.d.ts +0 -9
  93. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/crypto.d.ts +0 -39
  94. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/domexception.d.ts +0 -83
  95. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/encoding.d.ts +0 -11
  96. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/events.d.ts +0 -106
  97. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/fetch.d.ts +0 -69
  98. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/importmeta.d.ts +0 -13
  99. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/messaging.d.ts +0 -23
  100. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/navigator.d.ts +0 -25
  101. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/performance.d.ts +0 -45
  102. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/storage.d.ts +0 -24
  103. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/streams.d.ts +0 -119
  104. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/timers.d.ts +0 -44
  105. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/web-globals/url.d.ts +0 -24
  106. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/worker_threads.d.ts +0 -672
  107. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/zlib/iter.d.ts +0 -131
  108. package/node_modules/@slack/web-api/node_modules/@slack/logger/node_modules/@types/node/zlib.d.ts +0 -606
@@ -1,3964 +0,0 @@
1
- declare module "node:crypto" {
2
- import { NonSharedBuffer } from "node:buffer";
3
- import { Transform, TransformOptions, Writable, WritableOptions } from "node:stream";
4
- import { PeerCertificate } from "node:tls";
5
- /**
6
- * SPKAC is a Certificate Signing Request mechanism originally implemented by
7
- * Netscape and was specified formally as part of HTML5's `keygen` element.
8
- *
9
- * `<keygen>` is deprecated since [HTML 5.2](https://www.w3.org/TR/html52/changes.html#features-removed) and new projects
10
- * should not use this element anymore.
11
- *
12
- * The `node:crypto` module provides the `Certificate` class for working with SPKAC
13
- * data. The most common usage is handling output generated by the HTML5 `<keygen>` element. Node.js uses [OpenSSL's SPKAC
14
- * implementation](https://www.openssl.org/docs/man3.0/man1/openssl-spkac.html) internally.
15
- * @since v0.11.8
16
- */
17
- class Certificate {
18
- /**
19
- * ```js
20
- * const { Certificate } = await import('node:crypto');
21
- * const spkac = getSpkacSomehow();
22
- * const challenge = Certificate.exportChallenge(spkac);
23
- * console.log(challenge.toString('utf8'));
24
- * // Prints: the challenge as a UTF8 string
25
- * ```
26
- * @since v9.0.0
27
- * @param encoding The `encoding` of the `spkac` string.
28
- * @return The challenge component of the `spkac` data structure, which includes a public key and a challenge.
29
- */
30
- static exportChallenge(spkac: BinaryLike, encoding?: BufferEncoding): NonSharedBuffer;
31
- /**
32
- * ```js
33
- * const { Certificate } = await import('node:crypto');
34
- * const spkac = getSpkacSomehow();
35
- * const publicKey = Certificate.exportPublicKey(spkac);
36
- * console.log(publicKey);
37
- * // Prints: the public key as <Buffer ...>
38
- * ```
39
- * @since v9.0.0
40
- * @param encoding The `encoding` of the `spkac` string.
41
- * @return The public key component of the `spkac` data structure, which includes a public key and a challenge.
42
- */
43
- static exportPublicKey(spkac: BinaryLike, encoding?: BufferEncoding): NonSharedBuffer;
44
- /**
45
- * ```js
46
- * import { Buffer } from 'node:buffer';
47
- * const { Certificate } = await import('node:crypto');
48
- *
49
- * const spkac = getSpkacSomehow();
50
- * console.log(Certificate.verifySpkac(Buffer.from(spkac)));
51
- * // Prints: true or false
52
- * ```
53
- * @since v9.0.0
54
- * @param encoding The `encoding` of the `spkac` string.
55
- * @return `true` if the given `spkac` data structure is valid, `false` otherwise.
56
- */
57
- static verifySpkac(spkac: BinaryLike, encoding?: BufferEncoding): boolean;
58
- /**
59
- * @deprecated
60
- * @param encoding The `encoding` of the `spkac` string.
61
- * @returns The challenge component of the `spkac` data structure,
62
- * which includes a public key and a challenge.
63
- */
64
- exportChallenge(spkac: BinaryLike, encoding?: BufferEncoding): NonSharedBuffer;
65
- /**
66
- * @deprecated
67
- * @param encoding The encoding of the spkac string.
68
- * @returns The public key component of the `spkac` data structure,
69
- * which includes a public key and a challenge.
70
- */
71
- exportPublicKey(spkac: BinaryLike, encoding?: BufferEncoding): NonSharedBuffer;
72
- /**
73
- * @deprecated
74
- * @param encoding The `encoding` of the `spkac` string.
75
- * @returns `true` if the given `spkac` data structure is valid,
76
- * `false` otherwise.
77
- */
78
- verifySpkac(spkac: BinaryLike, encoding?: BufferEncoding): boolean;
79
- }
80
- /** @deprecated This property is deprecated. Please use `crypto.setFips()` and `crypto.getFips()` instead. */
81
- var fips: boolean;
82
- interface HashOptions extends TransformOptions {
83
- outputLength?: number | undefined;
84
- }
85
- /**
86
- * Creates and returns a `Hash` object that can be used to generate hash digests
87
- * using the given `algorithm`. Optional `options` argument controls stream
88
- * behavior. For XOF hash functions such as `'shake256'`, the `outputLength` option
89
- * can be used to specify the desired output length in bytes.
90
- *
91
- * When the data is small (< 5MB) and readily available, `crypto.hash()` is usually faster.
92
- *
93
- * The `algorithm` is dependent on the available algorithms supported by the
94
- * version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
95
- * On recent releases of OpenSSL, `openssl list -digest-algorithms` will
96
- * display the available digest algorithms.
97
- *
98
- * Example: generating the sha256 sum of a file
99
- *
100
- * ```js
101
- * import {
102
- * createReadStream,
103
- * } from 'node:fs';
104
- * import { argv } from 'node:process';
105
- * const {
106
- * createHash,
107
- * } = await import('node:crypto');
108
- *
109
- * const filename = argv[2];
110
- *
111
- * const hash = createHash('sha256');
112
- *
113
- * const input = createReadStream(filename);
114
- * input.on('readable', () => {
115
- * // Only one element is going to be produced by the
116
- * // hash stream.
117
- * const data = input.read();
118
- * if (data)
119
- * hash.update(data);
120
- * else {
121
- * console.log(`${hash.digest('hex')} ${filename}`);
122
- * }
123
- * });
124
- * ```
125
- * @since v0.1.92
126
- * @param options `stream.transform` options
127
- */
128
- function createHash(algorithm: string, options?: HashOptions): Hash;
129
- interface HmacOptions extends TransformOptions {
130
- encoding?: BufferEncoding | undefined;
131
- }
132
- /**
133
- * Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
134
- * Optional `options` argument controls stream behavior.
135
- *
136
- * The `algorithm` is dependent on the available algorithms supported by the
137
- * version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
138
- * On recent releases of OpenSSL, `openssl list -digest-algorithms` will
139
- * display the available digest algorithms.
140
- *
141
- * The `key` is the HMAC key used to generate the cryptographic HMAC hash. If it is
142
- * a `KeyObject`, its type must be `secret`. If it is a string, please consider `caveats when using strings as inputs to cryptographic APIs`. If it was
143
- * obtained from a cryptographically secure source of entropy, such as {@link randomBytes} or {@link generateKey}, its length should not
144
- * exceed the block size of `algorithm` (e.g., 512 bits for SHA-256).
145
- *
146
- * Example: generating the sha256 HMAC of a file
147
- *
148
- * ```js
149
- * import {
150
- * createReadStream,
151
- * } from 'node:fs';
152
- * import { argv } from 'node:process';
153
- * const {
154
- * createHmac,
155
- * } = await import('node:crypto');
156
- *
157
- * const filename = argv[2];
158
- *
159
- * const hmac = createHmac('sha256', 'a secret');
160
- *
161
- * const input = createReadStream(filename);
162
- * input.on('readable', () => {
163
- * // Only one element is going to be produced by the
164
- * // hash stream.
165
- * const data = input.read();
166
- * if (data)
167
- * hmac.update(data);
168
- * else {
169
- * console.log(`${hmac.digest('hex')} ${filename}`);
170
- * }
171
- * });
172
- * ```
173
- * @since v0.1.94
174
- * @param options `stream.transform` options
175
- */
176
- function createHmac(algorithm: string, key: KeyLike, options?: HmacOptions): Hmac;
177
- /**
178
- * The `Hash` class is a utility for creating hash digests of data. It can be
179
- * used in one of two ways:
180
- *
181
- * * As a `stream` that is both readable and writable, where data is written
182
- * to produce a computed hash digest on the readable side, or
183
- * * Using the `hash.update()` and `hash.digest()` methods to produce the
184
- * computed hash.
185
- *
186
- * The {@link createHash} method is used to create `Hash` instances. `Hash`objects are not to be created directly using the `new` keyword.
187
- *
188
- * Example: Using `Hash` objects as streams:
189
- *
190
- * ```js
191
- * const {
192
- * createHash,
193
- * } = await import('node:crypto');
194
- *
195
- * const hash = createHash('sha256');
196
- *
197
- * hash.on('readable', () => {
198
- * // Only one element is going to be produced by the
199
- * // hash stream.
200
- * const data = hash.read();
201
- * if (data) {
202
- * console.log(data.toString('hex'));
203
- * // Prints:
204
- * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
205
- * }
206
- * });
207
- *
208
- * hash.write('some data to hash');
209
- * hash.end();
210
- * ```
211
- *
212
- * Example: Using `Hash` and piped streams:
213
- *
214
- * ```js
215
- * import { createReadStream } from 'node:fs';
216
- * import { stdout } from 'node:process';
217
- * const { createHash } = await import('node:crypto');
218
- *
219
- * const hash = createHash('sha256');
220
- *
221
- * const input = createReadStream('test.js');
222
- * input.pipe(hash).setEncoding('hex').pipe(stdout);
223
- * ```
224
- *
225
- * Example: Using the `hash.update()` and `hash.digest()` methods:
226
- *
227
- * ```js
228
- * const {
229
- * createHash,
230
- * } = await import('node:crypto');
231
- *
232
- * const hash = createHash('sha256');
233
- *
234
- * hash.update('some data to hash');
235
- * console.log(hash.digest('hex'));
236
- * // Prints:
237
- * // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
238
- * ```
239
- * @since v0.1.92
240
- */
241
- class Hash extends Transform {
242
- private constructor();
243
- /**
244
- * Creates a new `Hash` object that contains a deep copy of the internal state
245
- * of the current `Hash` object.
246
- *
247
- * The optional `options` argument controls stream behavior. For XOF hash
248
- * functions such as `'shake256'`, the `outputLength` option can be used to
249
- * specify the desired output length in bytes.
250
- *
251
- * An error is thrown when an attempt is made to copy the `Hash` object after
252
- * its `hash.digest()` method has been called.
253
- *
254
- * ```js
255
- * // Calculate a rolling hash.
256
- * const {
257
- * createHash,
258
- * } = await import('node:crypto');
259
- *
260
- * const hash = createHash('sha256');
261
- *
262
- * hash.update('one');
263
- * console.log(hash.copy().digest('hex'));
264
- *
265
- * hash.update('two');
266
- * console.log(hash.copy().digest('hex'));
267
- *
268
- * hash.update('three');
269
- * console.log(hash.copy().digest('hex'));
270
- *
271
- * // Etc.
272
- * ```
273
- * @since v13.1.0
274
- * @param options `stream.transform` options
275
- */
276
- copy(options?: HashOptions): Hash;
277
- /**
278
- * Updates the hash content with the given `data`, the encoding of which
279
- * is given in `inputEncoding`.
280
- * If `encoding` is not provided, and the `data` is a string, an
281
- * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
282
- *
283
- * This can be called many times with new data as it is streamed.
284
- * @since v0.1.92
285
- * @param inputEncoding The `encoding` of the `data` string.
286
- */
287
- update(data: string | NodeJS.ArrayBufferView, inputEncoding?: BufferEncoding): Hash;
288
- /**
289
- * Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
290
- * If `encoding` is provided a string will be returned; otherwise
291
- * a `Buffer` is returned.
292
- *
293
- * The `Hash` object can not be used again after `hash.digest()` method has been
294
- * called. Multiple calls will cause an error to be thrown.
295
- * @since v0.1.92
296
- * @param encoding The `encoding` of the return value.
297
- */
298
- digest(): NonSharedBuffer;
299
- digest(encoding: BufferEncoding): string;
300
- }
301
- /**
302
- * The `Hmac` class is a utility for creating cryptographic HMAC digests. It can
303
- * be used in one of two ways:
304
- *
305
- * * As a `stream` that is both readable and writable, where data is written
306
- * to produce a computed HMAC digest on the readable side, or
307
- * * Using the `hmac.update()` and `hmac.digest()` methods to produce the
308
- * computed HMAC digest.
309
- *
310
- * The {@link createHmac} method is used to create `Hmac` instances. `Hmac`objects are not to be created directly using the `new` keyword.
311
- *
312
- * Example: Using `Hmac` objects as streams:
313
- *
314
- * ```js
315
- * const {
316
- * createHmac,
317
- * } = await import('node:crypto');
318
- *
319
- * const hmac = createHmac('sha256', 'a secret');
320
- *
321
- * hmac.on('readable', () => {
322
- * // Only one element is going to be produced by the
323
- * // hash stream.
324
- * const data = hmac.read();
325
- * if (data) {
326
- * console.log(data.toString('hex'));
327
- * // Prints:
328
- * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
329
- * }
330
- * });
331
- *
332
- * hmac.write('some data to hash');
333
- * hmac.end();
334
- * ```
335
- *
336
- * Example: Using `Hmac` and piped streams:
337
- *
338
- * ```js
339
- * import { createReadStream } from 'node:fs';
340
- * import { stdout } from 'node:process';
341
- * const {
342
- * createHmac,
343
- * } = await import('node:crypto');
344
- *
345
- * const hmac = createHmac('sha256', 'a secret');
346
- *
347
- * const input = createReadStream('test.js');
348
- * input.pipe(hmac).pipe(stdout);
349
- * ```
350
- *
351
- * Example: Using the `hmac.update()` and `hmac.digest()` methods:
352
- *
353
- * ```js
354
- * const {
355
- * createHmac,
356
- * } = await import('node:crypto');
357
- *
358
- * const hmac = createHmac('sha256', 'a secret');
359
- *
360
- * hmac.update('some data to hash');
361
- * console.log(hmac.digest('hex'));
362
- * // Prints:
363
- * // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
364
- * ```
365
- * @since v0.1.94
366
- */
367
- class Hmac extends Transform {
368
- private constructor();
369
- /**
370
- * Updates the `Hmac` content with the given `data`, the encoding of which
371
- * is given in `inputEncoding`.
372
- * If `encoding` is not provided, and the `data` is a string, an
373
- * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
374
- *
375
- * This can be called many times with new data as it is streamed.
376
- * @since v0.1.94
377
- * @param inputEncoding The `encoding` of the `data` string.
378
- */
379
- update(data: string | NodeJS.ArrayBufferView, inputEncoding?: BufferEncoding): Hmac;
380
- /**
381
- * Calculates the HMAC digest of all of the data passed using `hmac.update()`.
382
- * If `encoding` is
383
- * provided a string is returned; otherwise a `Buffer` is returned;
384
- *
385
- * The `Hmac` object can not be used again after `hmac.digest()` has been
386
- * called. Multiple calls to `hmac.digest()` will result in an error being thrown.
387
- * @since v0.1.94
388
- * @param encoding The `encoding` of the return value.
389
- */
390
- digest(): NonSharedBuffer;
391
- digest(encoding: BufferEncoding): string;
392
- }
393
- type KeyFormat = "pem" | "der" | "jwk" | "raw-public" | "raw-private" | "raw-seed";
394
- type KeyObjectType = "secret" | "public" | "private";
395
- type PublicKeyExportType = "pkcs1" | "spki";
396
- type PrivateKeyExportType = "pkcs1" | "pkcs8" | "sec1";
397
- type KeyExportOptions =
398
- | SymmetricKeyExportOptions
399
- | PublicKeyExportOptions
400
- | PrivateKeyExportOptions
401
- | JwkKeyExportOptions
402
- | RawPublicKeyExportOptions
403
- | RawPrivateKeyExportOptions;
404
- interface SymmetricKeyExportOptions {
405
- format?: "buffer" | undefined;
406
- }
407
- interface PublicKeyExportOptions<T extends PublicKeyExportType = PublicKeyExportType> {
408
- type: T;
409
- format: "pem" | "der";
410
- }
411
- interface PrivateKeyExportOptions<T extends PrivateKeyExportType = PrivateKeyExportType> {
412
- type: T;
413
- format: "pem" | "der";
414
- cipher?: string | undefined;
415
- passphrase?: BinaryLike | undefined;
416
- }
417
- interface JwkKeyExportOptions {
418
- format: "jwk";
419
- }
420
- interface RawPublicKeyExportOptions {
421
- format: "raw-public";
422
- }
423
- interface RawPrivateKeyExportOptions {
424
- format: "raw-private" | "raw-seed";
425
- }
426
- interface KeyPairExportOptions<
427
- TPublic extends PublicKeyExportType = PublicKeyExportType,
428
- TPrivate extends PrivateKeyExportType = PrivateKeyExportType,
429
- > {
430
- publicKeyEncoding?:
431
- | PublicKeyExportOptions<TPublic>
432
- | RawPublicKeyExportOptions
433
- | JwkKeyExportOptions
434
- | undefined;
435
- privateKeyEncoding?:
436
- | PrivateKeyExportOptions<TPrivate>
437
- | RawPrivateKeyExportOptions
438
- | JwkKeyExportOptions
439
- | undefined;
440
- }
441
- type KeyExportResult<T, Default> = T extends { format: infer F extends KeyFormat } ? {
442
- "der": NonSharedBuffer;
443
- "jwk": webcrypto.JsonWebKey;
444
- "pem": string;
445
- "raw-public": NonSharedBuffer;
446
- "raw-private": NonSharedBuffer;
447
- "raw-seed": NonSharedBuffer;
448
- }[F]
449
- : Default;
450
- interface KeyPairExportResult<T extends KeyPairExportOptions> {
451
- publicKey: KeyExportResult<T["publicKeyEncoding"], KeyObject>;
452
- privateKey: KeyExportResult<T["privateKeyEncoding"], KeyObject>;
453
- }
454
- type KeyPairExportCallback<T extends KeyPairExportOptions = {}> = (
455
- err: Error | null,
456
- publicKey: KeyExportResult<T["publicKeyEncoding"], KeyObject>,
457
- privateKey: KeyExportResult<T["privateKeyEncoding"], KeyObject>,
458
- ) => void;
459
- type MLDSAKeyType = `ml-dsa-${44 | 65 | 87}`;
460
- type MLKEMKeyType = `ml-kem-${1024 | 512 | 768}`;
461
- type SLHDSAKeyType = `slh-dsa-${"sha2" | "shake"}-${128 | 192 | 256}${"f" | "s"}`;
462
- type AsymmetricKeyType =
463
- | "dh"
464
- | "dsa"
465
- | "ec"
466
- | "ed25519"
467
- | "ed448"
468
- | MLDSAKeyType
469
- | MLKEMKeyType
470
- | "rsa-pss"
471
- | "rsa"
472
- | SLHDSAKeyType
473
- | "x25519"
474
- | "x448";
475
- interface AsymmetricKeyDetails {
476
- modulusLength?: number;
477
- publicExponent?: bigint;
478
- hashAlgorithm?: string;
479
- mgf1HashAlgorithm?: string;
480
- saltLength?: number;
481
- divisorLength?: number;
482
- namedCurve?: string;
483
- }
484
- /**
485
- * Node.js uses a `KeyObject` class to represent a symmetric or asymmetric key,
486
- * and each kind of key exposes different functions. The {@link createSecretKey}, {@link createPublicKey} and {@link createPrivateKey} methods are used to create `KeyObject`instances. `KeyObject`
487
- * objects are not to be created directly using the `new`keyword.
488
- *
489
- * Most applications should consider using the new `KeyObject` API instead of
490
- * passing keys as strings or `Buffer`s due to improved security features.
491
- *
492
- * `KeyObject` instances can be passed to other threads via `postMessage()`.
493
- * The receiver obtains a cloned `KeyObject`, and the `KeyObject` does not need to
494
- * be listed in the `transferList` argument.
495
- * @since v11.6.0
496
- */
497
- class KeyObject {
498
- private constructor();
499
- /**
500
- * Returns the underlying `KeyObject` of a `CryptoKey`. The returned `KeyObject`
501
- * does not retain any of the restrictions imposed by the Web Crypto API on the
502
- * original `CryptoKey`, such as the allowed key usages, the algorithm or hash
503
- * algorithm bindings, and the extractability flag. In particular, the underlying
504
- * key material of the returned `KeyObject` can always be exported.
505
- *
506
- * ```js
507
- * const { KeyObject } = await import('node:crypto');
508
- * const { subtle } = globalThis.crypto;
509
- *
510
- * const key = await subtle.generateKey({
511
- * name: 'HMAC',
512
- * hash: 'SHA-256',
513
- * length: 256,
514
- * }, true, ['sign', 'verify']);
515
- *
516
- * const keyObject = KeyObject.from(key);
517
- * console.log(keyObject.symmetricKeySize);
518
- * // Prints: 32 (symmetric key size in bytes)
519
- * ```
520
- * @since v15.0.0
521
- */
522
- static from(key: webcrypto.CryptoKey): KeyObject;
523
- /**
524
- * For asymmetric keys, this property represents the type of the key. See the
525
- * supported [asymmetric key types](https://nodejs.org/docs/latest-v26.x/api/crypto.html#asymmetric-key-types).
526
- *
527
- * This property is `undefined` for unrecognized `KeyObject` types and symmetric
528
- * keys.
529
- * @since v11.6.0
530
- */
531
- asymmetricKeyType?: AsymmetricKeyType;
532
- /**
533
- * This property exists only on asymmetric keys. Depending on the type of the key,
534
- * this object contains information about the key. None of the information obtained
535
- * through this property can be used to uniquely identify a key or to compromise
536
- * the security of the key.
537
- *
538
- * For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence,
539
- * the `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` properties will be
540
- * set.
541
- *
542
- * Other key details might be exposed via this API using additional attributes.
543
- * @since v15.7.0
544
- */
545
- asymmetricKeyDetails?: AsymmetricKeyDetails;
546
- /**
547
- * The result type depends on the selected encoding format, when PEM the
548
- * result is a string, when DER it will be a buffer containing the data
549
- * encoded as DER, when [JWK](https://tools.ietf.org/html/rfc7517) it will be an object. Raw formats return a
550
- * `Buffer` containing the raw key material.
551
- *
552
- * Private keys can be encrypted by specifying a `cipher` and `passphrase`.
553
- * The PKCS#8 `type` supports encryption with both PEM and DER `format` for any
554
- * key algorithm. PKCS#1 and SEC1 can only be encrypted when the PEM `format` is
555
- * used. For maximum compatibility, use PKCS#8 for encrypted private keys. Since
556
- * PKCS#8 defines its own encryption mechanism, PEM-level encryption is not
557
- * supported when encrypting a PKCS#8 key. See [RFC 5208](https://www.rfc-editor.org/rfc/rfc5208.txt) for PKCS#8 encryption
558
- * and [RFC 1421](https://www.rfc-editor.org/rfc/rfc1421.txt) for PKCS#1 and SEC1 encryption.
559
- * @since v11.6.0
560
- */
561
- export<T extends KeyExportOptions = {}>(options?: T): KeyExportResult<T, NonSharedBuffer>;
562
- /**
563
- * Returns `true` or `false` depending on whether the keys have exactly the same
564
- * type, value, and parameters. This method is not [constant time](https://en.wikipedia.org/wiki/Timing_attack).
565
- * @since v17.7.0, v16.15.0
566
- * @param otherKeyObject A `KeyObject` with which to compare `keyObject`.
567
- */
568
- equals(otherKeyObject: KeyObject): boolean;
569
- /**
570
- * For secret keys, this property represents the size of the key in bytes. This
571
- * property is `undefined` for asymmetric keys.
572
- * @since v11.6.0
573
- */
574
- symmetricKeySize?: number;
575
- /**
576
- * Converts a `KeyObject` instance to a `CryptoKey`.
577
- * @since 22.10.0
578
- */
579
- toCryptoKey(
580
- algorithm:
581
- | webcrypto.AlgorithmIdentifier
582
- | webcrypto.RsaHashedImportParams
583
- | webcrypto.EcKeyImportParams
584
- | webcrypto.HmacImportParams,
585
- extractable: boolean,
586
- keyUsages: readonly webcrypto.KeyUsage[],
587
- ): webcrypto.CryptoKey;
588
- /**
589
- * Depending on the type of this `KeyObject`, this property is either`'secret'` for secret (symmetric) keys, `'public'` for public (asymmetric) keys
590
- * or `'private'` for private (asymmetric) keys.
591
- * @since v11.6.0
592
- */
593
- type: KeyObjectType;
594
- }
595
- type CipherCCMTypes = "aes-128-ccm" | "aes-192-ccm" | "aes-256-ccm";
596
- type CipherGCMTypes = "aes-128-gcm" | "aes-192-gcm" | "aes-256-gcm";
597
- type CipherOCBTypes = "aes-128-ocb" | "aes-192-ocb" | "aes-256-ocb";
598
- type CipherChaCha20Poly1305Types = "chacha20-poly1305";
599
- type BinaryLike = string | ArrayBufferLike | NodeJS.ArrayBufferView;
600
- type KeyLike = BinaryLike | KeyObject;
601
- interface CipherCCMOptions extends TransformOptions {
602
- authTagLength: number;
603
- }
604
- interface CipherGCMOptions extends TransformOptions {
605
- authTagLength?: number | undefined;
606
- }
607
- interface CipherOCBOptions extends TransformOptions {
608
- authTagLength: number;
609
- }
610
- interface CipherChaCha20Poly1305Options extends TransformOptions {
611
- authTagLength?: number | undefined;
612
- }
613
- /**
614
- * Creates and returns a `Cipher` object, with the given `algorithm`, `key` and
615
- * initialization vector (`iv`).
616
- *
617
- * The `options` argument controls stream behavior and is optional except when a
618
- * cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the`authTagLength` option is required and specifies the length of the
619
- * authentication tag in bytes, see `CCM mode`. In GCM mode, the `authTagLength`option is not required but can be used to set the length of the authentication
620
- * tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
621
- * For `chacha20-poly1305`, the `authTagLength` option defaults to 16 bytes.
622
- *
623
- * The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
624
- * recent OpenSSL releases, `openssl list -cipher-algorithms` will
625
- * display the available cipher algorithms.
626
- *
627
- * The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded
628
- * strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
629
- * a `KeyObject` of type `secret`. If the cipher does not need
630
- * an initialization vector, `iv` may be `null`.
631
- *
632
- * When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
633
- *
634
- * Initialization vectors should be unpredictable and unique; ideally, they will be
635
- * cryptographically random. They do not have to be secret: IVs are typically just
636
- * added to ciphertext messages unencrypted. It may sound contradictory that
637
- * something has to be unpredictable and unique, but does not have to be secret;
638
- * remember that an attacker must not be able to predict ahead of time what a
639
- * given IV will be.
640
- * @since v0.1.94
641
- * @param options `stream.transform` options
642
- */
643
- function createCipheriv(
644
- algorithm: CipherCCMTypes,
645
- key: KeyLike,
646
- iv: BinaryLike,
647
- options: CipherCCMOptions,
648
- ): CipherCCM;
649
- function createCipheriv(
650
- algorithm: CipherOCBTypes,
651
- key: KeyLike,
652
- iv: BinaryLike,
653
- options: CipherOCBOptions,
654
- ): CipherOCB;
655
- function createCipheriv(
656
- algorithm: CipherGCMTypes,
657
- key: KeyLike,
658
- iv: BinaryLike,
659
- options?: CipherGCMOptions,
660
- ): CipherGCM;
661
- function createCipheriv(
662
- algorithm: CipherChaCha20Poly1305Types,
663
- key: KeyLike,
664
- iv: BinaryLike,
665
- options?: CipherChaCha20Poly1305Options,
666
- ): CipherChaCha20Poly1305;
667
- function createCipheriv(
668
- algorithm: string,
669
- key: KeyLike,
670
- iv: BinaryLike | null,
671
- options?: TransformOptions,
672
- ): Cipheriv;
673
- /**
674
- * Instances of the `Cipheriv` class are used to encrypt data. The class can be
675
- * used in one of two ways:
676
- *
677
- * * As a `stream` that is both readable and writable, where plain unencrypted
678
- * data is written to produce encrypted data on the readable side, or
679
- * * Using the `cipher.update()` and `cipher.final()` methods to produce
680
- * the encrypted data.
681
- *
682
- * The {@link createCipheriv} method is
683
- * used to create `Cipheriv` instances. `Cipheriv` objects are not to be created
684
- * directly using the `new` keyword.
685
- *
686
- * Example: Using `Cipheriv` objects as streams:
687
- *
688
- * ```js
689
- * const {
690
- * scrypt,
691
- * randomFill,
692
- * createCipheriv,
693
- * } = await import('node:crypto');
694
- *
695
- * const algorithm = 'aes-192-cbc';
696
- * const password = 'Password used to generate key';
697
- *
698
- * // First, we'll generate the key. The key length is dependent on the algorithm.
699
- * // In this case for aes192, it is 24 bytes (192 bits).
700
- * scrypt(password, 'salt', 24, (err, key) => {
701
- * if (err) throw err;
702
- * // Then, we'll generate a random initialization vector
703
- * randomFill(new Uint8Array(16), (err, iv) => {
704
- * if (err) throw err;
705
- *
706
- * // Once we have the key and iv, we can create and use the cipher...
707
- * const cipher = createCipheriv(algorithm, key, iv);
708
- *
709
- * let encrypted = '';
710
- * cipher.setEncoding('hex');
711
- *
712
- * cipher.on('data', (chunk) => encrypted += chunk);
713
- * cipher.on('end', () => console.log(encrypted));
714
- *
715
- * cipher.write('some clear text data');
716
- * cipher.end();
717
- * });
718
- * });
719
- * ```
720
- *
721
- * Example: Using `Cipheriv` and piped streams:
722
- *
723
- * ```js
724
- * import {
725
- * createReadStream,
726
- * createWriteStream,
727
- * } from 'node:fs';
728
- *
729
- * import {
730
- * pipeline,
731
- * } from 'node:stream';
732
- *
733
- * const {
734
- * scrypt,
735
- * randomFill,
736
- * createCipheriv,
737
- * } = await import('node:crypto');
738
- *
739
- * const algorithm = 'aes-192-cbc';
740
- * const password = 'Password used to generate key';
741
- *
742
- * // First, we'll generate the key. The key length is dependent on the algorithm.
743
- * // In this case for aes192, it is 24 bytes (192 bits).
744
- * scrypt(password, 'salt', 24, (err, key) => {
745
- * if (err) throw err;
746
- * // Then, we'll generate a random initialization vector
747
- * randomFill(new Uint8Array(16), (err, iv) => {
748
- * if (err) throw err;
749
- *
750
- * const cipher = createCipheriv(algorithm, key, iv);
751
- *
752
- * const input = createReadStream('test.js');
753
- * const output = createWriteStream('test.enc');
754
- *
755
- * pipeline(input, cipher, output, (err) => {
756
- * if (err) throw err;
757
- * });
758
- * });
759
- * });
760
- * ```
761
- *
762
- * Example: Using the `cipher.update()` and `cipher.final()` methods:
763
- *
764
- * ```js
765
- * const {
766
- * scrypt,
767
- * randomFill,
768
- * createCipheriv,
769
- * } = await import('node:crypto');
770
- *
771
- * const algorithm = 'aes-192-cbc';
772
- * const password = 'Password used to generate key';
773
- *
774
- * // First, we'll generate the key. The key length is dependent on the algorithm.
775
- * // In this case for aes192, it is 24 bytes (192 bits).
776
- * scrypt(password, 'salt', 24, (err, key) => {
777
- * if (err) throw err;
778
- * // Then, we'll generate a random initialization vector
779
- * randomFill(new Uint8Array(16), (err, iv) => {
780
- * if (err) throw err;
781
- *
782
- * const cipher = createCipheriv(algorithm, key, iv);
783
- *
784
- * let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
785
- * encrypted += cipher.final('hex');
786
- * console.log(encrypted);
787
- * });
788
- * });
789
- * ```
790
- * @since v0.1.94
791
- */
792
- class Cipheriv extends Transform {
793
- private constructor();
794
- /**
795
- * Updates the cipher with `data`. If the `inputEncoding` argument is given,
796
- * the `data`argument is a string using the specified encoding. If the `inputEncoding`argument is not given, `data` must be a `Buffer`, `TypedArray`, or `DataView`. If `data` is a `Buffer`,
797
- * `TypedArray`, or `DataView`, then `inputEncoding` is ignored.
798
- *
799
- * The `outputEncoding` specifies the output format of the enciphered
800
- * data. If the `outputEncoding`is specified, a string using the specified encoding is returned. If no`outputEncoding` is provided, a `Buffer` is returned.
801
- *
802
- * The `cipher.update()` method can be called multiple times with new data until `cipher.final()` is called. Calling `cipher.update()` after `cipher.final()` will result in an error being
803
- * thrown.
804
- * @since v0.1.94
805
- * @param inputEncoding The `encoding` of the data.
806
- * @param outputEncoding The `encoding` of the return value.
807
- */
808
- update(data: string | NodeJS.ArrayBufferView, inputEncoding?: BufferEncoding): NonSharedBuffer;
809
- update(
810
- data: string | NodeJS.ArrayBufferView,
811
- inputEncoding: BufferEncoding | null | undefined,
812
- outputEncoding: BufferEncoding,
813
- ): string;
814
- /**
815
- * Once the `cipher.final()` method has been called, the `Cipheriv` object can no
816
- * longer be used to encrypt data. Attempts to call `cipher.final()` more than
817
- * once will result in an error being thrown.
818
- * @since v0.1.94
819
- * @param outputEncoding The `encoding` of the return value.
820
- * @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
821
- */
822
- final(): NonSharedBuffer;
823
- final(outputEncoding: BufferEncoding): string;
824
- /**
825
- * When using block encryption algorithms, the `Cipheriv` class will automatically
826
- * add padding to the input data to the appropriate block size. To disable the
827
- * default padding call `cipher.setAutoPadding(false)`.
828
- *
829
- * When `autoPadding` is `false`, the length of the entire input data must be a
830
- * multiple of the cipher's block size or `cipher.final()` will throw an error.
831
- * Disabling automatic padding is useful for non-standard padding, for instance
832
- * using `0x0` instead of PKCS padding.
833
- *
834
- * The `cipher.setAutoPadding()` method must be called before `cipher.final()`.
835
- * @since v0.7.1
836
- * @param [autoPadding=true]
837
- * @return for method chaining.
838
- */
839
- setAutoPadding(autoPadding?: boolean): this;
840
- }
841
- interface CipherAEADMethods {
842
- getAuthTag(): NonSharedBuffer;
843
- setAAD(buffer: BinaryLike, options?: {
844
- plaintextLength?: number | undefined;
845
- encoding?: BufferEncoding | undefined;
846
- }): this;
847
- }
848
- interface CipherCCM extends Cipheriv, CipherAEADMethods {
849
- setAAD(buffer: BinaryLike, options: {
850
- plaintextLength: number;
851
- encoding?: BufferEncoding | undefined;
852
- }): this;
853
- }
854
- interface CipherGCM extends Cipheriv, CipherAEADMethods {}
855
- interface CipherOCB extends Cipheriv, CipherAEADMethods {}
856
- interface CipherChaCha20Poly1305 extends Cipheriv, CipherAEADMethods {}
857
- /**
858
- * Creates and returns a `Decipheriv` object that uses the given `algorithm`, `key` and initialization vector (`iv`).
859
- *
860
- * The `options` argument controls stream behavior and is optional except when a
861
- * cipher in CCM or OCB mode (e.g. `'aes-128-ccm'`) is used. In that case, the
862
- * `authTagLength` option is required and specifies the length of the
863
- * authentication tag in bytes, see [CCM mode](https://nodejs.org/docs/latest-v26.x/api/crypto.html#ccm-mode).
864
- * For AES-GCM and `chacha20-poly1305`, the `authTagLength` option defaults to 16
865
- * bytes and must be set to a different value if a different length is used.
866
- *
867
- * The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
868
- * recent OpenSSL releases, `openssl list -cipher-algorithms` will
869
- * display the available cipher algorithms.
870
- *
871
- * The `key` is the raw key used by the `algorithm` and `iv` is an [initialization vector](https://en.wikipedia.org/wiki/Initialization_vector). Both arguments must be `'utf8'` encoded
872
- * strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
873
- * a `KeyObject` of type `secret`. If the cipher does not need
874
- * an initialization vector, `iv` may be `null`.
875
- *
876
- * When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
877
- *
878
- * Initialization vectors should be unpredictable and unique; ideally, they will be
879
- * cryptographically random. They do not have to be secret: IVs are typically just
880
- * added to ciphertext messages unencrypted. It may sound contradictory that
881
- * something has to be unpredictable and unique, but does not have to be secret;
882
- * remember that an attacker must not be able to predict ahead of time what a given
883
- * IV will be.
884
- * @since v0.1.94
885
- * @param options `stream.transform` options
886
- */
887
- function createDecipheriv(
888
- algorithm: CipherCCMTypes,
889
- key: KeyLike,
890
- iv: BinaryLike,
891
- options: CipherCCMOptions,
892
- ): DecipherCCM;
893
- function createDecipheriv(
894
- algorithm: CipherOCBTypes,
895
- key: KeyLike,
896
- iv: BinaryLike,
897
- options: CipherOCBOptions,
898
- ): DecipherOCB;
899
- function createDecipheriv(
900
- algorithm: CipherGCMTypes,
901
- key: KeyLike,
902
- iv: BinaryLike,
903
- options?: CipherGCMOptions,
904
- ): DecipherGCM;
905
- function createDecipheriv(
906
- algorithm: CipherChaCha20Poly1305Types,
907
- key: KeyLike,
908
- iv: BinaryLike,
909
- options?: CipherChaCha20Poly1305Options,
910
- ): DecipherChaCha20Poly1305;
911
- function createDecipheriv(
912
- algorithm: string,
913
- key: KeyLike,
914
- iv: BinaryLike | null,
915
- options?: TransformOptions,
916
- ): Decipheriv;
917
- /**
918
- * Instances of the `Decipheriv` class are used to decrypt data. The class can be
919
- * used in one of two ways:
920
- *
921
- * * As a `stream` that is both readable and writable, where plain encrypted
922
- * data is written to produce unencrypted data on the readable side, or
923
- * * Using the `decipher.update()` and `decipher.final()` methods to
924
- * produce the unencrypted data.
925
- *
926
- * The {@link createDecipheriv} method is
927
- * used to create `Decipheriv` instances. `Decipheriv` objects are not to be created
928
- * directly using the `new` keyword.
929
- *
930
- * Example: Using `Decipheriv` objects as streams:
931
- *
932
- * ```js
933
- * import { Buffer } from 'node:buffer';
934
- * const {
935
- * scryptSync,
936
- * createDecipheriv,
937
- * } = await import('node:crypto');
938
- *
939
- * const algorithm = 'aes-192-cbc';
940
- * const password = 'Password used to generate key';
941
- * // Key length is dependent on the algorithm. In this case for aes192, it is
942
- * // 24 bytes (192 bits).
943
- * // Use the async `crypto.scrypt()` instead.
944
- * const key = scryptSync(password, 'salt', 24);
945
- * // The IV is usually passed along with the ciphertext.
946
- * const iv = Buffer.alloc(16, 0); // Initialization vector.
947
- *
948
- * const decipher = createDecipheriv(algorithm, key, iv);
949
- *
950
- * let decrypted = '';
951
- * decipher.on('readable', () => {
952
- * let chunk;
953
- * while (null !== (chunk = decipher.read())) {
954
- * decrypted += chunk.toString('utf8');
955
- * }
956
- * });
957
- * decipher.on('end', () => {
958
- * console.log(decrypted);
959
- * // Prints: some clear text data
960
- * });
961
- *
962
- * // Encrypted with same algorithm, key and iv.
963
- * const encrypted =
964
- * 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
965
- * decipher.write(encrypted, 'hex');
966
- * decipher.end();
967
- * ```
968
- *
969
- * Example: Using `Decipheriv` and piped streams:
970
- *
971
- * ```js
972
- * import {
973
- * createReadStream,
974
- * createWriteStream,
975
- * } from 'node:fs';
976
- * import { Buffer } from 'node:buffer';
977
- * const {
978
- * scryptSync,
979
- * createDecipheriv,
980
- * } = await import('node:crypto');
981
- *
982
- * const algorithm = 'aes-192-cbc';
983
- * const password = 'Password used to generate key';
984
- * // Use the async `crypto.scrypt()` instead.
985
- * const key = scryptSync(password, 'salt', 24);
986
- * // The IV is usually passed along with the ciphertext.
987
- * const iv = Buffer.alloc(16, 0); // Initialization vector.
988
- *
989
- * const decipher = createDecipheriv(algorithm, key, iv);
990
- *
991
- * const input = createReadStream('test.enc');
992
- * const output = createWriteStream('test.js');
993
- *
994
- * input.pipe(decipher).pipe(output);
995
- * ```
996
- *
997
- * Example: Using the `decipher.update()` and `decipher.final()` methods:
998
- *
999
- * ```js
1000
- * import { Buffer } from 'node:buffer';
1001
- * const {
1002
- * scryptSync,
1003
- * createDecipheriv,
1004
- * } = await import('node:crypto');
1005
- *
1006
- * const algorithm = 'aes-192-cbc';
1007
- * const password = 'Password used to generate key';
1008
- * // Use the async `crypto.scrypt()` instead.
1009
- * const key = scryptSync(password, 'salt', 24);
1010
- * // The IV is usually passed along with the ciphertext.
1011
- * const iv = Buffer.alloc(16, 0); // Initialization vector.
1012
- *
1013
- * const decipher = createDecipheriv(algorithm, key, iv);
1014
- *
1015
- * // Encrypted using same algorithm, key and iv.
1016
- * const encrypted =
1017
- * 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
1018
- * let decrypted = decipher.update(encrypted, 'hex', 'utf8');
1019
- * decrypted += decipher.final('utf8');
1020
- * console.log(decrypted);
1021
- * // Prints: some clear text data
1022
- * ```
1023
- * @since v0.1.94
1024
- */
1025
- class Decipheriv extends Transform {
1026
- private constructor();
1027
- /**
1028
- * Updates the decipher with `data`. If the `inputEncoding` argument is given,
1029
- * the `data` argument is a string using the specified encoding. If the `inputEncoding` argument is not given, `data` must be a `Buffer`. If `data` is a `Buffer` then `inputEncoding` is
1030
- * ignored.
1031
- *
1032
- * The `outputEncoding` specifies the output format of the enciphered
1033
- * data. If the `outputEncoding` is specified, a string using the specified encoding is returned. If no `outputEncoding` is provided, a `Buffer` is returned.
1034
- *
1035
- * The `decipher.update()` method can be called multiple times with new data until `decipher.final()` is called. Calling `decipher.update()` after `decipher.final()` will result in an error
1036
- * being thrown.
1037
- * @since v0.1.94
1038
- * @param inputEncoding The `encoding` of the `data` string.
1039
- * @param outputEncoding The `encoding` of the return value.
1040
- */
1041
- update(data: string | NodeJS.ArrayBufferView, inputEncoding?: BufferEncoding): NonSharedBuffer;
1042
- update(
1043
- data: string | NodeJS.ArrayBufferView,
1044
- inputEncoding: BufferEncoding | null | undefined,
1045
- outputEncoding: BufferEncoding,
1046
- ): string;
1047
- /**
1048
- * Once the `decipher.final()` method has been called, the `Decipheriv` object can
1049
- * no longer be used to decrypt data. Attempts to call `decipher.final()` more
1050
- * than once will result in an error being thrown.
1051
- * @since v0.1.94
1052
- * @param outputEncoding The `encoding` of the return value.
1053
- * @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
1054
- */
1055
- final(): NonSharedBuffer;
1056
- final(outputEncoding: BufferEncoding): string;
1057
- /**
1058
- * When data has been encrypted without standard block padding, calling `decipher.setAutoPadding(false)` will disable automatic padding to prevent `decipher.final()` from checking for and
1059
- * removing padding.
1060
- *
1061
- * Turning auto padding off will only work if the input data's length is a
1062
- * multiple of the ciphers block size.
1063
- *
1064
- * The `decipher.setAutoPadding()` method must be called before `decipher.final()`.
1065
- * @since v0.7.1
1066
- * @param [autoPadding=true]
1067
- * @return for method chaining.
1068
- */
1069
- setAutoPadding(auto_padding?: boolean): this;
1070
- }
1071
- interface DecipherAEADMethods {
1072
- setAAD(
1073
- buffer: BinaryLike,
1074
- options?: {
1075
- plaintextLength?: number | undefined;
1076
- encoding?: BufferEncoding | undefined;
1077
- },
1078
- ): this;
1079
- setAuthTag(buffer: BinaryLike, encoding?: BufferEncoding): this;
1080
- }
1081
- interface DecipherCCM extends Decipheriv, DecipherAEADMethods {
1082
- setAAD(
1083
- buffer: BinaryLike,
1084
- options: {
1085
- plaintextLength: number;
1086
- encoding?: BufferEncoding | undefined;
1087
- },
1088
- ): this;
1089
- }
1090
- interface DecipherGCM extends Decipheriv, DecipherAEADMethods {}
1091
- interface DecipherOCB extends Decipheriv, DecipherAEADMethods {}
1092
- interface DecipherChaCha20Poly1305 extends Decipheriv, DecipherAEADMethods {}
1093
- interface PrivateKeyInput {
1094
- key: BinaryLike;
1095
- format?: "pem" | "der" | undefined;
1096
- type?: PrivateKeyExportType | undefined;
1097
- passphrase?: BinaryLike | undefined;
1098
- encoding?: BufferEncoding | undefined;
1099
- }
1100
- interface PublicKeyInput {
1101
- key: BinaryLike;
1102
- format?: "pem" | "der" | undefined;
1103
- type?: PublicKeyExportType | undefined;
1104
- encoding?: BufferEncoding | undefined;
1105
- }
1106
- interface RawPrivateKeyInput {
1107
- key: ArrayBufferLike | NodeJS.ArrayBufferView;
1108
- format: "raw-private" | "raw-seed";
1109
- asymmetricKeyType: AsymmetricKeyType;
1110
- namedCurve?: string | undefined;
1111
- }
1112
- interface RawPublicKeyInput {
1113
- key: ArrayBufferLike | NodeJS.ArrayBufferView;
1114
- format: "raw-public";
1115
- asymmetricKeyType: AsymmetricKeyType;
1116
- namedCurve?: string | undefined;
1117
- }
1118
- interface JsonWebKeyInput {
1119
- key: webcrypto.JsonWebKey;
1120
- format: "jwk";
1121
- }
1122
- interface SecretKeyOptions {
1123
- length: number;
1124
- }
1125
- /**
1126
- * Asynchronously generates a new random secret key of the given `length`. The `type` will determine which validations will be performed on the `length`.
1127
- *
1128
- * ```js
1129
- * const {
1130
- * generateKey,
1131
- * } = await import('node:crypto');
1132
- *
1133
- * generateKey('hmac', { length: 512 }, (err, key) => {
1134
- * if (err) throw err;
1135
- * console.log(key.export().toString('hex')); // 46e..........620
1136
- * });
1137
- * ```
1138
- *
1139
- * The size of a generated HMAC key should not exceed the block size of the
1140
- * underlying hash function. See {@link createHmac} for more information.
1141
- * @since v15.0.0
1142
- * @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
1143
- */
1144
- function generateKey(
1145
- type: "hmac" | "aes",
1146
- options: SecretKeyOptions,
1147
- callback: (err: Error | null, key: KeyObject) => void,
1148
- ): void;
1149
- /**
1150
- * Synchronously generates a new random secret key of the given `length`. The `type` will determine which validations will be performed on the `length`.
1151
- *
1152
- * ```js
1153
- * const {
1154
- * generateKeySync,
1155
- * } = await import('node:crypto');
1156
- *
1157
- * const key = generateKeySync('hmac', { length: 512 });
1158
- * console.log(key.export().toString('hex')); // e89..........41e
1159
- * ```
1160
- *
1161
- * The size of a generated HMAC key should not exceed the block size of the
1162
- * underlying hash function. See {@link createHmac} for more information.
1163
- * @since v15.0.0
1164
- * @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
1165
- */
1166
- function generateKeySync(type: "hmac" | "aes", options: SecretKeyOptions): KeyObject;
1167
- /**
1168
- * Creates and returns a new key object containing a private key. If `key` is a
1169
- * string or `Buffer`, `format` is assumed to be `'pem'`; otherwise, `key` must be an object with the properties described above.
1170
- *
1171
- * If the private key is encrypted, a `passphrase` must be specified. The length
1172
- * of the passphrase is limited to 1024 bytes.
1173
- * @since v11.6.0
1174
- */
1175
- function createPrivateKey(key: PrivateKeyInput | RawPrivateKeyInput | JsonWebKeyInput | BinaryLike): KeyObject;
1176
- /**
1177
- * Creates and returns a new key object containing a public key. If `key` is a
1178
- * string or `Buffer`, `format` is assumed to be `'pem'`; if `key` is a `KeyObject` with type `'private'`, the public key is derived from the given private key;
1179
- * otherwise, `key` must be an object with the properties described above.
1180
- *
1181
- * If the format is `'pem'`, the `'key'` may also be an X.509 certificate.
1182
- *
1183
- * Because public keys can be derived from private keys, a private key may be
1184
- * passed instead of a public key. In that case, this function behaves as if {@link createPrivateKey} had been called, except that the type of the
1185
- * returned `KeyObject` will be `'public'` and that the private key cannot be
1186
- * extracted from the returned `KeyObject`. Similarly, if a `KeyObject` with type `'private'` is given, a new `KeyObject` with type `'public'` will be returned
1187
- * and it will be impossible to extract the private key from the returned object.
1188
- * @since v11.6.0
1189
- */
1190
- function createPublicKey(key: PublicKeyInput | RawPublicKeyInput | JsonWebKeyInput | KeyLike): KeyObject;
1191
- /**
1192
- * Creates and returns a new key object containing a secret key for symmetric
1193
- * encryption or `Hmac`.
1194
- * @since v11.6.0
1195
- * @param encoding The string encoding when `key` is a string.
1196
- */
1197
- function createSecretKey(key: BinaryLike, encoding?: BufferEncoding): KeyObject;
1198
- /**
1199
- * Creates and returns a `Sign` object that uses the given `algorithm`. Use {@link getHashes} to obtain the names of the available digest algorithms.
1200
- * Optional `options` argument controls the `stream.Writable` behavior.
1201
- *
1202
- * In some cases, a `Sign` instance can be created using the name of a signature
1203
- * algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
1204
- * the corresponding digest algorithm. This does not work for all signature
1205
- * algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
1206
- * algorithm names.
1207
- * @since v0.1.92
1208
- * @param options `stream.Writable` options
1209
- */
1210
- function createSign(algorithm: string, options?: WritableOptions): Sign;
1211
- type DSAEncoding = "der" | "ieee-p1363";
1212
- interface SigningOptions {
1213
- padding?: number | undefined;
1214
- saltLength?: number | undefined;
1215
- dsaEncoding?: DSAEncoding | undefined;
1216
- context?: NodeJS.ArrayBufferView | undefined;
1217
- }
1218
- interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {}
1219
- interface SignRawPrivateKeyInput extends RawPrivateKeyInput, SigningOptions {}
1220
- interface SignJsonWebKeyInput extends JsonWebKeyInput, SigningOptions {}
1221
- interface SignKeyObjectInput extends SigningOptions {
1222
- key: KeyObject;
1223
- }
1224
- interface VerifyPublicKeyInput extends PublicKeyInput, SigningOptions {}
1225
- interface VerifyRawPublicKeyInput extends RawPublicKeyInput, SigningOptions {}
1226
- interface VerifyJsonWebKeyInput extends JsonWebKeyInput, SigningOptions {}
1227
- interface VerifyKeyObjectInput extends SigningOptions {
1228
- key: KeyObject;
1229
- }
1230
- /**
1231
- * The `Sign` class is a utility for generating signatures. It can be used in one
1232
- * of two ways:
1233
- *
1234
- * * As a writable `stream`, where data to be signed is written and the `sign.sign()` method is used to generate and return the signature, or
1235
- * * Using the `sign.update()` and `sign.sign()` methods to produce the
1236
- * signature.
1237
- *
1238
- * The {@link createSign} method is used to create `Sign` instances. The
1239
- * argument is the string name of the hash function to use. `Sign` objects are not
1240
- * to be created directly using the `new` keyword.
1241
- *
1242
- * Example: Using `Sign` and `Verify` objects as streams:
1243
- *
1244
- * ```js
1245
- * const {
1246
- * generateKeyPairSync,
1247
- * createSign,
1248
- * createVerify,
1249
- * } = await import('node:crypto');
1250
- *
1251
- * const { privateKey, publicKey } = generateKeyPairSync('ec', {
1252
- * namedCurve: 'sect239k1',
1253
- * });
1254
- *
1255
- * const sign = createSign('SHA256');
1256
- * sign.write('some data to sign');
1257
- * sign.end();
1258
- * const signature = sign.sign(privateKey, 'hex');
1259
- *
1260
- * const verify = createVerify('SHA256');
1261
- * verify.write('some data to sign');
1262
- * verify.end();
1263
- * console.log(verify.verify(publicKey, signature, 'hex'));
1264
- * // Prints: true
1265
- * ```
1266
- *
1267
- * Example: Using the `sign.update()` and `verify.update()` methods:
1268
- *
1269
- * ```js
1270
- * const {
1271
- * generateKeyPairSync,
1272
- * createSign,
1273
- * createVerify,
1274
- * } = await import('node:crypto');
1275
- *
1276
- * const { privateKey, publicKey } = generateKeyPairSync('rsa', {
1277
- * modulusLength: 2048,
1278
- * });
1279
- *
1280
- * const sign = createSign('SHA256');
1281
- * sign.update('some data to sign');
1282
- * sign.end();
1283
- * const signature = sign.sign(privateKey);
1284
- *
1285
- * const verify = createVerify('SHA256');
1286
- * verify.update('some data to sign');
1287
- * verify.end();
1288
- * console.log(verify.verify(publicKey, signature));
1289
- * // Prints: true
1290
- * ```
1291
- * @since v0.1.92
1292
- */
1293
- class Sign extends Writable {
1294
- private constructor();
1295
- /**
1296
- * Updates the `Sign` content with the given `data`, the encoding of which
1297
- * is given in `inputEncoding`.
1298
- * If `encoding` is not provided, and the `data` is a string, an
1299
- * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
1300
- *
1301
- * This can be called many times with new data as it is streamed.
1302
- * @since v0.1.92
1303
- * @param inputEncoding The `encoding` of the `data` string.
1304
- */
1305
- update(data: string | NodeJS.ArrayBufferView, inputEncoding?: BufferEncoding): this;
1306
- /**
1307
- * Calculates the signature on all the data passed through using either `sign.update()` or `sign.write()`.
1308
- *
1309
- * If `privateKey` is not a `KeyObject`, this function behaves as if
1310
- * `privateKey` had been passed to `crypto.createPrivateKey()`. When
1311
- * `privateKey` is a string, `ArrayBuffer`, `Buffer`, `TypedArray`, or
1312
- * `DataView`, it must contain PEM-encoded key material. If it is an object, the
1313
- * following additional properties can be passed:
1314
- *
1315
- * If `outputEncoding` is provided a string is returned; otherwise a `Buffer` is returned.
1316
- *
1317
- * The `Sign` object can not be again used after `sign.sign()` method has been
1318
- * called. Multiple calls to `sign.sign()` will result in an error being thrown.
1319
- * @since v0.1.92
1320
- */
1321
- sign(
1322
- privateKey:
1323
- | KeyLike
1324
- | SignKeyObjectInput
1325
- | SignPrivateKeyInput
1326
- | SignRawPrivateKeyInput
1327
- | SignJsonWebKeyInput,
1328
- ): NonSharedBuffer;
1329
- sign(
1330
- privateKey:
1331
- | KeyLike
1332
- | SignKeyObjectInput
1333
- | SignPrivateKeyInput
1334
- | SignRawPrivateKeyInput
1335
- | SignJsonWebKeyInput,
1336
- outputFormat: BufferEncoding,
1337
- ): string;
1338
- }
1339
- /**
1340
- * Creates and returns a `Verify` object that uses the given algorithm.
1341
- * Use {@link getHashes} to obtain an array of names of the available
1342
- * signing algorithms. Optional `options` argument controls the `stream.Writable` behavior.
1343
- *
1344
- * In some cases, a `Verify` instance can be created using the name of a signature
1345
- * algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
1346
- * the corresponding digest algorithm. This does not work for all signature
1347
- * algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
1348
- * algorithm names.
1349
- * @since v0.1.92
1350
- * @param options `stream.Writable` options
1351
- */
1352
- function createVerify(algorithm: string, options?: WritableOptions): Verify;
1353
- /**
1354
- * The `Verify` class is a utility for verifying signatures. It can be used in one
1355
- * of two ways:
1356
- *
1357
- * * As a writable `stream` where written data is used to validate against the
1358
- * supplied signature, or
1359
- * * Using the `verify.update()` and `verify.verify()` methods to verify
1360
- * the signature.
1361
- *
1362
- * The {@link createVerify} method is used to create `Verify` instances. `Verify` objects are not to be created directly using the `new` keyword.
1363
- *
1364
- * See `Sign` for examples.
1365
- * @since v0.1.92
1366
- */
1367
- class Verify extends Writable {
1368
- private constructor();
1369
- /**
1370
- * Updates the `Verify` content with the given `data`, the encoding of which
1371
- * is given in `inputEncoding`.
1372
- * If `inputEncoding` is not provided, and the `data` is a string, an
1373
- * encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or `DataView`, then `inputEncoding` is ignored.
1374
- *
1375
- * This can be called many times with new data as it is streamed.
1376
- * @since v0.1.92
1377
- * @param inputEncoding The `encoding` of the `data` string.
1378
- */
1379
- update(data: string | NodeJS.ArrayBufferView, inputEncoding?: BufferEncoding): Verify;
1380
- /**
1381
- * Verifies the provided data using the given `key` and `signature`.
1382
- *
1383
- * If `key` is not a `KeyObject`, this function behaves as if
1384
- * `key` had been passed to `crypto.createPublicKey()`. When `key` is a string,
1385
- * `ArrayBuffer`, `Buffer`, `TypedArray`, or `DataView`, it must contain
1386
- * PEM-encoded key material. If it is an object, the following additional
1387
- * properties can be passed:
1388
- *
1389
- * The `signature` argument is the previously calculated signature for the data, in
1390
- * the `signatureEncoding`.
1391
- * If a `signatureEncoding` is specified, the `signature` is expected to be a
1392
- * string; otherwise `signature` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
1393
- *
1394
- * The `verify` object can not be used again after `verify.verify()` has been
1395
- * called. Multiple calls to `verify.verify()` will result in an error being
1396
- * thrown.
1397
- *
1398
- * Because public keys can be derived from private keys, a private key may
1399
- * be passed instead of a public key.
1400
- * @since v0.1.92
1401
- */
1402
- verify(
1403
- key:
1404
- | KeyLike
1405
- | VerifyKeyObjectInput
1406
- | VerifyPublicKeyInput
1407
- | VerifyRawPublicKeyInput
1408
- | VerifyJsonWebKeyInput,
1409
- signature: BinaryLike,
1410
- signatureEncoding?: BufferEncoding,
1411
- ): boolean;
1412
- }
1413
- /**
1414
- * Creates a `DiffieHellman` key exchange object using the supplied `prime` and an
1415
- * optional specific `generator`.
1416
- *
1417
- * The `generator` argument can be a number, string, or `Buffer`. If `generator` is not specified, the value `2` is used.
1418
- *
1419
- * If `primeEncoding` is specified, `prime` is expected to be a string; otherwise
1420
- * a `Buffer`, `TypedArray`, or `DataView` is expected.
1421
- *
1422
- * If `generatorEncoding` is specified, `generator` is expected to be a string;
1423
- * otherwise a number, `Buffer`, `TypedArray`, or `DataView` is expected.
1424
- * @since v0.11.12
1425
- * @param primeEncoding The `encoding` of the `prime` string.
1426
- * @param [generator=2]
1427
- * @param generatorEncoding The `encoding` of the `generator` string.
1428
- */
1429
- function createDiffieHellman(primeLength: number, generator?: number): DiffieHellman;
1430
- function createDiffieHellman(
1431
- prime: BinaryLike,
1432
- primeEncoding?: BufferEncoding,
1433
- generator?: number | BinaryLike,
1434
- generatorEncoding?: BufferEncoding,
1435
- ): DiffieHellman;
1436
- function createDiffieHellman(
1437
- prime: BinaryLike,
1438
- generator: number | BinaryLike,
1439
- generatorEncoding?: BufferEncoding,
1440
- ): DiffieHellman;
1441
- /**
1442
- * The `DiffieHellman` class is a utility for creating Diffie-Hellman key
1443
- * exchanges.
1444
- *
1445
- * Instances of the `DiffieHellman` class can be created using the {@link createDiffieHellman} function.
1446
- *
1447
- * ```js
1448
- * import assert from 'node:assert';
1449
- *
1450
- * const {
1451
- * createDiffieHellman,
1452
- * } = await import('node:crypto');
1453
- *
1454
- * // Generate Alice's keys...
1455
- * const alice = createDiffieHellman(2048);
1456
- * const aliceKey = alice.generateKeys();
1457
- *
1458
- * // Generate Bob's keys...
1459
- * const bob = createDiffieHellman(alice.getPrime(), alice.getGenerator());
1460
- * const bobKey = bob.generateKeys();
1461
- *
1462
- * // Exchange and generate the secret...
1463
- * const aliceSecret = alice.computeSecret(bobKey);
1464
- * const bobSecret = bob.computeSecret(aliceKey);
1465
- *
1466
- * // OK
1467
- * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
1468
- * ```
1469
- * @since v0.5.0
1470
- */
1471
- class DiffieHellman {
1472
- private constructor();
1473
- /**
1474
- * Generates private and public Diffie-Hellman key values unless they have been
1475
- * generated or computed already, and returns
1476
- * the public key in the specified `encoding`. This key should be
1477
- * transferred to the other party.
1478
- * If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
1479
- *
1480
- * This function is a thin wrapper around [`DH_generate_key()`](https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html). In particular,
1481
- * once a private key has been generated or set, calling this function only
1482
- * recomputes the public key from the existing private key. Since the public key is
1483
- * determined by the private key, the result will be the same unless the private key
1484
- * has been changed via `diffieHellman.setPrivateKey()`.
1485
- * @since v0.5.0
1486
- * @param encoding The `encoding` of the return value.
1487
- */
1488
- generateKeys(): NonSharedBuffer;
1489
- generateKeys(encoding: BufferEncoding): string;
1490
- /**
1491
- * Computes the shared secret using `otherPublicKey` as the other
1492
- * party's public key and returns the computed shared secret. The supplied
1493
- * key is interpreted using the specified `inputEncoding`, and secret is
1494
- * encoded using specified `outputEncoding`.
1495
- * If the `inputEncoding` is not
1496
- * provided, `otherPublicKey` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
1497
- *
1498
- * If `outputEncoding` is given a string is returned; otherwise, a `Buffer` is returned.
1499
- * @since v0.5.0
1500
- * @param inputEncoding The `encoding` of an `otherPublicKey` string.
1501
- * @param outputEncoding The `encoding` of the return value.
1502
- */
1503
- computeSecret(
1504
- otherPublicKey: BinaryLike,
1505
- inputEncoding?: BufferEncoding,
1506
- ): NonSharedBuffer;
1507
- computeSecret(
1508
- otherPublicKey: BinaryLike,
1509
- inputEncoding: BufferEncoding | null | undefined,
1510
- outputEncoding: BufferEncoding,
1511
- ): string;
1512
- /**
1513
- * Returns the Diffie-Hellman prime in the specified `encoding`.
1514
- * If `encoding` is provided a string is
1515
- * returned; otherwise a `Buffer` is returned.
1516
- * @since v0.5.0
1517
- * @param encoding The `encoding` of the return value.
1518
- */
1519
- getPrime(): NonSharedBuffer;
1520
- getPrime(encoding: BufferEncoding): string;
1521
- /**
1522
- * Returns the Diffie-Hellman generator in the specified `encoding`.
1523
- * If `encoding` is provided a string is
1524
- * returned; otherwise a `Buffer` is returned.
1525
- * @since v0.5.0
1526
- * @param encoding The `encoding` of the return value.
1527
- */
1528
- getGenerator(): NonSharedBuffer;
1529
- getGenerator(encoding: BufferEncoding): string;
1530
- /**
1531
- * Returns the Diffie-Hellman public key in the specified `encoding`.
1532
- * If `encoding` is provided a
1533
- * string is returned; otherwise a `Buffer` is returned.
1534
- * @since v0.5.0
1535
- * @param encoding The `encoding` of the return value.
1536
- */
1537
- getPublicKey(): NonSharedBuffer;
1538
- getPublicKey(encoding: BufferEncoding): string;
1539
- /**
1540
- * Returns the Diffie-Hellman private key in the specified `encoding`.
1541
- * If `encoding` is provided a
1542
- * string is returned; otherwise a `Buffer` is returned.
1543
- * @since v0.5.0
1544
- * @param encoding The `encoding` of the return value.
1545
- */
1546
- getPrivateKey(): NonSharedBuffer;
1547
- getPrivateKey(encoding: BufferEncoding): string;
1548
- /**
1549
- * Sets the Diffie-Hellman public key. If the `encoding` argument is provided, `publicKey` is expected
1550
- * to be a string. If no `encoding` is provided, `publicKey` is expected
1551
- * to be a `Buffer`, `TypedArray`, or `DataView`.
1552
- * @since v0.5.0
1553
- * @param encoding The `encoding` of the `publicKey` string.
1554
- */
1555
- setPublicKey(publicKey: BinaryLike, encoding?: BufferEncoding): void;
1556
- /**
1557
- * Sets the Diffie-Hellman private key. If the `encoding` argument is provided,`privateKey` is expected
1558
- * to be a string. If no `encoding` is provided, `privateKey` is expected
1559
- * to be a `Buffer`, `TypedArray`, or `DataView`.
1560
- *
1561
- * This function does not automatically compute the associated public key. Either `diffieHellman.setPublicKey()` or `diffieHellman.generateKeys()` can be
1562
- * used to manually provide the public key or to automatically derive it.
1563
- * @since v0.5.0
1564
- * @param encoding The `encoding` of the `privateKey` string.
1565
- */
1566
- setPrivateKey(privateKey: BinaryLike, encoding?: BufferEncoding): void;
1567
- /**
1568
- * A bit field containing any warnings and/or errors resulting from a check
1569
- * performed during initialization of the `DiffieHellman` object.
1570
- *
1571
- * The following values are valid for this property (as defined in `node:constants` module):
1572
- *
1573
- * * `DH_CHECK_P_NOT_SAFE_PRIME`
1574
- * * `DH_CHECK_P_NOT_PRIME`
1575
- * * `DH_UNABLE_TO_CHECK_GENERATOR`
1576
- * * `DH_NOT_SUITABLE_GENERATOR`
1577
- * @since v0.11.12
1578
- */
1579
- verifyError: number;
1580
- }
1581
- /**
1582
- * The `DiffieHellmanGroup` class takes a well-known modp group as its argument.
1583
- * It works the same as `DiffieHellman`, except that it does not allow changing its keys after creation.
1584
- * In other words, it does not implement `setPublicKey()` or `setPrivateKey()` methods.
1585
- *
1586
- * ```js
1587
- * const { createDiffieHellmanGroup } = await import('node:crypto');
1588
- * const dh = createDiffieHellmanGroup('modp1');
1589
- * ```
1590
- * The name (e.g. `'modp1'`) is taken from [RFC 2412](https://www.rfc-editor.org/rfc/rfc2412.txt) (modp1 and 2) and [RFC 3526](https://www.rfc-editor.org/rfc/rfc3526.txt):
1591
- * ```bash
1592
- * $ perl -ne 'print "$1\n" if /"(modp\d+)"/' src/node_crypto_groups.h
1593
- * modp1 # 768 bits
1594
- * modp2 # 1024 bits
1595
- * modp5 # 1536 bits
1596
- * modp14 # 2048 bits
1597
- * modp15 # etc.
1598
- * modp16
1599
- * modp17
1600
- * modp18
1601
- * ```
1602
- * @since v0.7.5
1603
- */
1604
- class DiffieHellmanGroup {
1605
- private constructor();
1606
- }
1607
- interface DiffieHellmanGroup extends Omit<DiffieHellman, "setPublicKey" | "setPrivateKey"> {}
1608
- /**
1609
- * Creates a predefined `DiffieHellmanGroup` key exchange object. The
1610
- * supported groups are listed in the documentation for `DiffieHellmanGroup`.
1611
- *
1612
- * The returned object mimics the interface of objects created by {@link createDiffieHellman}, but will not allow changing
1613
- * the keys (with `diffieHellman.setPublicKey()`, for example). The
1614
- * advantage of using this method is that the parties do not have to
1615
- * generate nor exchange a group modulus beforehand, saving both processor
1616
- * and communication time.
1617
- *
1618
- * Example (obtaining a shared secret):
1619
- *
1620
- * ```js
1621
- * const {
1622
- * getDiffieHellman,
1623
- * } = await import('node:crypto');
1624
- * const alice = getDiffieHellman('modp14');
1625
- * const bob = getDiffieHellman('modp14');
1626
- *
1627
- * alice.generateKeys();
1628
- * bob.generateKeys();
1629
- *
1630
- * const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
1631
- * const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
1632
- *
1633
- * // aliceSecret and bobSecret should be the same
1634
- * console.log(aliceSecret === bobSecret);
1635
- * ```
1636
- * @since v0.7.5
1637
- */
1638
- function getDiffieHellman(groupName: string): DiffieHellmanGroup;
1639
- /**
1640
- * An alias for {@link getDiffieHellman}
1641
- * @since v0.9.3
1642
- */
1643
- function createDiffieHellmanGroup(name: string): DiffieHellmanGroup;
1644
- /**
1645
- * Provides an asynchronous Password-Based Key Derivation Function 2 (PBKDF2)
1646
- * implementation. A selected HMAC digest algorithm specified by `digest` is
1647
- * applied to derive a key of the requested byte length (`keylen`) from the `password`, `salt` and `iterations`.
1648
- *
1649
- * The supplied `callback` function is called with two arguments: `err` and `derivedKey`. If an error occurs while deriving the key, `err` will be set;
1650
- * otherwise `err` will be `null`. By default, the successfully generated `derivedKey` will be passed to the callback as a `Buffer`. An error will be
1651
- * thrown if any of the input arguments specify invalid values or types.
1652
- *
1653
- * The `iterations` argument must be a number set as high as possible. The
1654
- * higher the number of iterations, the more secure the derived key will be,
1655
- * but will take a longer amount of time to complete.
1656
- *
1657
- * The `salt` should be as unique as possible. It is recommended that a salt is
1658
- * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
1659
- *
1660
- * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
1661
- *
1662
- * ```js
1663
- * const {
1664
- * pbkdf2,
1665
- * } = await import('node:crypto');
1666
- *
1667
- * pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
1668
- * if (err) throw err;
1669
- * console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
1670
- * });
1671
- * ```
1672
- *
1673
- * An array of supported digest functions can be retrieved using {@link getHashes}.
1674
- *
1675
- * This API uses libuv's threadpool, which can have surprising and
1676
- * negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
1677
- * @since v0.5.5
1678
- */
1679
- function pbkdf2(
1680
- password: BinaryLike,
1681
- salt: BinaryLike,
1682
- iterations: number,
1683
- keylen: number,
1684
- digest: string,
1685
- callback: (err: Error | null, derivedKey: NonSharedBuffer) => void,
1686
- ): void;
1687
- /**
1688
- * Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2)
1689
- * implementation. A selected HMAC digest algorithm specified by `digest` is
1690
- * applied to derive a key of the requested byte length (`keylen`) from the `password`, `salt` and `iterations`.
1691
- *
1692
- * If an error occurs an `Error` will be thrown, otherwise the derived key will be
1693
- * returned as a `Buffer`.
1694
- *
1695
- * The `iterations` argument must be a number set as high as possible. The
1696
- * higher the number of iterations, the more secure the derived key will be,
1697
- * but will take a longer amount of time to complete.
1698
- *
1699
- * The `salt` should be as unique as possible. It is recommended that a salt is
1700
- * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
1701
- *
1702
- * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
1703
- *
1704
- * ```js
1705
- * const {
1706
- * pbkdf2Sync,
1707
- * } = await import('node:crypto');
1708
- *
1709
- * const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
1710
- * console.log(key.toString('hex')); // '3745e48...08d59ae'
1711
- * ```
1712
- *
1713
- * An array of supported digest functions can be retrieved using {@link getHashes}.
1714
- * @since v0.9.3
1715
- */
1716
- function pbkdf2Sync(
1717
- password: BinaryLike,
1718
- salt: BinaryLike,
1719
- iterations: number,
1720
- keylen: number,
1721
- digest: string,
1722
- ): NonSharedBuffer;
1723
- /**
1724
- * Generates cryptographically strong pseudorandom data. The `size` argument
1725
- * is a number indicating the number of bytes to generate.
1726
- *
1727
- * If a `callback` function is provided, the bytes are generated asynchronously
1728
- * and the `callback` function is invoked with two arguments: `err` and `buf`.
1729
- * If an error occurs, `err` will be an `Error` object; otherwise it is `null`. The `buf` argument is a `Buffer` containing the generated bytes.
1730
- *
1731
- * ```js
1732
- * // Asynchronous
1733
- * const {
1734
- * randomBytes,
1735
- * } = await import('node:crypto');
1736
- *
1737
- * randomBytes(256, (err, buf) => {
1738
- * if (err) throw err;
1739
- * console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
1740
- * });
1741
- * ```
1742
- *
1743
- * If the `callback` function is not provided, the random bytes are generated
1744
- * synchronously and returned as a `Buffer`. An error will be thrown if
1745
- * there is a problem generating the bytes.
1746
- *
1747
- * ```js
1748
- * // Synchronous
1749
- * const {
1750
- * randomBytes,
1751
- * } = await import('node:crypto');
1752
- *
1753
- * const buf = randomBytes(256);
1754
- * console.log(
1755
- * `${buf.length} bytes of random data: ${buf.toString('hex')}`);
1756
- * ```
1757
- *
1758
- * The `crypto.randomBytes()` method will not complete until there is
1759
- * sufficient entropy available.
1760
- * This should normally never take longer than a few milliseconds. The only time
1761
- * when generating the random bytes may conceivably block for a longer period of
1762
- * time is right after boot, when the whole system is still low on entropy.
1763
- *
1764
- * This API uses libuv's threadpool, which can have surprising and
1765
- * negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
1766
- *
1767
- * The asynchronous version of `crypto.randomBytes()` is carried out in a single
1768
- * threadpool request. To minimize threadpool task length variation, partition
1769
- * large `randomBytes` requests when doing so as part of fulfilling a client
1770
- * request.
1771
- * @since v0.5.8
1772
- * @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`.
1773
- * @return if the `callback` function is not provided.
1774
- */
1775
- function randomBytes(size: number): NonSharedBuffer;
1776
- function randomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void;
1777
- function pseudoRandomBytes(size: number): NonSharedBuffer;
1778
- function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: NonSharedBuffer) => void): void;
1779
- /**
1780
- * Return a random integer `n` such that `min <= n < max`. This
1781
- * implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias).
1782
- *
1783
- * The range (`max - min`) must be less than 2**48. `min` and `max` must
1784
- * be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).
1785
- *
1786
- * If the `callback` function is not provided, the random integer is
1787
- * generated synchronously.
1788
- *
1789
- * ```js
1790
- * // Asynchronous
1791
- * const {
1792
- * randomInt,
1793
- * } = await import('node:crypto');
1794
- *
1795
- * randomInt(3, (err, n) => {
1796
- * if (err) throw err;
1797
- * console.log(`Random number chosen from (0, 1, 2): ${n}`);
1798
- * });
1799
- * ```
1800
- *
1801
- * ```js
1802
- * // Synchronous
1803
- * const {
1804
- * randomInt,
1805
- * } = await import('node:crypto');
1806
- *
1807
- * const n = randomInt(3);
1808
- * console.log(`Random number chosen from (0, 1, 2): ${n}`);
1809
- * ```
1810
- *
1811
- * ```js
1812
- * // With `min` argument
1813
- * const {
1814
- * randomInt,
1815
- * } = await import('node:crypto');
1816
- *
1817
- * const n = randomInt(1, 7);
1818
- * console.log(`The dice rolled: ${n}`);
1819
- * ```
1820
- * @since v14.10.0, v12.19.0
1821
- * @param min Start of random range (inclusive).
1822
- * @param max End of random range (exclusive).
1823
- */
1824
- function randomInt(max: number): number;
1825
- function randomInt(min: number, max: number): number;
1826
- function randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
1827
- function randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
1828
- /**
1829
- * Synchronous version of {@link randomFill}.
1830
- *
1831
- * ```js
1832
- * import { Buffer } from 'node:buffer';
1833
- * const { randomFillSync } = await import('node:crypto');
1834
- *
1835
- * const buf = Buffer.alloc(10);
1836
- * console.log(randomFillSync(buf).toString('hex'));
1837
- *
1838
- * randomFillSync(buf, 5);
1839
- * console.log(buf.toString('hex'));
1840
- *
1841
- * // The above is equivalent to the following:
1842
- * randomFillSync(buf, 5, 5);
1843
- * console.log(buf.toString('hex'));
1844
- * ```
1845
- *
1846
- * Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`.
1847
- *
1848
- * ```js
1849
- * import { Buffer } from 'node:buffer';
1850
- * const { randomFillSync } = await import('node:crypto');
1851
- *
1852
- * const a = new Uint32Array(10);
1853
- * console.log(Buffer.from(randomFillSync(a).buffer,
1854
- * a.byteOffset, a.byteLength).toString('hex'));
1855
- *
1856
- * const b = new DataView(new ArrayBuffer(10));
1857
- * console.log(Buffer.from(randomFillSync(b).buffer,
1858
- * b.byteOffset, b.byteLength).toString('hex'));
1859
- *
1860
- * const c = new ArrayBuffer(10);
1861
- * console.log(Buffer.from(randomFillSync(c)).toString('hex'));
1862
- * ```
1863
- * @since v7.10.0, v6.13.0
1864
- * @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
1865
- * @param [offset=0]
1866
- * @param [size=buffer.length - offset]
1867
- * @return The object passed as `buffer` argument.
1868
- */
1869
- function randomFillSync<T extends ArrayBufferLike | NodeJS.ArrayBufferView>(
1870
- buffer: T,
1871
- offset?: number,
1872
- size?: number,
1873
- ): T;
1874
- /**
1875
- * This function is similar to {@link randomBytes} but requires the first
1876
- * argument to be a `Buffer` that will be filled. It also
1877
- * requires that a callback is passed in.
1878
- *
1879
- * If the `callback` function is not provided, an error will be thrown.
1880
- *
1881
- * ```js
1882
- * import { Buffer } from 'node:buffer';
1883
- * const { randomFill } = await import('node:crypto');
1884
- *
1885
- * const buf = Buffer.alloc(10);
1886
- * randomFill(buf, (err, buf) => {
1887
- * if (err) throw err;
1888
- * console.log(buf.toString('hex'));
1889
- * });
1890
- *
1891
- * randomFill(buf, 5, (err, buf) => {
1892
- * if (err) throw err;
1893
- * console.log(buf.toString('hex'));
1894
- * });
1895
- *
1896
- * // The above is equivalent to the following:
1897
- * randomFill(buf, 5, 5, (err, buf) => {
1898
- * if (err) throw err;
1899
- * console.log(buf.toString('hex'));
1900
- * });
1901
- * ```
1902
- *
1903
- * Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as `buffer`.
1904
- *
1905
- * While this includes instances of `Float32Array` and `Float64Array`, this
1906
- * function should not be used to generate random floating-point numbers. The
1907
- * result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array
1908
- * contains finite numbers only, they are not drawn from a uniform random
1909
- * distribution and have no meaningful lower or upper bounds.
1910
- *
1911
- * ```js
1912
- * import { Buffer } from 'node:buffer';
1913
- * const { randomFill } = await import('node:crypto');
1914
- *
1915
- * const a = new Uint32Array(10);
1916
- * randomFill(a, (err, buf) => {
1917
- * if (err) throw err;
1918
- * console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
1919
- * .toString('hex'));
1920
- * });
1921
- *
1922
- * const b = new DataView(new ArrayBuffer(10));
1923
- * randomFill(b, (err, buf) => {
1924
- * if (err) throw err;
1925
- * console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
1926
- * .toString('hex'));
1927
- * });
1928
- *
1929
- * const c = new ArrayBuffer(10);
1930
- * randomFill(c, (err, buf) => {
1931
- * if (err) throw err;
1932
- * console.log(Buffer.from(buf).toString('hex'));
1933
- * });
1934
- * ```
1935
- *
1936
- * This API uses libuv's threadpool, which can have surprising and
1937
- * negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
1938
- *
1939
- * The asynchronous version of `crypto.randomFill()` is carried out in a single
1940
- * threadpool request. To minimize threadpool task length variation, partition
1941
- * large `randomFill` requests when doing so as part of fulfilling a client
1942
- * request.
1943
- * @since v7.10.0, v6.13.0
1944
- * @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
1945
- * @param [offset=0]
1946
- * @param [size=buffer.length - offset]
1947
- * @param callback `function(err, buf) {}`.
1948
- */
1949
- function randomFill<T extends ArrayBufferLike | NodeJS.ArrayBufferView>(
1950
- buffer: T,
1951
- callback: (err: Error | null, buf: T) => void,
1952
- ): void;
1953
- function randomFill<T extends ArrayBufferLike | NodeJS.ArrayBufferView>(
1954
- buffer: T,
1955
- offset: number,
1956
- callback: (err: Error | null, buf: T) => void,
1957
- ): void;
1958
- function randomFill<T extends ArrayBufferLike | NodeJS.ArrayBufferView>(
1959
- buffer: T,
1960
- offset: number,
1961
- size: number,
1962
- callback: (err: Error | null, buf: T) => void,
1963
- ): void;
1964
- interface ScryptOptions {
1965
- cost?: number | undefined;
1966
- blockSize?: number | undefined;
1967
- parallelization?: number | undefined;
1968
- N?: number | undefined;
1969
- r?: number | undefined;
1970
- p?: number | undefined;
1971
- maxmem?: number | undefined;
1972
- }
1973
- /**
1974
- * Provides an asynchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
1975
- * key derivation function that is designed to be expensive computationally and
1976
- * memory-wise in order to make brute-force attacks unrewarding.
1977
- *
1978
- * The `salt` should be as unique as possible. It is recommended that a salt is
1979
- * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
1980
- *
1981
- * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
1982
- *
1983
- * The `callback` function is called with two arguments: `err` and `derivedKey`. `err` is an exception object when key derivation fails, otherwise `err` is `null`. `derivedKey` is passed to the
1984
- * callback as a `Buffer`.
1985
- *
1986
- * An exception is thrown when any of the input arguments specify invalid values
1987
- * or types.
1988
- *
1989
- * ```js
1990
- * const {
1991
- * scrypt,
1992
- * } = await import('node:crypto');
1993
- *
1994
- * // Using the factory defaults.
1995
- * scrypt('password', 'salt', 64, (err, derivedKey) => {
1996
- * if (err) throw err;
1997
- * console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
1998
- * });
1999
- * // Using a custom N parameter. Must be a power of two.
2000
- * scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
2001
- * if (err) throw err;
2002
- * console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
2003
- * });
2004
- * ```
2005
- * @since v10.5.0
2006
- */
2007
- function scrypt(
2008
- password: BinaryLike,
2009
- salt: BinaryLike,
2010
- keylen: number,
2011
- callback: (err: Error | null, derivedKey: NonSharedBuffer) => void,
2012
- ): void;
2013
- function scrypt(
2014
- password: BinaryLike,
2015
- salt: BinaryLike,
2016
- keylen: number,
2017
- options: ScryptOptions,
2018
- callback: (err: Error | null, derivedKey: NonSharedBuffer) => void,
2019
- ): void;
2020
- /**
2021
- * Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
2022
- * key derivation function that is designed to be expensive computationally and
2023
- * memory-wise in order to make brute-force attacks unrewarding.
2024
- *
2025
- * The `salt` should be as unique as possible. It is recommended that a salt is
2026
- * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
2027
- *
2028
- * When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
2029
- *
2030
- * An exception is thrown when key derivation fails, otherwise the derived key is
2031
- * returned as a `Buffer`.
2032
- *
2033
- * An exception is thrown when any of the input arguments specify invalid values
2034
- * or types.
2035
- *
2036
- * ```js
2037
- * const {
2038
- * scryptSync,
2039
- * } = await import('node:crypto');
2040
- * // Using the factory defaults.
2041
- *
2042
- * const key1 = scryptSync('password', 'salt', 64);
2043
- * console.log(key1.toString('hex')); // '3745e48...08d59ae'
2044
- * // Using a custom N parameter. Must be a power of two.
2045
- * const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
2046
- * console.log(key2.toString('hex')); // '3745e48...aa39b34'
2047
- * ```
2048
- * @since v10.5.0
2049
- */
2050
- function scryptSync(
2051
- password: BinaryLike,
2052
- salt: BinaryLike,
2053
- keylen: number,
2054
- options?: ScryptOptions,
2055
- ): NonSharedBuffer;
2056
- interface PublicDecryptOptions {
2057
- padding?: number | undefined;
2058
- encoding?: BufferEncoding | undefined;
2059
- }
2060
- interface PublicDecryptPrivateKeyInput extends PrivateKeyInput, PublicDecryptOptions {}
2061
- interface PublicDecryptPublicKeyInput extends PublicKeyInput, PublicDecryptOptions {}
2062
- interface PublicDecryptJsonWebKeyInput extends JsonWebKeyInput, PublicDecryptOptions {}
2063
- interface PublicDecryptKeyObjectInput extends PublicDecryptOptions {
2064
- key: KeyObject;
2065
- }
2066
- interface PublicEncryptOptions extends PublicDecryptOptions {
2067
- oaepHash?: string | undefined;
2068
- oaepLabel?: BinaryLike | undefined;
2069
- }
2070
- interface PublicEncryptPrivateKeyInput extends PrivateKeyInput, PublicEncryptOptions {}
2071
- interface PublicEncryptPublicKeyInput extends PublicKeyInput, PublicEncryptOptions {}
2072
- interface PublicEncryptJsonWebKeyInput extends JsonWebKeyInput, PublicEncryptOptions {}
2073
- interface PublicEncryptKeyObjectInput extends PublicEncryptOptions {
2074
- key: KeyObject;
2075
- }
2076
- /**
2077
- * Encrypts the content of `buffer` with `key` and returns a new `Buffer` with encrypted content. The returned data can be decrypted using
2078
- * the corresponding private key, for example using {@link privateDecrypt}.
2079
- *
2080
- * If `key` is not a `KeyObject`, this function behaves as if `key` had been passed to {@link createPublicKey}. If it is an
2081
- * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`.
2082
- *
2083
- * Because RSA public keys can be derived from private keys, a private key may
2084
- * be passed instead of a public key.
2085
- * @since v0.11.14
2086
- */
2087
- function publicEncrypt(
2088
- key:
2089
- | KeyLike
2090
- | PublicEncryptKeyObjectInput
2091
- | PublicEncryptPrivateKeyInput
2092
- | PublicEncryptPublicKeyInput
2093
- | PublicEncryptJsonWebKeyInput,
2094
- buffer: BinaryLike,
2095
- ): NonSharedBuffer;
2096
- /**
2097
- * Decrypts `buffer` with `key`.`buffer` was previously encrypted using
2098
- * the corresponding private key, for example using {@link privateEncrypt}.
2099
- *
2100
- * If `key` is not a `KeyObject`, this function behaves as if `key` had been passed to {@link createPublicKey}. If it is an
2101
- * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`.
2102
- *
2103
- * Because RSA public keys can be derived from private keys, a private key may
2104
- * be passed instead of a public key.
2105
- * @since v1.1.0
2106
- */
2107
- function publicDecrypt(
2108
- key:
2109
- | KeyLike
2110
- | PublicDecryptKeyObjectInput
2111
- | PublicDecryptPrivateKeyInput
2112
- | PublicDecryptPublicKeyInput
2113
- | PublicDecryptJsonWebKeyInput,
2114
- buffer: BinaryLike,
2115
- ): NonSharedBuffer;
2116
- /**
2117
- * Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using
2118
- * the corresponding public key, for example using {@link publicEncrypt}.
2119
- *
2120
- * If `privateKey` is not a `KeyObject`, this function behaves as if `privateKey` had been passed to {@link createPrivateKey}. If it is an
2121
- * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_OAEP_PADDING`.
2122
- * @since v0.11.14
2123
- */
2124
- function privateDecrypt(
2125
- privateKey:
2126
- | KeyLike
2127
- | PublicEncryptKeyObjectInput
2128
- | PublicEncryptPrivateKeyInput
2129
- | PublicEncryptJsonWebKeyInput,
2130
- buffer: BinaryLike,
2131
- ): NonSharedBuffer;
2132
- /**
2133
- * Encrypts `buffer` with `privateKey`. The returned data can be decrypted using
2134
- * the corresponding public key, for example using {@link publicDecrypt}.
2135
- *
2136
- * If `privateKey` is not a `KeyObject`, this function behaves as if `privateKey` had been passed to {@link createPrivateKey}. If it is an
2137
- * object, the `padding` property can be passed. Otherwise, this function uses `RSA_PKCS1_PADDING`.
2138
- * @since v1.1.0
2139
- */
2140
- function privateEncrypt(
2141
- privateKey:
2142
- | KeyLike
2143
- | PublicDecryptKeyObjectInput
2144
- | PublicDecryptPrivateKeyInput
2145
- | PublicDecryptJsonWebKeyInput,
2146
- buffer: BinaryLike,
2147
- ): NonSharedBuffer;
2148
- /**
2149
- * ```js
2150
- * const {
2151
- * getCiphers,
2152
- * } = await import('node:crypto');
2153
- *
2154
- * console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
2155
- * ```
2156
- * @since v0.9.3
2157
- * @return An array with the names of the supported cipher algorithms.
2158
- */
2159
- function getCiphers(): string[];
2160
- /**
2161
- * ```js
2162
- * const {
2163
- * getCurves,
2164
- * } = await import('node:crypto');
2165
- *
2166
- * console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
2167
- * ```
2168
- * @since v2.3.0
2169
- * @return An array with the names of the supported elliptic curves.
2170
- */
2171
- function getCurves(): string[];
2172
- /**
2173
- * @since v10.0.0
2174
- * @return `1` if and only if a FIPS compliant crypto provider is currently in use, `0` otherwise. A future semver-major release may change the return type of this API to a {boolean}.
2175
- */
2176
- function getFips(): 1 | 0;
2177
- /**
2178
- * Enables the FIPS compliant crypto provider in a FIPS-enabled Node.js build.
2179
- * Throws an error if FIPS mode is not available.
2180
- * @since v10.0.0
2181
- * @param bool `true` to enable FIPS mode.
2182
- */
2183
- function setFips(bool: boolean): void;
2184
- /**
2185
- * ```js
2186
- * const {
2187
- * getHashes,
2188
- * } = await import('node:crypto');
2189
- *
2190
- * console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
2191
- * ```
2192
- * @since v0.9.3
2193
- * @return An array of the names of the supported hash algorithms, such as `'RSA-SHA256'`. Hash algorithms are also called "digest" algorithms.
2194
- */
2195
- function getHashes(): string[];
2196
- type ECDHKeyFormat = "compressed" | "uncompressed" | "hybrid";
2197
- /**
2198
- * The `ECDH` class is a utility for creating Elliptic Curve Diffie-Hellman (ECDH)
2199
- * key exchanges.
2200
- *
2201
- * Instances of the `ECDH` class can be created using the {@link createECDH} function.
2202
- *
2203
- * ```js
2204
- * import assert from 'node:assert';
2205
- *
2206
- * const {
2207
- * createECDH,
2208
- * } = await import('node:crypto');
2209
- *
2210
- * // Generate Alice's keys...
2211
- * const alice = createECDH('secp521r1');
2212
- * const aliceKey = alice.generateKeys();
2213
- *
2214
- * // Generate Bob's keys...
2215
- * const bob = createECDH('secp521r1');
2216
- * const bobKey = bob.generateKeys();
2217
- *
2218
- * // Exchange and generate the secret...
2219
- * const aliceSecret = alice.computeSecret(bobKey);
2220
- * const bobSecret = bob.computeSecret(aliceKey);
2221
- *
2222
- * assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
2223
- * // OK
2224
- * ```
2225
- * @since v0.11.14
2226
- */
2227
- class ECDH {
2228
- private constructor();
2229
- /**
2230
- * Converts the EC Diffie-Hellman public key specified by `key` and `curve` to the
2231
- * format specified by `format`. The `format` argument specifies point encoding
2232
- * and can be `'compressed'`, `'uncompressed'` or `'hybrid'`. The supplied key is
2233
- * interpreted using the specified `inputEncoding`, and the returned key is encoded
2234
- * using the specified `outputEncoding`.
2235
- *
2236
- * Use {@link getCurves} to obtain a list of available curve names.
2237
- * On recent OpenSSL releases, `openssl ecparam -list_curves` will also display
2238
- * the name and description of each available elliptic curve.
2239
- *
2240
- * If `format` is not specified the point will be returned in `'uncompressed'` format.
2241
- *
2242
- * If the `inputEncoding` is not provided, `key` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
2243
- *
2244
- * Example (uncompressing a key):
2245
- *
2246
- * ```js
2247
- * const {
2248
- * createECDH,
2249
- * ECDH,
2250
- * } = await import('node:crypto');
2251
- *
2252
- * const ecdh = createECDH('secp256k1');
2253
- * ecdh.generateKeys();
2254
- *
2255
- * const compressedKey = ecdh.getPublicKey('hex', 'compressed');
2256
- *
2257
- * const uncompressedKey = ECDH.convertKey(compressedKey,
2258
- * 'secp256k1',
2259
- * 'hex',
2260
- * 'hex',
2261
- * 'uncompressed');
2262
- *
2263
- * // The converted key and the uncompressed public key should be the same
2264
- * console.log(uncompressedKey === ecdh.getPublicKey('hex'));
2265
- * ```
2266
- * @since v10.0.0
2267
- * @param inputEncoding The `encoding` of the `key` string.
2268
- * @param outputEncoding The `encoding` of the return value.
2269
- */
2270
- static convertKey(
2271
- key: BinaryLike,
2272
- curve: string,
2273
- inputEncoding?: BufferEncoding,
2274
- outputEncoding?: null,
2275
- format?: "uncompressed" | "compressed" | "hybrid",
2276
- ): NonSharedBuffer;
2277
- static convertKey(
2278
- key: BinaryLike,
2279
- curve: string,
2280
- inputEncoding: BufferEncoding | null | undefined,
2281
- outputEncoding: BufferEncoding,
2282
- format?: "uncompressed" | "compressed" | "hybrid",
2283
- ): string;
2284
- /**
2285
- * Generates private and public EC Diffie-Hellman key values, and returns
2286
- * the public key in the specified `format` and `encoding`. This key should be
2287
- * transferred to the other party.
2288
- *
2289
- * The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified, the point will be returned in`'uncompressed'` format.
2290
- *
2291
- * If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
2292
- * @since v0.11.14
2293
- * @param encoding The `encoding` of the return value.
2294
- * @param [format='uncompressed']
2295
- */
2296
- generateKeys(encoding?: null, format?: ECDHKeyFormat): NonSharedBuffer;
2297
- generateKeys(encoding: BufferEncoding, format?: ECDHKeyFormat): string;
2298
- /**
2299
- * Computes the shared secret using `otherPublicKey` as the other
2300
- * party's public key and returns the computed shared secret. The supplied
2301
- * key is interpreted using specified `inputEncoding`, and the returned secret
2302
- * is encoded using the specified `outputEncoding`.
2303
- * If the `inputEncoding` is not
2304
- * provided, `otherPublicKey` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
2305
- *
2306
- * If `outputEncoding` is given a string will be returned; otherwise a `Buffer` is returned.
2307
- *
2308
- * `ecdh.computeSecret` will throw an`ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY` error when `otherPublicKey` lies outside of the elliptic curve. Since `otherPublicKey` is
2309
- * usually supplied from a remote user over an insecure network,
2310
- * be sure to handle this exception accordingly.
2311
- * @since v0.11.14
2312
- * @param inputEncoding The `encoding` of the `otherPublicKey` string.
2313
- * @param outputEncoding The `encoding` of the return value.
2314
- */
2315
- computeSecret(otherPublicKey: BinaryLike, inputEncoding?: BufferEncoding): NonSharedBuffer;
2316
- computeSecret(
2317
- otherPublicKey: BinaryLike,
2318
- inputEncoding: BufferEncoding | null | undefined,
2319
- outputEncoding: BufferEncoding,
2320
- ): string;
2321
- /**
2322
- * If `encoding` is specified, a string is returned; otherwise a `Buffer` is
2323
- * returned.
2324
- * @since v0.11.14
2325
- * @param encoding The `encoding` of the return value.
2326
- * @return The EC Diffie-Hellman in the specified `encoding`.
2327
- */
2328
- getPrivateKey(): NonSharedBuffer;
2329
- getPrivateKey(encoding: BufferEncoding): string;
2330
- /**
2331
- * The `format` argument specifies point encoding and can be `'compressed'` or `'uncompressed'`. If `format` is not specified the point will be returned in`'uncompressed'` format.
2332
- *
2333
- * If `encoding` is specified, a string is returned; otherwise a `Buffer` is
2334
- * returned.
2335
- * @since v0.11.14
2336
- * @param encoding The `encoding` of the return value.
2337
- * @param [format='uncompressed']
2338
- * @return The EC Diffie-Hellman public key in the specified `encoding` and `format`.
2339
- */
2340
- getPublicKey(encoding?: null, format?: ECDHKeyFormat): NonSharedBuffer;
2341
- getPublicKey(encoding: BufferEncoding, format?: ECDHKeyFormat): string;
2342
- /**
2343
- * Sets the EC Diffie-Hellman private key.
2344
- * If `encoding` is provided, `privateKey` is expected
2345
- * to be a string; otherwise `privateKey` is expected to be a `Buffer`, `TypedArray`, or `DataView`.
2346
- *
2347
- * If `privateKey` is not valid for the curve specified when the `ECDH` object was
2348
- * created, an error is thrown. Upon setting the private key, the associated
2349
- * public point (key) is also generated and set in the `ECDH` object.
2350
- * @since v0.11.14
2351
- * @param encoding The `encoding` of the `privateKey` string.
2352
- */
2353
- setPrivateKey(privateKey: BinaryLike, encoding?: BufferEncoding): void;
2354
- }
2355
- /**
2356
- * Creates an Elliptic Curve Diffie-Hellman (`ECDH`) key exchange object using a
2357
- * predefined curve specified by the `curveName` string. Use {@link getCurves} to obtain a list of available curve names. On recent
2358
- * OpenSSL releases, `openssl ecparam -list_curves` will also display the name
2359
- * and description of each available elliptic curve.
2360
- * @since v0.11.14
2361
- */
2362
- function createECDH(curveName: string): ECDH;
2363
- /**
2364
- * This function compares the underlying bytes that represent the given `ArrayBuffer`, `TypedArray`, or `DataView` instances using a constant-time
2365
- * algorithm.
2366
- *
2367
- * This function does not leak timing information that
2368
- * would allow an attacker to guess one of the values. This is suitable for
2369
- * comparing HMAC digests or secret values like authentication cookies or [capability urls](https://www.w3.org/TR/capability-urls/).
2370
- *
2371
- * `a` and `b` must both be `Buffer`s, `TypedArray`s, or `DataView`s, and they
2372
- * must have the same byte length. An error is thrown if `a` and `b` have
2373
- * different byte lengths.
2374
- *
2375
- * If at least one of `a` and `b` is a `TypedArray` with more than one byte per
2376
- * entry, such as `Uint16Array`, the result will be computed using the platform
2377
- * byte order.
2378
- *
2379
- * **When both of the inputs are `Float32Array`s or `Float64Array`s, this function might return unexpected results due to IEEE 754**
2380
- * **encoding of floating-point numbers. In particular, neither `x === y` nor `Object.is(x, y)` implies that the byte representations of two floating-point**
2381
- * **numbers `x` and `y` are equal.**
2382
- *
2383
- * Use of `crypto.timingSafeEqual` does not guarantee that the _surrounding_ code
2384
- * is timing-safe. Care should be taken to ensure that the surrounding code does
2385
- * not introduce timing vulnerabilities.
2386
- * @since v6.6.0
2387
- */
2388
- function timingSafeEqual(
2389
- a: ArrayBufferLike | NodeJS.ArrayBufferView,
2390
- b: ArrayBufferLike | NodeJS.ArrayBufferView,
2391
- ): boolean;
2392
- interface DHKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {
2393
- prime?: NodeJS.ArrayBufferView | undefined;
2394
- primeLength?: number | undefined;
2395
- generator?: number | undefined;
2396
- groupName?: string | undefined;
2397
- }
2398
- interface DSAKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {
2399
- modulusLength: number;
2400
- divisorLength?: number | undefined;
2401
- }
2402
- interface ECKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8" | "sec1"> {
2403
- namedCurve: string;
2404
- paramEncoding?: "explicit" | "named" | undefined;
2405
- }
2406
- interface ED25519KeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2407
- interface ED448KeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2408
- interface MLDSAKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2409
- interface MLKEMKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2410
- interface RSAPSSKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {
2411
- modulusLength: number;
2412
- publicExponent?: number | undefined;
2413
- hashAlgorithm?: string | undefined;
2414
- mgf1HashAlgorithm?: string | undefined;
2415
- saltLength?: string | undefined;
2416
- }
2417
- interface RSAKeyPairOptions extends KeyPairExportOptions<"pkcs1" | "spki", "pkcs1" | "pkcs8"> {
2418
- modulusLength: number;
2419
- publicExponent?: number | undefined;
2420
- }
2421
- interface SLHDSAKeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2422
- interface X25519KeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2423
- interface X448KeyPairOptions extends KeyPairExportOptions<"spki", "pkcs8"> {}
2424
- /**
2425
- * Generates a new asymmetric key pair of the given `type`. See the
2426
- * supported [asymmetric key types](https://nodejs.org/docs/latest-v26.x/api/crypto.html#asymmetric-key-types).
2427
- *
2428
- * If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
2429
- * behaves as if `keyObject.export()` had been called on its result. Otherwise,
2430
- * the respective part of the key is returned as a `KeyObject`.
2431
- *
2432
- * When encoding public keys, it is recommended to use `'spki'`. When encoding
2433
- * private keys, it is recommended to use `'pkcs8'` with a strong passphrase,
2434
- * and to keep the passphrase confidential.
2435
- *
2436
- * ```js
2437
- * const {
2438
- * generateKeyPairSync,
2439
- * } = await import('node:crypto');
2440
- *
2441
- * const {
2442
- * publicKey,
2443
- * privateKey,
2444
- * } = generateKeyPairSync('rsa', {
2445
- * modulusLength: 4096,
2446
- * publicKeyEncoding: {
2447
- * type: 'spki',
2448
- * format: 'pem',
2449
- * },
2450
- * privateKeyEncoding: {
2451
- * type: 'pkcs8',
2452
- * format: 'pem',
2453
- * cipher: 'aes-256-cbc',
2454
- * passphrase: 'top secret',
2455
- * },
2456
- * });
2457
- * ```
2458
- *
2459
- * The return value `{ publicKey, privateKey }` represents the generated key pair.
2460
- * When PEM encoding was selected, the respective key will be a string, otherwise
2461
- * it will be a buffer containing the data encoded as DER.
2462
- * @since v10.12.0
2463
- * @param type The asymmetric key type to generate. See the
2464
- * supported [asymmetric key types](https://nodejs.org/docs/latest-v26.x/api/crypto.html#asymmetric-key-types).
2465
- */
2466
- function generateKeyPairSync<T extends DHKeyPairOptions>(
2467
- type: "dh",
2468
- options: T,
2469
- ): KeyPairExportResult<T>;
2470
- function generateKeyPairSync<T extends DSAKeyPairOptions>(
2471
- type: "dsa",
2472
- options: T,
2473
- ): KeyPairExportResult<T>;
2474
- function generateKeyPairSync<T extends ECKeyPairOptions>(
2475
- type: "ec",
2476
- options: T,
2477
- ): KeyPairExportResult<T>;
2478
- function generateKeyPairSync<T extends ED25519KeyPairOptions = {}>(
2479
- type: "ed25519",
2480
- options?: T,
2481
- ): KeyPairExportResult<T>;
2482
- function generateKeyPairSync<T extends ED448KeyPairOptions = {}>(
2483
- type: "ed448",
2484
- options?: T,
2485
- ): KeyPairExportResult<T>;
2486
- function generateKeyPairSync<T extends MLDSAKeyPairOptions = {}>(
2487
- type: MLDSAKeyType,
2488
- options?: T,
2489
- ): KeyPairExportResult<T>;
2490
- function generateKeyPairSync<T extends MLKEMKeyPairOptions = {}>(
2491
- type: MLKEMKeyType,
2492
- options?: T,
2493
- ): KeyPairExportResult<T>;
2494
- function generateKeyPairSync<T extends RSAPSSKeyPairOptions>(
2495
- type: "rsa-pss",
2496
- options: T,
2497
- ): KeyPairExportResult<T>;
2498
- function generateKeyPairSync<T extends RSAKeyPairOptions>(
2499
- type: "rsa",
2500
- options: T,
2501
- ): KeyPairExportResult<T>;
2502
- function generateKeyPairSync<T extends SLHDSAKeyPairOptions = {}>(
2503
- type: SLHDSAKeyType,
2504
- options?: T,
2505
- ): KeyPairExportResult<T>;
2506
- function generateKeyPairSync<T extends X25519KeyPairOptions = {}>(
2507
- type: "x25519",
2508
- options?: T,
2509
- ): KeyPairExportResult<T>;
2510
- function generateKeyPairSync<T extends X448KeyPairOptions = {}>(
2511
- type: "x448",
2512
- options?: T,
2513
- ): KeyPairExportResult<T>;
2514
- /**
2515
- * Generates a new asymmetric key pair of the given `type`. See the
2516
- * supported [asymmetric key types](https://nodejs.org/docs/latest-v26.x/api/crypto.html#asymmetric-key-types).
2517
- *
2518
- * If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
2519
- * behaves as if `keyObject.export()` had been called on its result. Otherwise,
2520
- * the respective part of the key is returned as a `KeyObject`.
2521
- *
2522
- * It is recommended to encode public keys as `'spki'` and private keys as `'pkcs8'` with encryption for long-term storage:
2523
- *
2524
- * ```js
2525
- * const {
2526
- * generateKeyPair,
2527
- * } = await import('node:crypto');
2528
- *
2529
- * generateKeyPair('rsa', {
2530
- * modulusLength: 4096,
2531
- * publicKeyEncoding: {
2532
- * type: 'spki',
2533
- * format: 'pem',
2534
- * },
2535
- * privateKeyEncoding: {
2536
- * type: 'pkcs8',
2537
- * format: 'pem',
2538
- * cipher: 'aes-256-cbc',
2539
- * passphrase: 'top secret',
2540
- * },
2541
- * }, (err, publicKey, privateKey) => {
2542
- * // Handle errors and use the generated key pair.
2543
- * });
2544
- * ```
2545
- *
2546
- * On completion, `callback` will be called with `err` set to `undefined` and `publicKey` / `privateKey` representing the generated key pair.
2547
- *
2548
- * If this method is invoked as its `util.promisify()` ed version, it returns
2549
- * a `Promise` for an `Object` with `publicKey` and `privateKey` properties.
2550
- * @since v10.12.0
2551
- * @param type The asymmetric key type to generate. See the
2552
- * supported [asymmetric key types](https://nodejs.org/docs/latest-v26.x/api/crypto.html#asymmetric-key-types).
2553
- */
2554
- function generateKeyPair<T extends DHKeyPairOptions>(
2555
- type: "dh",
2556
- options: T,
2557
- callback: KeyPairExportCallback<T>,
2558
- ): void;
2559
- function generateKeyPair<T extends DSAKeyPairOptions>(
2560
- type: "dsa",
2561
- options: T,
2562
- callback: KeyPairExportCallback<T>,
2563
- ): void;
2564
- function generateKeyPair<T extends ECKeyPairOptions>(
2565
- type: "ec",
2566
- options: T,
2567
- callback: KeyPairExportCallback<T>,
2568
- ): void;
2569
- function generateKeyPair(
2570
- type: "ed25519",
2571
- callback: KeyPairExportCallback,
2572
- ): void;
2573
- function generateKeyPair<T extends ED25519KeyPairOptions = {}>(
2574
- type: "ed25519",
2575
- options: T | undefined,
2576
- callback: KeyPairExportCallback<T>,
2577
- ): void;
2578
- function generateKeyPair(
2579
- type: "ed448",
2580
- callback: KeyPairExportCallback,
2581
- ): void;
2582
- function generateKeyPair<T extends ED448KeyPairOptions = {}>(
2583
- type: "ed448",
2584
- options: T | undefined,
2585
- callback: KeyPairExportCallback<T>,
2586
- ): void;
2587
- function generateKeyPair(
2588
- type: MLDSAKeyType,
2589
- callback: KeyPairExportCallback,
2590
- ): void;
2591
- function generateKeyPair<T extends MLDSAKeyPairOptions = {}>(
2592
- type: MLDSAKeyType,
2593
- options: T | undefined,
2594
- callback: KeyPairExportCallback<T>,
2595
- ): void;
2596
- function generateKeyPair(
2597
- type: MLKEMKeyType,
2598
- callback: KeyPairExportCallback,
2599
- ): void;
2600
- function generateKeyPair<T extends MLKEMKeyPairOptions = {}>(
2601
- type: MLKEMKeyType,
2602
- options: T | undefined,
2603
- callback: KeyPairExportCallback<T>,
2604
- ): void;
2605
- function generateKeyPair<T extends RSAPSSKeyPairOptions>(
2606
- type: "rsa-pss",
2607
- options: T,
2608
- callback: KeyPairExportCallback<T>,
2609
- ): void;
2610
- function generateKeyPair<T extends RSAKeyPairOptions>(
2611
- type: "rsa",
2612
- options: T,
2613
- callback: KeyPairExportCallback<T>,
2614
- ): void;
2615
- function generateKeyPair(
2616
- type: SLHDSAKeyType,
2617
- callback: KeyPairExportCallback,
2618
- ): void;
2619
- function generateKeyPair<T extends SLHDSAKeyPairOptions = {}>(
2620
- type: SLHDSAKeyType,
2621
- options: T | undefined,
2622
- callback: KeyPairExportCallback<T>,
2623
- ): void;
2624
- function generateKeyPair(
2625
- type: "x25519",
2626
- callback: KeyPairExportCallback,
2627
- ): void;
2628
- function generateKeyPair<T extends X25519KeyPairOptions = {}>(
2629
- type: "x25519",
2630
- options: T | undefined,
2631
- callback: KeyPairExportCallback<T>,
2632
- ): void;
2633
- function generateKeyPair(
2634
- type: "x448",
2635
- callback: KeyPairExportCallback,
2636
- ): void;
2637
- function generateKeyPair<T extends X448KeyPairOptions = {}>(
2638
- type: "x448",
2639
- options: T | undefined,
2640
- callback: KeyPairExportCallback<T>,
2641
- ): void;
2642
- namespace generateKeyPair {
2643
- function __promisify__<T extends DHKeyPairOptions>(
2644
- type: "dh",
2645
- options: T,
2646
- ): Promise<KeyPairExportResult<T>>;
2647
- function __promisify__<T extends DSAKeyPairOptions>(
2648
- type: "dsa",
2649
- options: T,
2650
- ): Promise<KeyPairExportResult<T>>;
2651
- function __promisify__<T extends ECKeyPairOptions>(
2652
- type: "ec",
2653
- options: T,
2654
- ): Promise<KeyPairExportResult<T>>;
2655
- function __promisify__<T extends ED25519KeyPairOptions = {}>(
2656
- type: "ed25519",
2657
- options?: T,
2658
- ): Promise<KeyPairExportResult<T>>;
2659
- function __promisify__<T extends ED448KeyPairOptions = {}>(
2660
- type: "ed448",
2661
- options?: T,
2662
- ): Promise<KeyPairExportResult<T>>;
2663
- function __promisify__<T extends MLDSAKeyPairOptions = {}>(
2664
- type: MLDSAKeyType,
2665
- options?: T,
2666
- ): Promise<KeyPairExportResult<T>>;
2667
- function __promisify__<T extends MLKEMKeyPairOptions = {}>(
2668
- type: MLKEMKeyType,
2669
- options?: T,
2670
- ): Promise<KeyPairExportResult<T>>;
2671
- function __promisify__<T extends RSAPSSKeyPairOptions>(
2672
- type: "rsa-pss",
2673
- options: T,
2674
- ): Promise<KeyPairExportResult<T>>;
2675
- function __promisify__<T extends RSAKeyPairOptions>(
2676
- type: "rsa",
2677
- options: T,
2678
- ): Promise<KeyPairExportResult<T>>;
2679
- function __promisify__<T extends SLHDSAKeyPairOptions = {}>(
2680
- type: SLHDSAKeyType,
2681
- options?: T,
2682
- ): Promise<KeyPairExportResult<T>>;
2683
- function __promisify__<T extends X25519KeyPairOptions = {}>(
2684
- type: "x25519",
2685
- options?: T,
2686
- ): Promise<KeyPairExportResult<T>>;
2687
- function __promisify__<T extends X448KeyPairOptions = {}>(
2688
- type: "x448",
2689
- options?: T,
2690
- ): Promise<KeyPairExportResult<T>>;
2691
- }
2692
- /**
2693
- * Calculates and returns the signature for `data` using the given private key and
2694
- * algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
2695
- * dependent upon the key type.
2696
- *
2697
- * `algorithm` is required to be `null` or `undefined` for Ed25519, Ed448, and
2698
- * ML-DSA.
2699
- *
2700
- * If `key` is not a `KeyObject`, this function behaves as if `key` had been
2701
- * passed to `crypto.createPrivateKey()`. When `key` is a string, `ArrayBuffer`,
2702
- * `Buffer`, `TypedArray`, or `DataView`, it must contain PEM-encoded key
2703
- * material. If it is an object, the following additional properties can be
2704
- * passed:
2705
- *
2706
- * If the `callback` function is provided this function uses libuv's threadpool.
2707
- * @since v12.0.0
2708
- */
2709
- function sign(
2710
- algorithm: string | null | undefined,
2711
- data: BinaryLike,
2712
- key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput,
2713
- ): NonSharedBuffer;
2714
- function sign(
2715
- algorithm: string | null | undefined,
2716
- data: BinaryLike,
2717
- key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput | SignJsonWebKeyInput,
2718
- callback: (error: Error | null, data: NonSharedBuffer) => void,
2719
- ): void;
2720
- /**
2721
- * Verifies the given signature for `data` using the given key and algorithm. If
2722
- * `algorithm` is `null` or `undefined`, then the algorithm is dependent upon the
2723
- * key type.
2724
- *
2725
- * `algorithm` is required to be `null` or `undefined` for Ed25519, Ed448, and
2726
- * ML-DSA.
2727
- *
2728
- * If `key` is not a `KeyObject`, this function behaves as if `key` had been
2729
- * passed to `crypto.createPublicKey()`. When `key` is a string, `ArrayBuffer`,
2730
- * `Buffer`, `TypedArray`, or `DataView`, it must contain PEM-encoded key
2731
- * material. If it is an object, the following additional properties can be
2732
- * passed:
2733
- *
2734
- * The `signature` argument is the previously calculated signature for the `data`.
2735
- *
2736
- * Because public keys can be derived from private keys, a private key or a public
2737
- * key may be passed for `key`.
2738
- *
2739
- * If the `callback` function is provided this function uses libuv's threadpool.
2740
- * @since v12.0.0
2741
- */
2742
- function verify(
2743
- algorithm: string | null | undefined,
2744
- data: BinaryLike,
2745
- key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput | VerifyJsonWebKeyInput,
2746
- signature: BinaryLike,
2747
- ): boolean;
2748
- function verify(
2749
- algorithm: string | null | undefined,
2750
- data: BinaryLike,
2751
- key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput | VerifyJsonWebKeyInput,
2752
- signature: BinaryLike,
2753
- callback: (error: Error | null, result: boolean) => void,
2754
- ): void;
2755
- /**
2756
- * Key decapsulation using a KEM algorithm with a private key.
2757
- *
2758
- * Supported key types and their KEM algorithms are:
2759
- *
2760
- * * `'rsa'` RSA Secret Value Encapsulation
2761
- * * `'ec'` DHKEM(P-256, HKDF-SHA256), DHKEM(P-384, HKDF-SHA256), DHKEM(P-521, HKDF-SHA256)
2762
- * * `'x25519'` DHKEM(X25519, HKDF-SHA256)
2763
- * * `'x448'` DHKEM(X448, HKDF-SHA512)
2764
- * * `'ml-kem-512'` ML-KEM
2765
- * * `'ml-kem-768'` ML-KEM
2766
- * * `'ml-kem-1024'` ML-KEM
2767
- *
2768
- * If `key` is not a {@link KeyObject}, this function behaves as if `key` had been
2769
- * passed to `crypto.createPrivateKey()`.
2770
- *
2771
- * If the `callback` function is provided this function uses libuv's threadpool.
2772
- * @since v24.7.0
2773
- */
2774
- function decapsulate(
2775
- key: KeyLike | PrivateKeyInput | RawPrivateKeyInput | JsonWebKeyInput,
2776
- ciphertext: ArrayBufferLike | NodeJS.ArrayBufferView,
2777
- ): NonSharedBuffer;
2778
- function decapsulate(
2779
- key: KeyLike | PrivateKeyInput | RawPrivateKeyInput | JsonWebKeyInput,
2780
- ciphertext: ArrayBufferLike | NodeJS.ArrayBufferView,
2781
- callback: (err: Error, sharedKey: NonSharedBuffer) => void,
2782
- ): void;
2783
- interface DiffieHellmanOptions {
2784
- privateKey: KeyLike | PrivateKeyInput;
2785
- publicKey: KeyLike | PublicKeyInput;
2786
- }
2787
- /**
2788
- * Computes the Diffie-Hellman shared secret based on a `privateKey` and a `publicKey`.
2789
- * Both keys must have the same `asymmetricKeyType` and must support either the DH or
2790
- * ECDH operation.
2791
- *
2792
- * If the `callback` function is provided this function uses libuv's threadpool.
2793
- * @since v13.9.0, v12.17.0
2794
- */
2795
- function diffieHellman(options: DiffieHellmanOptions): NonSharedBuffer;
2796
- function diffieHellman(
2797
- options: DiffieHellmanOptions,
2798
- callback: (err: Error | null, secret: NonSharedBuffer) => void,
2799
- ): void;
2800
- /**
2801
- * Key encapsulation using a KEM algorithm with a public key.
2802
- *
2803
- * Supported key types and their KEM algorithms are:
2804
- *
2805
- * * `'rsa'` RSA Secret Value Encapsulation
2806
- * * `'ec'` DHKEM(P-256, HKDF-SHA256), DHKEM(P-384, HKDF-SHA256), DHKEM(P-521, HKDF-SHA256)
2807
- * * `'x25519'` DHKEM(X25519, HKDF-SHA256)
2808
- * * `'x448'` DHKEM(X448, HKDF-SHA512)
2809
- * * `'ml-kem-512'` ML-KEM
2810
- * * `'ml-kem-768'` ML-KEM
2811
- * * `'ml-kem-1024'` ML-KEM
2812
- *
2813
- * If `key` is not a {@link KeyObject}, this function behaves as if `key` had been
2814
- * passed to `crypto.createPublicKey()`.
2815
- *
2816
- * If the `callback` function is provided this function uses libuv's threadpool.
2817
- * @since v24.7.0
2818
- */
2819
- function encapsulate(
2820
- key: KeyLike | PublicKeyInput | RawPublicKeyInput | JsonWebKeyInput,
2821
- ): { sharedKey: NonSharedBuffer; ciphertext: NonSharedBuffer };
2822
- function encapsulate(
2823
- key: KeyLike | PublicKeyInput | RawPublicKeyInput | JsonWebKeyInput,
2824
- callback: (err: Error, result: { sharedKey: NonSharedBuffer; ciphertext: NonSharedBuffer }) => void,
2825
- ): void;
2826
- interface OneShotDigestOptions {
2827
- /**
2828
- * Encoding used to encode the returned digest.
2829
- * @default 'hex'
2830
- */
2831
- outputEncoding?: BufferEncoding | "buffer" | undefined;
2832
- /**
2833
- * For XOF hash functions such as 'shake256', the outputLength option
2834
- * can be used to specify the desired output length in bytes.
2835
- */
2836
- outputLength?: number | undefined;
2837
- }
2838
- interface OneShotDigestOptionsWithStringEncoding extends OneShotDigestOptions {
2839
- outputEncoding?: BufferEncoding | undefined;
2840
- }
2841
- interface OneShotDigestOptionsWithBufferEncoding extends OneShotDigestOptions {
2842
- outputEncoding: "buffer";
2843
- }
2844
- /**
2845
- * A utility for creating one-shot hash digests of data. It can be faster than
2846
- * the object-based `crypto.createHash()` when hashing a smaller amount of data
2847
- * (<= 5MB) that's readily available. If the data can be big or if it is streamed,
2848
- * it's still recommended to use `crypto.createHash()` instead.
2849
- *
2850
- * The `algorithm` is dependent on the available algorithms supported by the
2851
- * version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
2852
- * On recent releases of OpenSSL, `openssl list -digest-algorithms` will
2853
- * display the available digest algorithms.
2854
- *
2855
- * If `options` is a string, then it specifies the `outputEncoding`.
2856
- *
2857
- * Example:
2858
- *
2859
- * ```js
2860
- * import crypto from 'node:crypto';
2861
- * import { Buffer } from 'node:buffer';
2862
- *
2863
- * // Hashing a string and return the result as a hex-encoded string.
2864
- * const string = 'Node.js';
2865
- * // 10b3493287f831e81a438811a1ffba01f8cec4b7
2866
- * console.log(crypto.hash('sha1', string));
2867
- *
2868
- * // Encode a base64-encoded string into a Buffer, hash it and return
2869
- * // the result as a buffer.
2870
- * const base64 = 'Tm9kZS5qcw==';
2871
- * // <Buffer 10 b3 49 32 87 f8 31 e8 1a 43 88 11 a1 ff ba 01 f8 ce c4 b7>
2872
- * console.log(crypto.hash('sha1', Buffer.from(base64, 'base64'), 'buffer'));
2873
- * ```
2874
- * @since v21.7.0, v20.12.0
2875
- * @param data When `data` is a string, it will be encoded as UTF-8 before being hashed. If a different
2876
- * input encoding is desired for a string input, user could encode the string
2877
- * into a `TypedArray` using either `TextEncoder` or `Buffer.from()` and passing
2878
- * the encoded `TypedArray` into this API instead.
2879
- */
2880
- function hash(
2881
- algorithm: string,
2882
- data: BinaryLike,
2883
- options?: OneShotDigestOptionsWithStringEncoding | BufferEncoding,
2884
- ): string;
2885
- function hash(
2886
- algorithm: string,
2887
- data: BinaryLike,
2888
- options: OneShotDigestOptionsWithBufferEncoding | "buffer",
2889
- ): NonSharedBuffer;
2890
- function hash(
2891
- algorithm: string,
2892
- data: BinaryLike,
2893
- options: OneShotDigestOptions | BufferEncoding | "buffer",
2894
- ): string | NonSharedBuffer;
2895
- type CipherMode = "cbc" | "ccm" | "cfb" | "ctr" | "ecb" | "gcm" | "ocb" | "ofb" | "stream" | "wrap" | "xts";
2896
- interface CipherInfoOptions {
2897
- /**
2898
- * A test key length.
2899
- */
2900
- keyLength?: number | undefined;
2901
- /**
2902
- * A test IV length.
2903
- */
2904
- ivLength?: number | undefined;
2905
- }
2906
- interface CipherInfo {
2907
- name: string;
2908
- nid: number;
2909
- blockSize?: number;
2910
- ivLength?: number;
2911
- keyLength: number;
2912
- mode: CipherMode;
2913
- }
2914
- /**
2915
- * Returns information about a given cipher.
2916
- *
2917
- * Some ciphers accept variable length keys and initialization vectors. By default,
2918
- * the `crypto.getCipherInfo()` method will return the default values for these
2919
- * ciphers. To test if a given key length or iv length is acceptable for given
2920
- * cipher, use the `keyLength` and `ivLength` options. If the given values are
2921
- * unacceptable, `undefined` will be returned.
2922
- * @since v15.0.0
2923
- * @param nameOrNid The name or nid of the cipher to query.
2924
- */
2925
- function getCipherInfo(nameOrNid: string | number, options?: CipherInfoOptions): CipherInfo | undefined;
2926
- /**
2927
- * HKDF is a simple key derivation function defined in RFC 5869\. The given `ikm`, `salt` and `info` are used with the `digest` to derive a key of `keylen` bytes.
2928
- *
2929
- * The supplied `callback` function is called with two arguments: `err` and `derivedKey`. If an errors occurs while deriving the key, `err` will be set;
2930
- * otherwise `err` will be `null`. The successfully generated `derivedKey` will
2931
- * be passed to the callback as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). An error will be thrown if any
2932
- * of the input arguments specify invalid values or types.
2933
- *
2934
- * ```js
2935
- * import { Buffer } from 'node:buffer';
2936
- * const {
2937
- * hkdf,
2938
- * } = await import('node:crypto');
2939
- *
2940
- * hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
2941
- * if (err) throw err;
2942
- * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
2943
- * });
2944
- * ```
2945
- * @since v15.0.0
2946
- * @param digest The digest algorithm to use.
2947
- * @param ikm The input keying material. Must be provided but can be zero-length.
2948
- * @param salt The salt value. Must be provided but can be zero-length.
2949
- * @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
2950
- * @param keylen The length of the key to generate. Must be greater than 0. The maximum allowable value is `255` times the number of bytes produced by the selected digest function (e.g. `sha512`
2951
- * generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
2952
- */
2953
- function hkdf(
2954
- digest: string,
2955
- ikm: KeyLike,
2956
- salt: BinaryLike,
2957
- info: BinaryLike,
2958
- keylen: number,
2959
- callback: (err: Error | null, derivedKey: ArrayBuffer) => void,
2960
- ): void;
2961
- /**
2962
- * Provides a synchronous HKDF key derivation function as defined in RFC 5869\. The
2963
- * given `ikm`, `salt` and `info` are used with the `digest` to derive a key of `keylen` bytes.
2964
- *
2965
- * The successfully generated `derivedKey` will be returned as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
2966
- *
2967
- * An error will be thrown if any of the input arguments specify invalid values or
2968
- * types, or if the derived key cannot be generated.
2969
- *
2970
- * ```js
2971
- * import { Buffer } from 'node:buffer';
2972
- * const {
2973
- * hkdfSync,
2974
- * } = await import('node:crypto');
2975
- *
2976
- * const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
2977
- * console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
2978
- * ```
2979
- * @since v15.0.0
2980
- * @param digest The digest algorithm to use.
2981
- * @param ikm The input keying material. Must be provided but can be zero-length.
2982
- * @param salt The salt value. Must be provided but can be zero-length.
2983
- * @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
2984
- * @param keylen The length of the key to generate. Must be greater than 0. The maximum allowable value is `255` times the number of bytes produced by the selected digest function (e.g. `sha512`
2985
- * generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
2986
- */
2987
- function hkdfSync(
2988
- digest: string,
2989
- ikm: KeyLike,
2990
- salt: BinaryLike,
2991
- info: BinaryLike,
2992
- keylen: number,
2993
- ): ArrayBuffer;
2994
- interface SecureHeapUsage {
2995
- total: number;
2996
- min: number;
2997
- used: number;
2998
- utilization: number;
2999
- }
3000
- /**
3001
- * @since v15.6.0
3002
- */
3003
- function secureHeapUsed(): SecureHeapUsage;
3004
- interface RandomUUIDOptions {
3005
- /**
3006
- * By default, to improve performance,
3007
- * Node.js will pre-emptively generate and persistently cache enough
3008
- * random data to generate up to 128 random UUIDs. To generate a UUID
3009
- * without using the cache, set `disableEntropyCache` to `true`.
3010
- * @default `false`
3011
- */
3012
- disableEntropyCache?: boolean | undefined;
3013
- }
3014
- interface RandomUUIDV7Options extends RandomUUIDOptions {}
3015
- type UUID = `${string}-${string}-${string}-${string}-${string}`;
3016
- /**
3017
- * Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
3018
- * cryptographic pseudorandom number generator.
3019
- * @since v15.6.0, v14.17.0
3020
- */
3021
- function randomUUID(options?: RandomUUIDOptions): UUID;
3022
- /**
3023
- * Generates a random [RFC 9562](https://www.rfc-editor.org/rfc/rfc9562.txt) version 7 UUID. The UUID contains a millisecond
3024
- * precision Unix timestamp in the most significant 48 bits, followed by
3025
- * cryptographically secure random bits for the remaining fields, making it
3026
- * suitable for use as a database key with time-based sorting. The embedded
3027
- * timestamp relies on a non-monotonic clock and is not guaranteed to be strictly
3028
- * increasing.
3029
- * @since v26.1.0
3030
- */
3031
- function randomUUIDv7(options?: RandomUUIDV7Options): UUID;
3032
- interface X509CheckOptions {
3033
- subject?: "always" | "default" | "never" | undefined;
3034
- wildcards?: boolean | undefined;
3035
- partialWildcards?: boolean | undefined;
3036
- multiLabelWildcards?: boolean | undefined;
3037
- singleLabelSubdomains?: boolean | undefined;
3038
- }
3039
- /**
3040
- * Encapsulates an X509 certificate and provides read-only access to
3041
- * its information.
3042
- *
3043
- * ```js
3044
- * const { X509Certificate } = await import('node:crypto');
3045
- *
3046
- * const x509 = new X509Certificate('{... pem encoded cert ...}');
3047
- *
3048
- * console.log(x509.subject);
3049
- * ```
3050
- * @since v15.6.0
3051
- */
3052
- class X509Certificate {
3053
- /**
3054
- * Will be \`true\` if this is a Certificate Authority (CA) certificate.
3055
- * @since v15.6.0
3056
- */
3057
- readonly ca: boolean;
3058
- /**
3059
- * The SHA-1 fingerprint of this certificate.
3060
- *
3061
- * Because SHA-1 is cryptographically broken and because the security of SHA-1 is
3062
- * significantly worse than that of algorithms that are commonly used to sign
3063
- * certificates, consider using `x509.fingerprint256` instead.
3064
- * @since v15.6.0
3065
- */
3066
- readonly fingerprint: string;
3067
- /**
3068
- * The SHA-256 fingerprint of this certificate.
3069
- * @since v15.6.0
3070
- */
3071
- readonly fingerprint256: string;
3072
- /**
3073
- * The SHA-512 fingerprint of this certificate.
3074
- *
3075
- * Because computing the SHA-256 fingerprint is usually faster and because it is
3076
- * only half the size of the SHA-512 fingerprint, `x509.fingerprint256` may be
3077
- * a better choice. While SHA-512 presumably provides a higher level of security in
3078
- * general, the security of SHA-256 matches that of most algorithms that are
3079
- * commonly used to sign certificates.
3080
- * @since v17.2.0, v16.14.0
3081
- */
3082
- readonly fingerprint512: string;
3083
- /**
3084
- * The complete subject of this certificate.
3085
- * @since v15.6.0
3086
- */
3087
- readonly subject: string;
3088
- /**
3089
- * The subject alternative name specified for this certificate.
3090
- *
3091
- * This is a comma-separated list of subject alternative names. Each entry begins
3092
- * with a string identifying the kind of the subject alternative name followed by
3093
- * a colon and the value associated with the entry.
3094
- *
3095
- * Earlier versions of Node.js incorrectly assumed that it is safe to split this
3096
- * property at the two-character sequence `', '` (see [CVE-2021-44532](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-44532)). However,
3097
- * both malicious and legitimate certificates can contain subject alternative names
3098
- * that include this sequence when represented as a string.
3099
- *
3100
- * After the prefix denoting the type of the entry, the remainder of each entry
3101
- * might be enclosed in quotes to indicate that the value is a JSON string literal.
3102
- * For backward compatibility, Node.js only uses JSON string literals within this
3103
- * property when necessary to avoid ambiguity. Third-party code should be prepared
3104
- * to handle both possible entry formats.
3105
- * @since v15.6.0
3106
- */
3107
- readonly subjectAltName: string | undefined;
3108
- /**
3109
- * A textual representation of the certificate's authority information access
3110
- * extension.
3111
- *
3112
- * This is a line feed separated list of access descriptions. Each line begins with
3113
- * the access method and the kind of the access location, followed by a colon and
3114
- * the value associated with the access location.
3115
- *
3116
- * After the prefix denoting the access method and the kind of the access location,
3117
- * the remainder of each line might be enclosed in quotes to indicate that the
3118
- * value is a JSON string literal. For backward compatibility, Node.js only uses
3119
- * JSON string literals within this property when necessary to avoid ambiguity.
3120
- * Third-party code should be prepared to handle both possible entry formats.
3121
- * @since v15.6.0
3122
- */
3123
- readonly infoAccess: string | undefined;
3124
- /**
3125
- * An array detailing the key usages for this certificate.
3126
- * @since v15.6.0
3127
- */
3128
- readonly keyUsage: string[];
3129
- /**
3130
- * The issuer identification included in this certificate.
3131
- * @since v15.6.0
3132
- */
3133
- readonly issuer: string;
3134
- /**
3135
- * The issuer certificate or `undefined` if the issuer certificate is not
3136
- * available.
3137
- * @since v15.9.0
3138
- */
3139
- readonly issuerCertificate: X509Certificate | undefined;
3140
- /**
3141
- * The public key `KeyObject` for this certificate.
3142
- * @since v15.6.0
3143
- */
3144
- readonly publicKey: KeyObject;
3145
- /**
3146
- * A `Buffer` containing the DER encoding of this certificate.
3147
- * @since v15.6.0
3148
- */
3149
- readonly raw: NonSharedBuffer;
3150
- /**
3151
- * The serial number of this certificate.
3152
- *
3153
- * Serial numbers are assigned by certificate authorities and do not uniquely
3154
- * identify certificates. Consider using `x509.fingerprint256` as a unique
3155
- * identifier instead.
3156
- * @since v15.6.0
3157
- */
3158
- readonly serialNumber: string;
3159
- /**
3160
- * The algorithm used to sign the certificate or `undefined` if the signature algorithm is unknown by OpenSSL.
3161
- * @since v24.9.0
3162
- */
3163
- readonly signatureAlgorithm: string | undefined;
3164
- /**
3165
- * The OID of the algorithm used to sign the certificate.
3166
- * @since v24.9.0
3167
- */
3168
- readonly signatureAlgorithmOid: string;
3169
- /**
3170
- * The date/time from which this certificate is considered valid.
3171
- * @since v15.6.0
3172
- */
3173
- readonly validFrom: string;
3174
- /**
3175
- * The date/time from which this certificate is valid, encapsulated in a `Date` object.
3176
- * @since v22.10.0
3177
- */
3178
- readonly validFromDate: Date;
3179
- /**
3180
- * The date/time until which this certificate is considered valid.
3181
- * @since v15.6.0
3182
- */
3183
- readonly validTo: string;
3184
- /**
3185
- * The date/time until which this certificate is valid, encapsulated in a `Date` object.
3186
- * @since v22.10.0
3187
- */
3188
- readonly validToDate: Date;
3189
- constructor(buffer: string | NodeJS.ArrayBufferView);
3190
- /**
3191
- * Checks whether the certificate matches the given email address.
3192
- *
3193
- * If the `'subject'` option is undefined or set to `'default'`, the certificate
3194
- * subject is only considered if the subject alternative name extension either does
3195
- * not exist or does not contain any email addresses.
3196
- *
3197
- * If the `'subject'` option is set to `'always'` and if the subject alternative
3198
- * name extension either does not exist or does not contain a matching email
3199
- * address, the certificate subject is considered.
3200
- *
3201
- * If the `'subject'` option is set to `'never'`, the certificate subject is never
3202
- * considered, even if the certificate contains no subject alternative names.
3203
- * @since v15.6.0
3204
- * @return Returns `email` if the certificate matches, `undefined` if it does not.
3205
- */
3206
- checkEmail(email: string, options?: Pick<X509CheckOptions, "subject">): string | undefined;
3207
- /**
3208
- * Checks whether the certificate matches the given host name.
3209
- *
3210
- * If the certificate matches the given host name, the matching subject name is
3211
- * returned. The returned name might be an exact match (e.g., `foo.example.com`)
3212
- * or it might contain wildcards (e.g., `*.example.com`). Because host name
3213
- * comparisons are case-insensitive, the returned subject name might also differ
3214
- * from the given `name` in capitalization.
3215
- *
3216
- * If the `'subject'` option is undefined or set to `'default'`, the certificate
3217
- * subject is only considered if the subject alternative name extension either does
3218
- * not exist or does not contain any DNS names. This behavior is consistent with [RFC 2818](https://www.rfc-editor.org/rfc/rfc2818.txt) ("HTTP Over TLS").
3219
- *
3220
- * If the `'subject'` option is set to `'always'` and if the subject alternative
3221
- * name extension either does not exist or does not contain a matching DNS name,
3222
- * the certificate subject is considered.
3223
- *
3224
- * If the `'subject'` option is set to `'never'`, the certificate subject is never
3225
- * considered, even if the certificate contains no subject alternative names.
3226
- * @since v15.6.0
3227
- * @return Returns a subject name that matches `name`, or `undefined` if no subject name matches `name`.
3228
- */
3229
- checkHost(name: string, options?: X509CheckOptions): string | undefined;
3230
- /**
3231
- * Checks whether the certificate matches the given IP address (IPv4 or IPv6).
3232
- *
3233
- * Only [RFC 5280](https://www.rfc-editor.org/rfc/rfc5280.txt) `iPAddress` subject alternative names are considered, and they
3234
- * must match the given `ip` address exactly. Other subject alternative names as
3235
- * well as the subject field of the certificate are ignored.
3236
- * @since v15.6.0
3237
- * @return Returns `ip` if the certificate matches, `undefined` if it does not.
3238
- */
3239
- checkIP(ip: string): string | undefined;
3240
- /**
3241
- * Checks whether this certificate was potentially issued by the given `otherCert`
3242
- * by comparing the certificate metadata.
3243
- *
3244
- * This is useful for pruning a list of possible issuer certificates which have been
3245
- * selected using a more rudimentary filtering routine, i.e. just based on subject
3246
- * and issuer names.
3247
- *
3248
- * Finally, to verify that this certificate's signature was produced by a private key
3249
- * corresponding to `otherCert`'s public key use `x509.verify(publicKey)`
3250
- * with `otherCert`'s public key represented as a `KeyObject`
3251
- * like so
3252
- *
3253
- * ```js
3254
- * if (!x509.verify(otherCert.publicKey)) {
3255
- * throw new Error('otherCert did not issue x509');
3256
- * }
3257
- * ```
3258
- * @since v15.6.0
3259
- */
3260
- checkIssued(otherCert: X509Certificate): boolean;
3261
- /**
3262
- * Checks whether the public key for this certificate is consistent with
3263
- * the given private key.
3264
- * @since v15.6.0
3265
- * @param privateKey A private key.
3266
- */
3267
- checkPrivateKey(privateKey: KeyObject): boolean;
3268
- /**
3269
- * There is no standard JSON encoding for X509 certificates. The`toJSON()` method returns a string containing the PEM encoded
3270
- * certificate.
3271
- * @since v15.6.0
3272
- */
3273
- toJSON(): string;
3274
- /**
3275
- * Returns information about this certificate using the legacy `certificate object` encoding.
3276
- * @since v15.6.0
3277
- */
3278
- toLegacyObject(): PeerCertificate;
3279
- /**
3280
- * Returns the PEM-encoded certificate.
3281
- * @since v15.6.0
3282
- */
3283
- toString(): string;
3284
- /**
3285
- * Verifies that this certificate was signed by the given public key.
3286
- * Does not perform any other validation checks on the certificate.
3287
- * @since v15.6.0
3288
- * @param publicKey A public key.
3289
- */
3290
- verify(publicKey: KeyObject): boolean;
3291
- }
3292
- type LargeNumberLike = ArrayBufferLike | NodeJS.ArrayBufferView | bigint;
3293
- interface GeneratePrimeOptions {
3294
- add?: LargeNumberLike | undefined;
3295
- rem?: LargeNumberLike | undefined;
3296
- safe?: boolean | undefined;
3297
- bigint?: boolean | undefined;
3298
- }
3299
- interface GeneratePrimeOptionsBigInt extends GeneratePrimeOptions {
3300
- bigint: true;
3301
- }
3302
- interface GeneratePrimeOptionsArrayBuffer extends GeneratePrimeOptions {
3303
- bigint?: false | undefined;
3304
- }
3305
- /**
3306
- * Generates a pseudorandom prime of `size` bits.
3307
- *
3308
- * If `options.safe` is `true`, the prime will be a safe prime -- that is, `(prime - 1) / 2` will also be a prime.
3309
- *
3310
- * The `options.add` and `options.rem` parameters can be used to enforce additional
3311
- * requirements, e.g., for Diffie-Hellman:
3312
- *
3313
- * * If `options.add` and `options.rem` are both set, the prime will satisfy the
3314
- * condition that `prime % add = rem`.
3315
- * * If only `options.add` is set and `options.safe` is not `true`, the prime will
3316
- * satisfy the condition that `prime % add = 1`.
3317
- * * If only `options.add` is set and `options.safe` is set to `true`, the prime
3318
- * will instead satisfy the condition that `prime % add = 3`. This is necessary
3319
- * because `prime % add = 1` for `options.add > 2` would contradict the condition
3320
- * enforced by `options.safe`.
3321
- * * `options.rem` is ignored if `options.add` is not given.
3322
- *
3323
- * Both `options.add` and `options.rem` must be encoded as big-endian sequences
3324
- * if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or `DataView`.
3325
- *
3326
- * By default, the prime is encoded as a big-endian sequence of octets
3327
- * in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
3328
- * [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
3329
- * @since v15.8.0
3330
- * @param size The size (in bits) of the prime to generate.
3331
- */
3332
- function generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
3333
- function generatePrime(
3334
- size: number,
3335
- options: GeneratePrimeOptionsArrayBuffer,
3336
- callback: (err: Error | null, prime: ArrayBuffer) => void,
3337
- ): void;
3338
- function generatePrime(
3339
- size: number,
3340
- options: GeneratePrimeOptionsBigInt,
3341
- callback: (err: Error | null, prime: bigint) => void,
3342
- ): void;
3343
- function generatePrime(
3344
- size: number,
3345
- options: GeneratePrimeOptions,
3346
- callback: (err: Error | null, prime: ArrayBuffer | bigint) => void,
3347
- ): void;
3348
- /**
3349
- * Generates a pseudorandom prime of `size` bits.
3350
- *
3351
- * If `options.safe` is `true`, the prime will be a safe prime -- that is, `(prime - 1) / 2` will also be a prime.
3352
- *
3353
- * The `options.add` and `options.rem` parameters can be used to enforce additional
3354
- * requirements, e.g., for Diffie-Hellman:
3355
- *
3356
- * * If `options.add` and `options.rem` are both set, the prime will satisfy the
3357
- * condition that `prime % add = rem`.
3358
- * * If only `options.add` is set and `options.safe` is not `true`, the prime will
3359
- * satisfy the condition that `prime % add = 1`.
3360
- * * If only `options.add` is set and `options.safe` is set to `true`, the prime
3361
- * will instead satisfy the condition that `prime % add = 3`. This is necessary
3362
- * because `prime % add = 1` for `options.add > 2` would contradict the condition
3363
- * enforced by `options.safe`.
3364
- * * `options.rem` is ignored if `options.add` is not given.
3365
- *
3366
- * Both `options.add` and `options.rem` must be encoded as big-endian sequences
3367
- * if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or `DataView`.
3368
- *
3369
- * By default, the prime is encoded as a big-endian sequence of octets
3370
- * in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
3371
- * [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
3372
- * @since v15.8.0
3373
- * @param size The size (in bits) of the prime to generate.
3374
- */
3375
- function generatePrimeSync(size: number): ArrayBuffer;
3376
- function generatePrimeSync(size: number, options: GeneratePrimeOptionsArrayBuffer): ArrayBuffer;
3377
- function generatePrimeSync(size: number, options: GeneratePrimeOptionsBigInt): bigint;
3378
- function generatePrimeSync(size: number, options: GeneratePrimeOptions): ArrayBuffer | bigint;
3379
- interface CheckPrimeOptions {
3380
- /**
3381
- * The number of Miller-Rabin probabilistic primality iterations to perform.
3382
- * When the value is 0 (zero), a number of checks is used that yields a false positive rate of at most `2**-64` for random input.
3383
- * Care must be used when selecting a number of checks.
3384
- * Refer to the OpenSSL documentation for the BN_is_prime_ex function nchecks options for more details.
3385
- * @default 0
3386
- */
3387
- checks?: number | undefined;
3388
- }
3389
- /**
3390
- * Checks the primality of the `candidate`.
3391
- * @since v15.8.0
3392
- * @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
3393
- */
3394
- function checkPrime(value: LargeNumberLike, callback: (err: Error | null, result: boolean) => void): void;
3395
- function checkPrime(
3396
- value: LargeNumberLike,
3397
- options: CheckPrimeOptions,
3398
- callback: (err: Error | null, result: boolean) => void,
3399
- ): void;
3400
- /**
3401
- * Checks the primality of the `candidate`.
3402
- * @since v15.8.0
3403
- * @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
3404
- * @return `true` if the candidate is a prime with an error probability less than `0.25 ** options.checks`.
3405
- */
3406
- function checkPrimeSync(candidate: LargeNumberLike, options?: CheckPrimeOptions): boolean;
3407
- /**
3408
- * Load and set the `engine` for some or all OpenSSL functions (selected by flags).
3409
- *
3410
- * `engine` could be either an id or a path to the engine's shared library.
3411
- *
3412
- * The optional `flags` argument uses `ENGINE_METHOD_ALL` by default. The `flags` is a bit field taking one of or a mix of the following flags (defined in `crypto.constants`):
3413
- *
3414
- * * `crypto.constants.ENGINE_METHOD_RSA`
3415
- * * `crypto.constants.ENGINE_METHOD_DSA`
3416
- * * `crypto.constants.ENGINE_METHOD_DH`
3417
- * * `crypto.constants.ENGINE_METHOD_RAND`
3418
- * * `crypto.constants.ENGINE_METHOD_EC`
3419
- * * `crypto.constants.ENGINE_METHOD_CIPHERS`
3420
- * * `crypto.constants.ENGINE_METHOD_DIGESTS`
3421
- * * `crypto.constants.ENGINE_METHOD_PKEY_METHS`
3422
- * * `crypto.constants.ENGINE_METHOD_PKEY_ASN1_METHS`
3423
- * * `crypto.constants.ENGINE_METHOD_ALL`
3424
- * * `crypto.constants.ENGINE_METHOD_NONE`
3425
- * @since v0.11.11
3426
- * @param flags
3427
- */
3428
- function setEngine(engine: string, flags?: number): void;
3429
- /**
3430
- * A convenient alias for {@link webcrypto.getRandomValues}. This
3431
- * implementation is not compliant with the Web Crypto spec, to write
3432
- * web-compatible code use {@link webcrypto.getRandomValues} instead.
3433
- * @since v17.4.0
3434
- * @return Returns `typedArray`.
3435
- */
3436
- function getRandomValues<
3437
- T extends Exclude<
3438
- NodeJS.NonSharedTypedArray,
3439
- NodeJS.NonSharedFloat16Array | NodeJS.NonSharedFloat32Array | NodeJS.NonSharedFloat64Array
3440
- >,
3441
- >(typedArray: T): T;
3442
- type Argon2Algorithm = "argon2d" | "argon2i" | "argon2id";
3443
- interface Argon2Parameters {
3444
- message: BinaryLike;
3445
- nonce: BinaryLike;
3446
- parallelism: number;
3447
- tagLength: number;
3448
- memory: number;
3449
- passes: number;
3450
- secret?: BinaryLike | undefined;
3451
- associatedData?: BinaryLike | undefined;
3452
- }
3453
- /**
3454
- * Provides an asynchronous [Argon2](https://www.rfc-editor.org/rfc/rfc9106.html) implementation. Argon2 is a password-based
3455
- * key derivation function that is designed to be expensive computationally and
3456
- * memory-wise in order to make brute-force attacks unrewarding.
3457
- *
3458
- * The `nonce` should be as unique as possible. It is recommended that a nonce is
3459
- * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
3460
- *
3461
- * When passing strings for `message`, `nonce`, `secret` or `associatedData`, please
3462
- * consider [caveats when using strings as inputs to cryptographic APIs](https://nodejs.org/docs/latest-v26.x/api/crypto.html#using-strings-as-inputs-to-cryptographic-apis).
3463
- *
3464
- * The `callback` function is called with two arguments: `err` and `derivedKey`.
3465
- * `err` is an exception object when key derivation fails, otherwise `err` is
3466
- * `null`. `derivedKey` is passed to the callback as a `Buffer`.
3467
- *
3468
- * An exception is thrown when any of the input arguments specify invalid values
3469
- * or types.
3470
- *
3471
- * ```js
3472
- * const { argon2, randomBytes } = await import('node:crypto');
3473
- *
3474
- * const parameters = {
3475
- * message: 'password',
3476
- * nonce: randomBytes(16),
3477
- * parallelism: 4,
3478
- * tagLength: 64,
3479
- * memory: 65536,
3480
- * passes: 3,
3481
- * };
3482
- *
3483
- * argon2('argon2id', parameters, (err, derivedKey) => {
3484
- * if (err) throw err;
3485
- * console.log(derivedKey.toString('hex')); // 'af91dad...9520f15'
3486
- * });
3487
- * ```
3488
- * @since v24.7.0
3489
- * @param algorithm Variant of Argon2, one of `"argon2d"`, `"argon2i"` or `"argon2id"`.
3490
- */
3491
- function argon2(
3492
- algorithm: Argon2Algorithm,
3493
- parameters: Argon2Parameters,
3494
- callback: (err: Error | null, derivedKey: NonSharedBuffer) => void,
3495
- ): void;
3496
- /**
3497
- * Provides a synchronous [Argon2][] implementation. Argon2 is a password-based
3498
- * key derivation function that is designed to be expensive computationally and
3499
- * memory-wise in order to make brute-force attacks unrewarding.
3500
- *
3501
- * The `nonce` should be as unique as possible. It is recommended that a nonce is
3502
- * random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
3503
- *
3504
- * When passing strings for `message`, `nonce`, `secret` or `associatedData`, please
3505
- * consider [caveats when using strings as inputs to cryptographic APIs](https://nodejs.org/docs/latest-v26.x/api/crypto.html#using-strings-as-inputs-to-cryptographic-apis).
3506
- *
3507
- * An exception is thrown when key derivation fails, otherwise the derived key is
3508
- * returned as a `Buffer`.
3509
- *
3510
- * An exception is thrown when any of the input arguments specify invalid values
3511
- * or types.
3512
- *
3513
- * ```js
3514
- * const { argon2Sync, randomBytes } = await import('node:crypto');
3515
- *
3516
- * const parameters = {
3517
- * message: 'password',
3518
- * nonce: randomBytes(16),
3519
- * parallelism: 4,
3520
- * tagLength: 64,
3521
- * memory: 65536,
3522
- * passes: 3,
3523
- * };
3524
- *
3525
- * const derivedKey = argon2Sync('argon2id', parameters);
3526
- * console.log(derivedKey.toString('hex')); // 'af91dad...9520f15'
3527
- * ```
3528
- * @since v24.7.0
3529
- */
3530
- function argon2Sync(algorithm: Argon2Algorithm, parameters: Argon2Parameters): NonSharedBuffer;
3531
- /**
3532
- * A convenient alias for `crypto.webcrypto.subtle`.
3533
- * @since v17.4.0
3534
- */
3535
- const subtle: webcrypto.SubtleCrypto;
3536
- /**
3537
- * An implementation of the Web Crypto API standard.
3538
- *
3539
- * See the {@link https://nodejs.org/docs/latest/api/webcrypto.html Web Crypto API documentation} for details.
3540
- * @since v15.0.0
3541
- */
3542
- const webcrypto: webcrypto.Crypto;
3543
- namespace webcrypto {
3544
- type AlgorithmIdentifier = Algorithm | string;
3545
- type BigInteger = NodeJS.NonSharedUint8Array;
3546
- type KeyFormat = "jwk" | "pkcs8" | "raw" | "raw-public" | "raw-secret" | "raw-seed" | "spki";
3547
- type KeyType = "private" | "public" | "secret";
3548
- type KeyUsage =
3549
- | "decapsulateBits"
3550
- | "decapsulateKey"
3551
- | "decrypt"
3552
- | "deriveBits"
3553
- | "deriveKey"
3554
- | "encapsulateBits"
3555
- | "encapsulateKey"
3556
- | "encrypt"
3557
- | "sign"
3558
- | "unwrapKey"
3559
- | "verify"
3560
- | "wrapKey";
3561
- type HashAlgorithmIdentifier = AlgorithmIdentifier;
3562
- type NamedCurve = string;
3563
- interface AeadParams extends Algorithm {
3564
- additionalData?: NodeJS.BufferSource;
3565
- iv: NodeJS.BufferSource;
3566
- tagLength: number;
3567
- }
3568
- interface AesCbcParams extends Algorithm {
3569
- iv: NodeJS.BufferSource;
3570
- }
3571
- interface AesCtrParams extends Algorithm {
3572
- counter: NodeJS.BufferSource;
3573
- length: number;
3574
- }
3575
- interface AesDerivedKeyParams extends Algorithm {
3576
- length: number;
3577
- }
3578
- interface AesKeyAlgorithm extends KeyAlgorithm {
3579
- length: number;
3580
- }
3581
- interface AesKeyGenParams extends Algorithm {
3582
- length: number;
3583
- }
3584
- interface Algorithm {
3585
- name: string;
3586
- }
3587
- interface Argon2Params extends Algorithm {
3588
- associatedData?: NodeJS.BufferSource;
3589
- memory: number;
3590
- nonce: NodeJS.BufferSource;
3591
- parallelism: number;
3592
- passes: number;
3593
- secretValue?: NodeJS.BufferSource;
3594
- version?: number;
3595
- }
3596
- interface CShakeParams extends Algorithm {
3597
- customization?: NodeJS.BufferSource;
3598
- functionName?: NodeJS.BufferSource;
3599
- outputLength: number;
3600
- }
3601
- interface ContextParams extends Algorithm {
3602
- context?: NodeJS.BufferSource;
3603
- }
3604
- interface EcKeyAlgorithm extends KeyAlgorithm {
3605
- namedCurve: NamedCurve;
3606
- }
3607
- interface EcKeyGenParams extends Algorithm {
3608
- namedCurve: NamedCurve;
3609
- }
3610
- interface EcKeyImportParams extends Algorithm {
3611
- namedCurve: NamedCurve;
3612
- }
3613
- interface EcdhKeyDeriveParams extends Algorithm {
3614
- public: CryptoKey;
3615
- }
3616
- interface EcdsaParams extends Algorithm {
3617
- hash: HashAlgorithmIdentifier;
3618
- }
3619
- interface HkdfParams extends Algorithm {
3620
- hash: HashAlgorithmIdentifier;
3621
- info: NodeJS.BufferSource;
3622
- salt: NodeJS.BufferSource;
3623
- }
3624
- interface HmacImportParams extends Algorithm {
3625
- hash: HashAlgorithmIdentifier;
3626
- length?: number;
3627
- }
3628
- interface HmacKeyAlgorithm extends KeyAlgorithm {
3629
- hash: KeyAlgorithm;
3630
- length: number;
3631
- }
3632
- interface HmacKeyGenParams extends Algorithm {
3633
- hash: HashAlgorithmIdentifier;
3634
- length?: number;
3635
- }
3636
- interface KangarooTwelveParams {
3637
- customization?: NodeJS.BufferSource;
3638
- outputLength: number;
3639
- }
3640
- interface JsonWebKey {
3641
- alg?: string;
3642
- crv?: string;
3643
- d?: string;
3644
- dp?: string;
3645
- dq?: string;
3646
- e?: string;
3647
- ext?: boolean;
3648
- k?: string;
3649
- key_ops?: string[];
3650
- kty?: string;
3651
- n?: string;
3652
- oth?: RsaOtherPrimesInfo[];
3653
- p?: string;
3654
- q?: string;
3655
- qi?: string;
3656
- use?: string;
3657
- x?: string;
3658
- y?: string;
3659
- }
3660
- interface KeyAlgorithm {
3661
- name: string;
3662
- }
3663
- interface KmacImportParams extends Algorithm {
3664
- length?: number;
3665
- }
3666
- interface KmacKeyAlgorithm extends KeyAlgorithm {
3667
- length: number;
3668
- }
3669
- interface KmacKeyGenParams extends Algorithm {
3670
- length?: number;
3671
- }
3672
- interface KmacParams extends Algorithm {
3673
- customization?: NodeJS.BufferSource;
3674
- outputLength: number;
3675
- }
3676
- interface Pbkdf2Params extends Algorithm {
3677
- hash: HashAlgorithmIdentifier;
3678
- iterations: number;
3679
- salt: NodeJS.BufferSource;
3680
- }
3681
- interface RsaHashedImportParams extends Algorithm {
3682
- hash: HashAlgorithmIdentifier;
3683
- }
3684
- interface RsaHashedKeyAlgorithm extends RsaKeyAlgorithm {
3685
- hash: KeyAlgorithm;
3686
- }
3687
- interface RsaHashedKeyGenParams extends RsaKeyGenParams {
3688
- hash: HashAlgorithmIdentifier;
3689
- }
3690
- interface RsaKeyAlgorithm extends KeyAlgorithm {
3691
- modulusLength: number;
3692
- publicExponent: BigInteger;
3693
- }
3694
- interface RsaKeyGenParams extends Algorithm {
3695
- modulusLength: number;
3696
- publicExponent: BigInteger;
3697
- }
3698
- interface RsaOaepParams extends Algorithm {
3699
- label?: NodeJS.BufferSource;
3700
- }
3701
- interface RsaOtherPrimesInfo {
3702
- d?: string;
3703
- r?: string;
3704
- t?: string;
3705
- }
3706
- interface RsaPssParams extends Algorithm {
3707
- saltLength: number;
3708
- }
3709
- interface TurboShakeParams {
3710
- domainSeparation?: number;
3711
- outputLength: number;
3712
- }
3713
- interface Crypto {
3714
- readonly subtle: SubtleCrypto;
3715
- getRandomValues<
3716
- T extends Exclude<
3717
- NodeJS.NonSharedTypedArray,
3718
- NodeJS.NonSharedFloat16Array | NodeJS.NonSharedFloat32Array | NodeJS.NonSharedFloat64Array
3719
- >,
3720
- >(
3721
- typedArray: T,
3722
- ): T;
3723
- randomUUID(): UUID;
3724
- }
3725
- interface CryptoKey {
3726
- readonly algorithm: KeyAlgorithm;
3727
- readonly extractable: boolean;
3728
- readonly type: KeyType;
3729
- readonly usages: KeyUsage[];
3730
- }
3731
- interface CryptoKeyPair {
3732
- privateKey: CryptoKey;
3733
- publicKey: CryptoKey;
3734
- }
3735
- interface EncapsulatedBits {
3736
- sharedKey: ArrayBuffer;
3737
- ciphertext: ArrayBuffer;
3738
- }
3739
- interface EncapsulatedKey {
3740
- sharedKey: CryptoKey;
3741
- ciphertext: ArrayBuffer;
3742
- }
3743
- interface SubtleCrypto {
3744
- decapsulateBits(
3745
- decapsulationAlgorithm: AlgorithmIdentifier,
3746
- decapsulationKey: CryptoKey,
3747
- ciphertext: NodeJS.BufferSource,
3748
- ): Promise<ArrayBuffer>;
3749
- decapsulateKey(
3750
- decapsulationAlgorithm: AlgorithmIdentifier,
3751
- decapsulationKey: CryptoKey,
3752
- ciphertext: NodeJS.BufferSource,
3753
- sharedKeyAlgorithm: AlgorithmIdentifier | HmacImportParams | AesDerivedKeyParams | KmacImportParams,
3754
- extractable: boolean,
3755
- keyUsages: KeyUsage[],
3756
- ): Promise<CryptoKey>;
3757
- decrypt(
3758
- algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AeadParams,
3759
- key: CryptoKey,
3760
- data: NodeJS.BufferSource,
3761
- ): Promise<ArrayBuffer>;
3762
- deriveBits(
3763
- algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params | Argon2Params,
3764
- baseKey: CryptoKey,
3765
- length?: number | null,
3766
- ): Promise<ArrayBuffer>;
3767
- deriveKey(
3768
- algorithm: AlgorithmIdentifier | EcdhKeyDeriveParams | HkdfParams | Pbkdf2Params | Argon2Params,
3769
- baseKey: CryptoKey,
3770
- derivedKeyType: AlgorithmIdentifier | AesDerivedKeyParams | HmacImportParams | KmacImportParams,
3771
- extractable: boolean,
3772
- keyUsages: readonly KeyUsage[],
3773
- ): Promise<CryptoKey>;
3774
- digest(
3775
- algorithm: AlgorithmIdentifier | CShakeParams | TurboShakeParams | KangarooTwelveParams,
3776
- data: NodeJS.BufferSource,
3777
- ): Promise<ArrayBuffer>;
3778
- encapsulateBits(
3779
- encapsulationAlgorithm: AlgorithmIdentifier,
3780
- encapsulationKey: CryptoKey,
3781
- ): Promise<EncapsulatedBits>;
3782
- encapsulateKey(
3783
- encapsulationAlgorithm: AlgorithmIdentifier,
3784
- encapsulationKey: CryptoKey,
3785
- sharedKeyAlgorithm: AlgorithmIdentifier | AesDerivedKeyParams | HmacImportParams | KmacImportParams,
3786
- extractable: boolean,
3787
- keyUsages: KeyUsage[],
3788
- ): Promise<EncapsulatedKey>;
3789
- encrypt(
3790
- algorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AeadParams,
3791
- key: CryptoKey,
3792
- data: NodeJS.BufferSource,
3793
- ): Promise<ArrayBuffer>;
3794
- exportKey(format: "jwk", key: CryptoKey): Promise<JsonWebKey>;
3795
- exportKey(format: Exclude<KeyFormat, "jwk">, key: CryptoKey): Promise<ArrayBuffer>;
3796
- exportKey(format: KeyFormat, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>;
3797
- generateKey(
3798
- algorithm: RsaHashedKeyGenParams | EcKeyGenParams,
3799
- extractable: boolean,
3800
- keyUsages: KeyUsage[],
3801
- ): Promise<CryptoKeyPair>;
3802
- generateKey(
3803
- algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params | KmacKeyGenParams,
3804
- extractable: boolean,
3805
- keyUsages: KeyUsage[],
3806
- ): Promise<CryptoKey>;
3807
- generateKey(
3808
- algorithm: AlgorithmIdentifier,
3809
- extractable: boolean,
3810
- keyUsages: KeyUsage[],
3811
- ): Promise<CryptoKeyPair | CryptoKey>;
3812
- getPublicKey(key: CryptoKey, keyUsages: KeyUsage[]): Promise<CryptoKey>;
3813
- importKey(
3814
- format: "jwk",
3815
- keyData: JsonWebKey,
3816
- algorithm:
3817
- | AlgorithmIdentifier
3818
- | RsaHashedImportParams
3819
- | EcKeyImportParams
3820
- | HmacImportParams
3821
- | AesKeyAlgorithm
3822
- | KmacImportParams,
3823
- extractable: boolean,
3824
- keyUsages: KeyUsage[],
3825
- ): Promise<CryptoKey>;
3826
- importKey(
3827
- format: Exclude<KeyFormat, "jwk">,
3828
- keyData: NodeJS.BufferSource,
3829
- algorithm:
3830
- | AlgorithmIdentifier
3831
- | RsaHashedImportParams
3832
- | EcKeyImportParams
3833
- | HmacImportParams
3834
- | AesKeyAlgorithm
3835
- | KmacImportParams,
3836
- extractable: boolean,
3837
- keyUsages: KeyUsage[],
3838
- ): Promise<CryptoKey>;
3839
- sign(
3840
- algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | ContextParams | KmacParams,
3841
- key: CryptoKey,
3842
- data: NodeJS.BufferSource,
3843
- ): Promise<ArrayBuffer>;
3844
- unwrapKey(
3845
- format: KeyFormat,
3846
- wrappedKey: NodeJS.BufferSource,
3847
- unwrappingKey: CryptoKey,
3848
- unwrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AeadParams,
3849
- unwrappedKeyAlgorithm:
3850
- | AlgorithmIdentifier
3851
- | RsaHashedImportParams
3852
- | EcKeyImportParams
3853
- | HmacImportParams
3854
- | AesKeyAlgorithm
3855
- | KmacImportParams,
3856
- extractable: boolean,
3857
- keyUsages: KeyUsage[],
3858
- ): Promise<CryptoKey>;
3859
- verify(
3860
- algorithm: AlgorithmIdentifier | RsaPssParams | EcdsaParams | ContextParams | KmacParams,
3861
- key: CryptoKey,
3862
- signature: NodeJS.BufferSource,
3863
- data: NodeJS.BufferSource,
3864
- ): Promise<boolean>;
3865
- wrapKey(
3866
- format: KeyFormat,
3867
- key: CryptoKey,
3868
- wrappingKey: CryptoKey,
3869
- wrapAlgorithm: AlgorithmIdentifier | RsaOaepParams | AesCtrParams | AesCbcParams | AeadParams,
3870
- ): Promise<ArrayBuffer>;
3871
- }
3872
- }
3873
- /**
3874
- * An object containing commonly used constants for crypto and security related
3875
- * operations. The specific constants currently defined are described in
3876
- * [Crypto constants](https://nodejs.org/docs/latest-v26.x/api/crypto.html#crypto-constants).
3877
- * @since v6.3.0
3878
- */
3879
- namespace constants {
3880
- const OPENSSL_VERSION_NUMBER: number;
3881
- const SSL_OP_ALL: number;
3882
- const SSL_OP_ALLOW_NO_DHE_KEX: number;
3883
- const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number;
3884
- const SSL_OP_CIPHER_SERVER_PREFERENCE: number;
3885
- const SSL_OP_CISCO_ANYCONNECT: number;
3886
- const SSL_OP_COOKIE_EXCHANGE: number;
3887
- const SSL_OP_CRYPTOPRO_TLSEXT_BUG: number;
3888
- const SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number;
3889
- const SSL_OP_LEGACY_SERVER_CONNECT: number;
3890
- const SSL_OP_NO_COMPRESSION: number;
3891
- const SSL_OP_NO_ENCRYPT_THEN_MAC: number;
3892
- const SSL_OP_NO_QUERY_MTU: number;
3893
- const SSL_OP_NO_RENEGOTIATION: number;
3894
- const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number;
3895
- const SSL_OP_NO_SSLv2: number;
3896
- const SSL_OP_NO_SSLv3: number;
3897
- const SSL_OP_NO_TICKET: number;
3898
- const SSL_OP_NO_TLSv1: number;
3899
- const SSL_OP_NO_TLSv1_1: number;
3900
- const SSL_OP_NO_TLSv1_2: number;
3901
- const SSL_OP_NO_TLSv1_3: number;
3902
- const SSL_OP_PRIORITIZE_CHACHA: number;
3903
- const SSL_OP_TLS_ROLLBACK_BUG: number;
3904
- const ENGINE_METHOD_RSA: number;
3905
- const ENGINE_METHOD_DSA: number;
3906
- const ENGINE_METHOD_DH: number;
3907
- const ENGINE_METHOD_RAND: number;
3908
- const ENGINE_METHOD_EC: number;
3909
- const ENGINE_METHOD_CIPHERS: number;
3910
- const ENGINE_METHOD_DIGESTS: number;
3911
- const ENGINE_METHOD_PKEY_METHS: number;
3912
- const ENGINE_METHOD_PKEY_ASN1_METHS: number;
3913
- const ENGINE_METHOD_ALL: number;
3914
- const ENGINE_METHOD_NONE: number;
3915
- const DH_CHECK_P_NOT_SAFE_PRIME: number;
3916
- const DH_CHECK_P_NOT_PRIME: number;
3917
- const DH_UNABLE_TO_CHECK_GENERATOR: number;
3918
- const DH_NOT_SUITABLE_GENERATOR: number;
3919
- const RSA_PKCS1_PADDING: number;
3920
- const RSA_NO_PADDING: number;
3921
- const RSA_PKCS1_OAEP_PADDING: number;
3922
- const RSA_X931_PADDING: number;
3923
- const RSA_PKCS1_PSS_PADDING: number;
3924
- const RSA_PSS_SALTLEN_DIGEST: number;
3925
- const RSA_PSS_SALTLEN_MAX_SIGN: number;
3926
- const RSA_PSS_SALTLEN_AUTO: number;
3927
- const TLS1_VERSION: number;
3928
- const TLS1_1_VERSION: number;
3929
- const TLS1_2_VERSION: number;
3930
- const TLS1_3_VERSION: number;
3931
- const POINT_CONVERSION_COMPRESSED: number;
3932
- const POINT_CONVERSION_UNCOMPRESSED: number;
3933
- const POINT_CONVERSION_HYBRID: number;
3934
- const defaultCipherList: string;
3935
- const defaultCoreCipherList: string;
3936
- }
3937
- // TODO: remove in future major version
3938
- /** @deprecated This type will be removed in a future version. Use `BufferEncoding` instead. */
3939
- type BinaryToTextEncoding = "base64" | "base64url" | "hex" | "binary";
3940
- /** @deprecated This type will be removed in a future version. Use `BufferEncoding` instead. */
3941
- type CharacterEncoding = "utf8" | "utf-8" | "utf16le" | "utf-16le" | "latin1";
3942
- /** @deprecated This type will be removed in a future version. Use `BufferEncoding` instead. */
3943
- type LegacyCharacterEncoding = "ascii" | "binary" | "ucs2" | "ucs-2";
3944
- /** @deprecated This type will be removed in a future version. Use `BufferEncoding` instead. */
3945
- type Encoding = BufferEncoding;
3946
- /** @deprecated This type will be removed in a future version. Use `KeyLike` instead. */
3947
- type CipherKey = KeyLike;
3948
- /** @deprecated This type will be removed in a future version. */
3949
- interface RsaPrivateKey {
3950
- key: KeyLike;
3951
- passphrase?: string | undefined;
3952
- oaepHash?: string | undefined;
3953
- oaepLabel?: NodeJS.TypedArray | undefined;
3954
- padding?: number | undefined;
3955
- }
3956
- /** @deprecated This type will be removed in a future version. */
3957
- interface RsaPublicKey {
3958
- key: KeyLike;
3959
- padding?: number | undefined;
3960
- }
3961
- }
3962
- declare module "crypto" {
3963
- export * from "node:crypto";
3964
- }