alicezetion 1.8.5 → 1.8.7

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