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