cloudstructs 0.1.38 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +19 -19
- package/.jsii +75 -31
- package/lib/codecommit-mirror/index.js +2 -2
- package/lib/ecs-service-roller/index.js +2 -2
- package/lib/email-receiver/receiver.js +1 -1
- package/lib/saml-identity-provider/index.js +2 -2
- package/lib/slack-events/index.js +1 -1
- package/lib/slack-textract/index.js +1 -1
- package/lib/state-machine-cr-provider/index.js +1 -1
- package/lib/static-website/index.js +1 -1
- package/lib/url-shortener/index.handler.js +2 -1
- package/lib/url-shortener/index.js +1 -1
- package/node_modules/@sindresorhus/is/dist/index.d.ts +9 -4
- package/node_modules/@sindresorhus/is/dist/index.js +9 -0
- package/node_modules/@sindresorhus/is/package.json +1 -1
- package/node_modules/@sindresorhus/is/readme.md +26 -0
- package/node_modules/@slack/logger/node_modules/@types/node/README.md +3 -3
- package/node_modules/@slack/logger/node_modules/@types/node/assert/strict.d.ts +0 -1
- package/node_modules/@slack/logger/node_modules/@types/node/assert.d.ts +823 -40
- package/node_modules/@slack/logger/node_modules/@types/node/async_hooks.d.ts +359 -90
- package/node_modules/@slack/logger/node_modules/@types/node/buffer.d.ts +1895 -113
- package/node_modules/@slack/logger/node_modules/@types/node/child_process.d.ts +1080 -247
- package/node_modules/@slack/logger/node_modules/@types/node/cluster.d.ts +327 -101
- package/node_modules/@slack/logger/node_modules/@types/node/console.d.ts +310 -32
- package/node_modules/@slack/logger/node_modules/@types/node/crypto.d.ts +2454 -742
- package/node_modules/@slack/logger/node_modules/@types/node/dgram.d.ts +463 -63
- package/node_modules/@slack/logger/node_modules/@types/node/diagnostics_channel.d.ts +109 -13
- package/node_modules/@slack/logger/node_modules/@types/node/dns/promises.d.ts +303 -36
- package/node_modules/@slack/logger/node_modules/@types/node/dns.d.ts +425 -97
- package/node_modules/@slack/logger/node_modules/@types/node/domain.d.ts +154 -10
- package/node_modules/@slack/logger/node_modules/@types/node/events.d.ts +559 -34
- package/node_modules/@slack/logger/node_modules/@types/node/fs/promises.d.ts +812 -269
- package/node_modules/@slack/logger/node_modules/@types/node/fs.d.ts +2408 -874
- package/node_modules/@slack/logger/node_modules/@types/node/globals.d.ts +24 -14
- package/node_modules/@slack/logger/node_modules/@types/node/http.d.ts +1031 -98
- package/node_modules/@slack/logger/node_modules/@types/node/http2.d.ts +1579 -459
- package/node_modules/@slack/logger/node_modules/@types/node/https.d.ts +363 -12
- package/node_modules/@slack/logger/node_modules/@types/node/index.d.ts +88 -15
- package/node_modules/@slack/logger/node_modules/@types/node/inspector.d.ts +360 -661
- package/node_modules/@slack/logger/node_modules/@types/node/module.d.ts +52 -11
- package/node_modules/@slack/logger/node_modules/@types/node/net.d.ts +557 -142
- package/node_modules/@slack/logger/node_modules/@types/node/os.d.ts +236 -26
- package/node_modules/@slack/logger/node_modules/@types/node/package.json +23 -25
- package/node_modules/@slack/logger/node_modules/@types/node/path.d.ts +9 -5
- package/node_modules/@slack/logger/node_modules/@types/node/perf_hooks.d.ts +289 -91
- package/node_modules/@slack/logger/node_modules/@types/node/process.d.ts +1173 -155
- package/node_modules/@slack/logger/node_modules/@types/node/punycode.d.ts +64 -26
- package/node_modules/@slack/logger/node_modules/@types/node/querystring.d.ts +107 -8
- package/node_modules/@slack/logger/node_modules/@types/node/readline.d.ts +426 -79
- package/node_modules/@slack/logger/node_modules/@types/node/repl.d.ts +135 -110
- package/node_modules/@slack/logger/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@slack/logger/node_modules/@types/node/stream/promises.d.ts +15 -44
- package/node_modules/@slack/logger/node_modules/@types/node/stream/web.d.ts +391 -0
- package/node_modules/@slack/logger/node_modules/@types/node/stream.d.ts +998 -225
- package/node_modules/@slack/logger/node_modules/@types/node/string_decoder.d.ts +57 -1
- package/node_modules/@slack/logger/node_modules/@types/node/timers/promises.d.ts +52 -9
- package/node_modules/@slack/logger/node_modules/@types/node/timers.d.ts +30 -11
- package/node_modules/@slack/logger/node_modules/@types/node/tls.d.ts +447 -225
- package/node_modules/@slack/logger/node_modules/@types/node/trace_events.d.ts +107 -11
- package/node_modules/@slack/logger/node_modules/@types/node/tty.d.ts +157 -23
- package/node_modules/@slack/logger/node_modules/@types/node/url.d.ts +724 -30
- package/node_modules/@slack/logger/node_modules/@types/node/util.d.ts +1399 -73
- package/node_modules/@slack/logger/node_modules/@types/node/v8.d.ts +254 -78
- package/node_modules/@slack/logger/node_modules/@types/node/vm.d.ts +384 -33
- package/node_modules/@slack/logger/node_modules/@types/node/wasi.d.ts +92 -24
- package/node_modules/@slack/logger/node_modules/@types/node/worker_threads.d.ts +494 -131
- package/node_modules/@slack/logger/node_modules/@types/node/zlib.d.ts +215 -63
- package/node_modules/@slack/web-api/node_modules/@types/node/README.md +3 -3
- package/node_modules/@slack/web-api/node_modules/@types/node/assert/strict.d.ts +0 -1
- package/node_modules/@slack/web-api/node_modules/@types/node/assert.d.ts +823 -40
- package/node_modules/@slack/web-api/node_modules/@types/node/async_hooks.d.ts +359 -90
- package/node_modules/@slack/web-api/node_modules/@types/node/buffer.d.ts +1895 -113
- package/node_modules/@slack/web-api/node_modules/@types/node/child_process.d.ts +1080 -247
- package/node_modules/@slack/web-api/node_modules/@types/node/cluster.d.ts +327 -101
- package/node_modules/@slack/web-api/node_modules/@types/node/console.d.ts +310 -32
- package/node_modules/@slack/web-api/node_modules/@types/node/crypto.d.ts +2454 -742
- package/node_modules/@slack/web-api/node_modules/@types/node/dgram.d.ts +463 -63
- package/node_modules/@slack/web-api/node_modules/@types/node/diagnostics_channel.d.ts +109 -13
- package/node_modules/@slack/web-api/node_modules/@types/node/dns/promises.d.ts +303 -36
- package/node_modules/@slack/web-api/node_modules/@types/node/dns.d.ts +425 -97
- package/node_modules/@slack/web-api/node_modules/@types/node/domain.d.ts +154 -10
- package/node_modules/@slack/web-api/node_modules/@types/node/events.d.ts +559 -34
- package/node_modules/@slack/web-api/node_modules/@types/node/fs/promises.d.ts +812 -269
- package/node_modules/@slack/web-api/node_modules/@types/node/fs.d.ts +2408 -874
- package/node_modules/@slack/web-api/node_modules/@types/node/globals.d.ts +24 -14
- package/node_modules/@slack/web-api/node_modules/@types/node/http.d.ts +1031 -98
- package/node_modules/@slack/web-api/node_modules/@types/node/http2.d.ts +1579 -459
- package/node_modules/@slack/web-api/node_modules/@types/node/https.d.ts +363 -12
- package/node_modules/@slack/web-api/node_modules/@types/node/index.d.ts +88 -15
- package/node_modules/@slack/web-api/node_modules/@types/node/inspector.d.ts +360 -661
- package/node_modules/@slack/web-api/node_modules/@types/node/module.d.ts +52 -11
- package/node_modules/@slack/web-api/node_modules/@types/node/net.d.ts +557 -142
- package/node_modules/@slack/web-api/node_modules/@types/node/os.d.ts +236 -26
- package/node_modules/@slack/web-api/node_modules/@types/node/package.json +23 -25
- package/node_modules/@slack/web-api/node_modules/@types/node/path.d.ts +9 -5
- package/node_modules/@slack/web-api/node_modules/@types/node/perf_hooks.d.ts +289 -91
- package/node_modules/@slack/web-api/node_modules/@types/node/process.d.ts +1173 -155
- package/node_modules/@slack/web-api/node_modules/@types/node/punycode.d.ts +64 -26
- package/node_modules/@slack/web-api/node_modules/@types/node/querystring.d.ts +107 -8
- package/node_modules/@slack/web-api/node_modules/@types/node/readline.d.ts +426 -79
- package/node_modules/@slack/web-api/node_modules/@types/node/repl.d.ts +135 -110
- package/node_modules/@slack/web-api/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@slack/web-api/node_modules/@types/node/stream/promises.d.ts +15 -44
- package/node_modules/@slack/web-api/node_modules/@types/node/stream/web.d.ts +391 -0
- package/node_modules/@slack/web-api/node_modules/@types/node/stream.d.ts +998 -225
- package/node_modules/@slack/web-api/node_modules/@types/node/string_decoder.d.ts +57 -1
- package/node_modules/@slack/web-api/node_modules/@types/node/timers/promises.d.ts +52 -9
- package/node_modules/@slack/web-api/node_modules/@types/node/timers.d.ts +30 -11
- package/node_modules/@slack/web-api/node_modules/@types/node/tls.d.ts +447 -225
- package/node_modules/@slack/web-api/node_modules/@types/node/trace_events.d.ts +107 -11
- package/node_modules/@slack/web-api/node_modules/@types/node/tty.d.ts +157 -23
- package/node_modules/@slack/web-api/node_modules/@types/node/url.d.ts +724 -30
- package/node_modules/@slack/web-api/node_modules/@types/node/util.d.ts +1399 -73
- package/node_modules/@slack/web-api/node_modules/@types/node/v8.d.ts +254 -78
- package/node_modules/@slack/web-api/node_modules/@types/node/vm.d.ts +384 -33
- package/node_modules/@slack/web-api/node_modules/@types/node/wasi.d.ts +92 -24
- package/node_modules/@slack/web-api/node_modules/@types/node/worker_threads.d.ts +494 -131
- package/node_modules/@slack/web-api/node_modules/@types/node/zlib.d.ts +215 -63
- package/node_modules/@types/cacheable-request/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/cacheable-request/node_modules/@types/node/assert/strict.d.ts +0 -1
- package/node_modules/@types/cacheable-request/node_modules/@types/node/assert.d.ts +823 -40
- package/node_modules/@types/cacheable-request/node_modules/@types/node/async_hooks.d.ts +359 -90
- package/node_modules/@types/cacheable-request/node_modules/@types/node/buffer.d.ts +1895 -113
- package/node_modules/@types/cacheable-request/node_modules/@types/node/child_process.d.ts +1080 -247
- package/node_modules/@types/cacheable-request/node_modules/@types/node/cluster.d.ts +327 -101
- package/node_modules/@types/cacheable-request/node_modules/@types/node/console.d.ts +310 -32
- package/node_modules/@types/cacheable-request/node_modules/@types/node/crypto.d.ts +2454 -742
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dgram.d.ts +463 -63
- package/node_modules/@types/cacheable-request/node_modules/@types/node/diagnostics_channel.d.ts +109 -13
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns/promises.d.ts +303 -36
- package/node_modules/@types/cacheable-request/node_modules/@types/node/dns.d.ts +425 -97
- package/node_modules/@types/cacheable-request/node_modules/@types/node/domain.d.ts +154 -10
- package/node_modules/@types/cacheable-request/node_modules/@types/node/events.d.ts +559 -34
- package/node_modules/@types/cacheable-request/node_modules/@types/node/fs/promises.d.ts +812 -269
- package/node_modules/@types/cacheable-request/node_modules/@types/node/fs.d.ts +2408 -874
- package/node_modules/@types/cacheable-request/node_modules/@types/node/globals.d.ts +24 -14
- package/node_modules/@types/cacheable-request/node_modules/@types/node/http.d.ts +1031 -98
- package/node_modules/@types/cacheable-request/node_modules/@types/node/http2.d.ts +1579 -459
- package/node_modules/@types/cacheable-request/node_modules/@types/node/https.d.ts +363 -12
- package/node_modules/@types/cacheable-request/node_modules/@types/node/index.d.ts +88 -15
- package/node_modules/@types/cacheable-request/node_modules/@types/node/inspector.d.ts +360 -661
- package/node_modules/@types/cacheable-request/node_modules/@types/node/module.d.ts +52 -11
- package/node_modules/@types/cacheable-request/node_modules/@types/node/net.d.ts +557 -142
- package/node_modules/@types/cacheable-request/node_modules/@types/node/os.d.ts +236 -26
- package/node_modules/@types/cacheable-request/node_modules/@types/node/package.json +23 -25
- package/node_modules/@types/cacheable-request/node_modules/@types/node/path.d.ts +9 -5
- package/node_modules/@types/cacheable-request/node_modules/@types/node/perf_hooks.d.ts +289 -91
- package/node_modules/@types/cacheable-request/node_modules/@types/node/process.d.ts +1173 -155
- package/node_modules/@types/cacheable-request/node_modules/@types/node/punycode.d.ts +64 -26
- package/node_modules/@types/cacheable-request/node_modules/@types/node/querystring.d.ts +107 -8
- package/node_modules/@types/cacheable-request/node_modules/@types/node/readline.d.ts +426 -79
- package/node_modules/@types/cacheable-request/node_modules/@types/node/repl.d.ts +135 -110
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/promises.d.ts +15 -44
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream/web.d.ts +391 -0
- package/node_modules/@types/cacheable-request/node_modules/@types/node/stream.d.ts +998 -225
- package/node_modules/@types/cacheable-request/node_modules/@types/node/string_decoder.d.ts +57 -1
- package/node_modules/@types/cacheable-request/node_modules/@types/node/timers/promises.d.ts +52 -9
- package/node_modules/@types/cacheable-request/node_modules/@types/node/timers.d.ts +30 -11
- package/node_modules/@types/cacheable-request/node_modules/@types/node/tls.d.ts +447 -225
- package/node_modules/@types/cacheable-request/node_modules/@types/node/trace_events.d.ts +107 -11
- package/node_modules/@types/cacheable-request/node_modules/@types/node/tty.d.ts +157 -23
- package/node_modules/@types/cacheable-request/node_modules/@types/node/url.d.ts +724 -30
- package/node_modules/@types/cacheable-request/node_modules/@types/node/util.d.ts +1399 -73
- package/node_modules/@types/cacheable-request/node_modules/@types/node/v8.d.ts +254 -78
- package/node_modules/@types/cacheable-request/node_modules/@types/node/vm.d.ts +384 -33
- package/node_modules/@types/cacheable-request/node_modules/@types/node/wasi.d.ts +92 -24
- package/node_modules/@types/cacheable-request/node_modules/@types/node/worker_threads.d.ts +494 -131
- package/node_modules/@types/cacheable-request/node_modules/@types/node/zlib.d.ts +215 -63
- package/node_modules/@types/is-stream/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/is-stream/node_modules/@types/node/assert/strict.d.ts +0 -1
- package/node_modules/@types/is-stream/node_modules/@types/node/assert.d.ts +823 -40
- package/node_modules/@types/is-stream/node_modules/@types/node/async_hooks.d.ts +359 -90
- package/node_modules/@types/is-stream/node_modules/@types/node/buffer.d.ts +1895 -113
- package/node_modules/@types/is-stream/node_modules/@types/node/child_process.d.ts +1080 -247
- package/node_modules/@types/is-stream/node_modules/@types/node/cluster.d.ts +327 -101
- package/node_modules/@types/is-stream/node_modules/@types/node/console.d.ts +310 -32
- package/node_modules/@types/is-stream/node_modules/@types/node/crypto.d.ts +2454 -742
- package/node_modules/@types/is-stream/node_modules/@types/node/dgram.d.ts +463 -63
- package/node_modules/@types/is-stream/node_modules/@types/node/diagnostics_channel.d.ts +109 -13
- package/node_modules/@types/is-stream/node_modules/@types/node/dns/promises.d.ts +303 -36
- package/node_modules/@types/is-stream/node_modules/@types/node/dns.d.ts +425 -97
- package/node_modules/@types/is-stream/node_modules/@types/node/domain.d.ts +154 -10
- package/node_modules/@types/is-stream/node_modules/@types/node/events.d.ts +559 -34
- package/node_modules/@types/is-stream/node_modules/@types/node/fs/promises.d.ts +812 -269
- package/node_modules/@types/is-stream/node_modules/@types/node/fs.d.ts +2408 -874
- package/node_modules/@types/is-stream/node_modules/@types/node/globals.d.ts +24 -14
- package/node_modules/@types/is-stream/node_modules/@types/node/http.d.ts +1031 -98
- package/node_modules/@types/is-stream/node_modules/@types/node/http2.d.ts +1579 -459
- package/node_modules/@types/is-stream/node_modules/@types/node/https.d.ts +363 -12
- package/node_modules/@types/is-stream/node_modules/@types/node/index.d.ts +88 -15
- package/node_modules/@types/is-stream/node_modules/@types/node/inspector.d.ts +360 -661
- package/node_modules/@types/is-stream/node_modules/@types/node/module.d.ts +52 -11
- package/node_modules/@types/is-stream/node_modules/@types/node/net.d.ts +557 -142
- package/node_modules/@types/is-stream/node_modules/@types/node/os.d.ts +236 -26
- package/node_modules/@types/is-stream/node_modules/@types/node/package.json +23 -25
- package/node_modules/@types/is-stream/node_modules/@types/node/path.d.ts +9 -5
- package/node_modules/@types/is-stream/node_modules/@types/node/perf_hooks.d.ts +289 -91
- package/node_modules/@types/is-stream/node_modules/@types/node/process.d.ts +1173 -155
- package/node_modules/@types/is-stream/node_modules/@types/node/punycode.d.ts +64 -26
- package/node_modules/@types/is-stream/node_modules/@types/node/querystring.d.ts +107 -8
- package/node_modules/@types/is-stream/node_modules/@types/node/readline.d.ts +426 -79
- package/node_modules/@types/is-stream/node_modules/@types/node/repl.d.ts +135 -110
- package/node_modules/@types/is-stream/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/is-stream/node_modules/@types/node/stream/promises.d.ts +15 -44
- package/node_modules/@types/is-stream/node_modules/@types/node/stream/web.d.ts +391 -0
- package/node_modules/@types/is-stream/node_modules/@types/node/stream.d.ts +998 -225
- package/node_modules/@types/is-stream/node_modules/@types/node/string_decoder.d.ts +57 -1
- package/node_modules/@types/is-stream/node_modules/@types/node/timers/promises.d.ts +52 -9
- package/node_modules/@types/is-stream/node_modules/@types/node/timers.d.ts +30 -11
- package/node_modules/@types/is-stream/node_modules/@types/node/tls.d.ts +447 -225
- package/node_modules/@types/is-stream/node_modules/@types/node/trace_events.d.ts +107 -11
- package/node_modules/@types/is-stream/node_modules/@types/node/tty.d.ts +157 -23
- package/node_modules/@types/is-stream/node_modules/@types/node/url.d.ts +724 -30
- package/node_modules/@types/is-stream/node_modules/@types/node/util.d.ts +1399 -73
- package/node_modules/@types/is-stream/node_modules/@types/node/v8.d.ts +254 -78
- package/node_modules/@types/is-stream/node_modules/@types/node/vm.d.ts +384 -33
- package/node_modules/@types/is-stream/node_modules/@types/node/wasi.d.ts +92 -24
- package/node_modules/@types/is-stream/node_modules/@types/node/worker_threads.d.ts +494 -131
- package/node_modules/@types/is-stream/node_modules/@types/node/zlib.d.ts +215 -63
- package/node_modules/@types/keyv/README.md +1 -1
- package/node_modules/@types/keyv/index.d.ts +10 -3
- package/node_modules/@types/keyv/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/keyv/node_modules/@types/node/assert/strict.d.ts +0 -1
- package/node_modules/@types/keyv/node_modules/@types/node/assert.d.ts +823 -40
- package/node_modules/@types/keyv/node_modules/@types/node/async_hooks.d.ts +359 -90
- package/node_modules/@types/keyv/node_modules/@types/node/buffer.d.ts +1895 -113
- package/node_modules/@types/keyv/node_modules/@types/node/child_process.d.ts +1080 -247
- package/node_modules/@types/keyv/node_modules/@types/node/cluster.d.ts +327 -101
- package/node_modules/@types/keyv/node_modules/@types/node/console.d.ts +310 -32
- package/node_modules/@types/keyv/node_modules/@types/node/crypto.d.ts +2454 -742
- package/node_modules/@types/keyv/node_modules/@types/node/dgram.d.ts +463 -63
- package/node_modules/@types/keyv/node_modules/@types/node/diagnostics_channel.d.ts +109 -13
- package/node_modules/@types/keyv/node_modules/@types/node/dns/promises.d.ts +303 -36
- package/node_modules/@types/keyv/node_modules/@types/node/dns.d.ts +425 -97
- package/node_modules/@types/keyv/node_modules/@types/node/domain.d.ts +154 -10
- package/node_modules/@types/keyv/node_modules/@types/node/events.d.ts +559 -34
- package/node_modules/@types/keyv/node_modules/@types/node/fs/promises.d.ts +812 -269
- package/node_modules/@types/keyv/node_modules/@types/node/fs.d.ts +2408 -874
- package/node_modules/@types/keyv/node_modules/@types/node/globals.d.ts +24 -14
- package/node_modules/@types/keyv/node_modules/@types/node/http.d.ts +1031 -98
- package/node_modules/@types/keyv/node_modules/@types/node/http2.d.ts +1579 -459
- package/node_modules/@types/keyv/node_modules/@types/node/https.d.ts +363 -12
- package/node_modules/@types/keyv/node_modules/@types/node/index.d.ts +88 -15
- package/node_modules/@types/keyv/node_modules/@types/node/inspector.d.ts +360 -661
- package/node_modules/@types/keyv/node_modules/@types/node/module.d.ts +52 -11
- package/node_modules/@types/keyv/node_modules/@types/node/net.d.ts +557 -142
- package/node_modules/@types/keyv/node_modules/@types/node/os.d.ts +236 -26
- package/node_modules/@types/keyv/node_modules/@types/node/package.json +23 -25
- package/node_modules/@types/keyv/node_modules/@types/node/path.d.ts +9 -5
- package/node_modules/@types/keyv/node_modules/@types/node/perf_hooks.d.ts +289 -91
- package/node_modules/@types/keyv/node_modules/@types/node/process.d.ts +1173 -155
- package/node_modules/@types/keyv/node_modules/@types/node/punycode.d.ts +64 -26
- package/node_modules/@types/keyv/node_modules/@types/node/querystring.d.ts +107 -8
- package/node_modules/@types/keyv/node_modules/@types/node/readline.d.ts +426 -79
- package/node_modules/@types/keyv/node_modules/@types/node/repl.d.ts +135 -110
- package/node_modules/@types/keyv/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/keyv/node_modules/@types/node/stream/promises.d.ts +15 -44
- package/node_modules/@types/keyv/node_modules/@types/node/stream/web.d.ts +391 -0
- package/node_modules/@types/keyv/node_modules/@types/node/stream.d.ts +998 -225
- package/node_modules/@types/keyv/node_modules/@types/node/string_decoder.d.ts +57 -1
- package/node_modules/@types/keyv/node_modules/@types/node/timers/promises.d.ts +52 -9
- package/node_modules/@types/keyv/node_modules/@types/node/timers.d.ts +30 -11
- package/node_modules/@types/keyv/node_modules/@types/node/tls.d.ts +447 -225
- package/node_modules/@types/keyv/node_modules/@types/node/trace_events.d.ts +107 -11
- package/node_modules/@types/keyv/node_modules/@types/node/tty.d.ts +157 -23
- package/node_modules/@types/keyv/node_modules/@types/node/url.d.ts +724 -30
- package/node_modules/@types/keyv/node_modules/@types/node/util.d.ts +1399 -73
- package/node_modules/@types/keyv/node_modules/@types/node/v8.d.ts +254 -78
- package/node_modules/@types/keyv/node_modules/@types/node/vm.d.ts +384 -33
- package/node_modules/@types/keyv/node_modules/@types/node/wasi.d.ts +92 -24
- package/node_modules/@types/keyv/node_modules/@types/node/worker_threads.d.ts +494 -131
- package/node_modules/@types/keyv/node_modules/@types/node/zlib.d.ts +215 -63
- package/node_modules/@types/keyv/package.json +3 -3
- package/node_modules/@types/responselike/node_modules/@types/node/README.md +3 -3
- package/node_modules/@types/responselike/node_modules/@types/node/assert/strict.d.ts +0 -1
- package/node_modules/@types/responselike/node_modules/@types/node/assert.d.ts +823 -40
- package/node_modules/@types/responselike/node_modules/@types/node/async_hooks.d.ts +359 -90
- package/node_modules/@types/responselike/node_modules/@types/node/buffer.d.ts +1895 -113
- package/node_modules/@types/responselike/node_modules/@types/node/child_process.d.ts +1080 -247
- package/node_modules/@types/responselike/node_modules/@types/node/cluster.d.ts +327 -101
- package/node_modules/@types/responselike/node_modules/@types/node/console.d.ts +310 -32
- package/node_modules/@types/responselike/node_modules/@types/node/crypto.d.ts +2454 -742
- package/node_modules/@types/responselike/node_modules/@types/node/dgram.d.ts +463 -63
- package/node_modules/@types/responselike/node_modules/@types/node/diagnostics_channel.d.ts +109 -13
- package/node_modules/@types/responselike/node_modules/@types/node/dns/promises.d.ts +303 -36
- package/node_modules/@types/responselike/node_modules/@types/node/dns.d.ts +425 -97
- package/node_modules/@types/responselike/node_modules/@types/node/domain.d.ts +154 -10
- package/node_modules/@types/responselike/node_modules/@types/node/events.d.ts +559 -34
- package/node_modules/@types/responselike/node_modules/@types/node/fs/promises.d.ts +812 -269
- package/node_modules/@types/responselike/node_modules/@types/node/fs.d.ts +2408 -874
- package/node_modules/@types/responselike/node_modules/@types/node/globals.d.ts +24 -14
- package/node_modules/@types/responselike/node_modules/@types/node/http.d.ts +1031 -98
- package/node_modules/@types/responselike/node_modules/@types/node/http2.d.ts +1579 -459
- package/node_modules/@types/responselike/node_modules/@types/node/https.d.ts +363 -12
- package/node_modules/@types/responselike/node_modules/@types/node/index.d.ts +88 -15
- package/node_modules/@types/responselike/node_modules/@types/node/inspector.d.ts +360 -661
- package/node_modules/@types/responselike/node_modules/@types/node/module.d.ts +52 -11
- package/node_modules/@types/responselike/node_modules/@types/node/net.d.ts +557 -142
- package/node_modules/@types/responselike/node_modules/@types/node/os.d.ts +236 -26
- package/node_modules/@types/responselike/node_modules/@types/node/package.json +23 -25
- package/node_modules/@types/responselike/node_modules/@types/node/path.d.ts +9 -5
- package/node_modules/@types/responselike/node_modules/@types/node/perf_hooks.d.ts +289 -91
- package/node_modules/@types/responselike/node_modules/@types/node/process.d.ts +1173 -155
- package/node_modules/@types/responselike/node_modules/@types/node/punycode.d.ts +64 -26
- package/node_modules/@types/responselike/node_modules/@types/node/querystring.d.ts +107 -8
- package/node_modules/@types/responselike/node_modules/@types/node/readline.d.ts +426 -79
- package/node_modules/@types/responselike/node_modules/@types/node/repl.d.ts +135 -110
- package/node_modules/@types/responselike/node_modules/@types/node/stream/consumers.d.ts +24 -0
- package/node_modules/@types/responselike/node_modules/@types/node/stream/promises.d.ts +15 -44
- package/node_modules/@types/responselike/node_modules/@types/node/stream/web.d.ts +391 -0
- package/node_modules/@types/responselike/node_modules/@types/node/stream.d.ts +998 -225
- package/node_modules/@types/responselike/node_modules/@types/node/string_decoder.d.ts +57 -1
- package/node_modules/@types/responselike/node_modules/@types/node/timers/promises.d.ts +52 -9
- package/node_modules/@types/responselike/node_modules/@types/node/timers.d.ts +30 -11
- package/node_modules/@types/responselike/node_modules/@types/node/tls.d.ts +447 -225
- package/node_modules/@types/responselike/node_modules/@types/node/trace_events.d.ts +107 -11
- package/node_modules/@types/responselike/node_modules/@types/node/tty.d.ts +157 -23
- package/node_modules/@types/responselike/node_modules/@types/node/url.d.ts +724 -30
- package/node_modules/@types/responselike/node_modules/@types/node/util.d.ts +1399 -73
- package/node_modules/@types/responselike/node_modules/@types/node/v8.d.ts +254 -78
- package/node_modules/@types/responselike/node_modules/@types/node/vm.d.ts +384 -33
- package/node_modules/@types/responselike/node_modules/@types/node/wasi.d.ts +92 -24
- package/node_modules/@types/responselike/node_modules/@types/node/worker_threads.d.ts +494 -131
- package/node_modules/@types/responselike/node_modules/@types/node/zlib.d.ts +215 -63
- package/node_modules/axios/CHANGELOG.md +98 -8
- package/node_modules/axios/README.md +74 -6
- package/node_modules/axios/SECURITY.md +5 -0
- package/node_modules/axios/dist/axios.js +2028 -1591
- package/node_modules/axios/dist/axios.map +1 -1
- package/node_modules/axios/dist/axios.min.js +2 -2
- package/node_modules/axios/dist/axios.min.map +1 -1
- package/node_modules/axios/index.d.ts +8 -1
- package/node_modules/axios/lib/adapters/http.js +33 -5
- package/node_modules/axios/lib/adapters/xhr.js +35 -25
- package/node_modules/axios/lib/core/Axios.js +60 -7
- package/node_modules/axios/lib/core/InterceptorManager.js +4 -2
- package/node_modules/axios/lib/core/README.md +1 -0
- package/node_modules/axios/lib/core/dispatchRequest.js +6 -3
- package/node_modules/axios/lib/core/transformData.js +3 -1
- package/node_modules/axios/lib/defaults.js +43 -7
- package/node_modules/axios/lib/helpers/validator.js +105 -0
- package/node_modules/axios/lib/utils.js +1 -3
- package/node_modules/axios/package.json +19 -21
- package/node_modules/follow-redirects/debug.js +2 -1
- package/node_modules/follow-redirects/index.js +59 -21
- package/node_modules/follow-redirects/package.json +1 -1
- package/node_modules/got/dist/source/as-promise/parse-body.d.ts +1 -1
- package/node_modules/got/dist/source/as-promise/types.js +2 -0
- package/node_modules/got/dist/source/core/index.d.ts +1 -1
- package/node_modules/got/dist/source/core/index.js +9 -3
- package/node_modules/got/dist/source/types.d.ts +14 -12
- package/node_modules/got/package.json +2 -2
- package/node_modules/got/readme.md +11 -10
- package/node_modules/keyv/LICENSE +1 -1
- package/node_modules/keyv/README.md +12 -10
- package/node_modules/keyv/package.json +17 -12
- package/node_modules/keyv/src/index.js +14 -16
- package/node_modules/mime-db/HISTORY.md +19 -0
- package/node_modules/mime-db/db.json +93 -1
- package/node_modules/mime-db/package.json +7 -7
- package/node_modules/mime-types/HISTORY.md +20 -3
- package/node_modules/mime-types/package.json +7 -7
- package/node_modules/{http2-wrapper/node_modules/quick-lru → quick-lru}/index.d.ts +0 -0
- package/node_modules/{http2-wrapper/node_modules/quick-lru → quick-lru}/index.js +0 -0
- package/node_modules/{http2-wrapper/node_modules/quick-lru → quick-lru}/license +0 -0
- package/node_modules/{http2-wrapper/node_modules/quick-lru → quick-lru}/package.json +0 -0
- package/node_modules/{http2-wrapper/node_modules/quick-lru → quick-lru}/readme.md +0 -0
- package/node_modules/resolve-alpn/README.md +8 -1
- package/node_modules/resolve-alpn/index.js +14 -4
- package/node_modules/resolve-alpn/package.json +1 -1
- package/package.json +33 -34
- package/node_modules/@slack/logger/node_modules/@types/node/base.d.ts +0 -19
- package/node_modules/@slack/logger/node_modules/@types/node/ts3.6/assert.d.ts +0 -103
- package/node_modules/@slack/logger/node_modules/@types/node/ts3.6/base.d.ts +0 -67
- package/node_modules/@slack/logger/node_modules/@types/node/ts3.6/index.d.ts +0 -7
- package/node_modules/@slack/web-api/node_modules/@types/node/base.d.ts +0 -19
- package/node_modules/@slack/web-api/node_modules/@types/node/ts3.6/assert.d.ts +0 -103
- package/node_modules/@slack/web-api/node_modules/@types/node/ts3.6/base.d.ts +0 -67
- package/node_modules/@slack/web-api/node_modules/@types/node/ts3.6/index.d.ts +0 -7
- package/node_modules/@types/cacheable-request/node_modules/@types/node/base.d.ts +0 -19
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts3.6/assert.d.ts +0 -103
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts3.6/base.d.ts +0 -67
- package/node_modules/@types/cacheable-request/node_modules/@types/node/ts3.6/index.d.ts +0 -7
- package/node_modules/@types/is-stream/node_modules/@types/node/base.d.ts +0 -19
- package/node_modules/@types/is-stream/node_modules/@types/node/ts3.6/assert.d.ts +0 -103
- package/node_modules/@types/is-stream/node_modules/@types/node/ts3.6/base.d.ts +0 -67
- package/node_modules/@types/is-stream/node_modules/@types/node/ts3.6/index.d.ts +0 -7
- package/node_modules/@types/keyv/node_modules/@types/node/base.d.ts +0 -19
- package/node_modules/@types/keyv/node_modules/@types/node/ts3.6/assert.d.ts +0 -103
- package/node_modules/@types/keyv/node_modules/@types/node/ts3.6/base.d.ts +0 -67
- package/node_modules/@types/keyv/node_modules/@types/node/ts3.6/index.d.ts +0 -7
- package/node_modules/@types/responselike/node_modules/@types/node/base.d.ts +0 -19
- package/node_modules/@types/responselike/node_modules/@types/node/ts3.6/assert.d.ts +0 -103
- package/node_modules/@types/responselike/node_modules/@types/node/ts3.6/base.d.ts +0 -67
- package/node_modules/@types/responselike/node_modules/@types/node/ts3.6/index.d.ts +0 -7
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `crypto` module provides cryptographic functionality that includes a set of
|
|
3
|
+
* wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
|
|
4
|
+
*
|
|
5
|
+
* ```js
|
|
6
|
+
* const { createHmac } = await import('crypto');
|
|
7
|
+
*
|
|
8
|
+
* const secret = 'abcdefg';
|
|
9
|
+
* const hash = createHmac('sha256', secret)
|
|
10
|
+
* .update('I love cupcakes')
|
|
11
|
+
* .digest('hex');
|
|
12
|
+
* console.log(hash);
|
|
13
|
+
* // Prints:
|
|
14
|
+
* // c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e
|
|
15
|
+
* ```
|
|
16
|
+
* @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/crypto.js)
|
|
17
|
+
*/
|
|
1
18
|
declare module 'crypto' {
|
|
2
19
|
import * as stream from 'node:stream';
|
|
3
20
|
import { PeerCertificate } from 'node:tls';
|
|
4
|
-
|
|
5
21
|
interface Certificate {
|
|
6
22
|
/**
|
|
7
23
|
* @deprecated
|
|
@@ -28,10 +44,9 @@ declare module 'crypto' {
|
|
|
28
44
|
}
|
|
29
45
|
const Certificate: Certificate & {
|
|
30
46
|
/** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
|
|
31
|
-
new(): Certificate;
|
|
47
|
+
new (): Certificate;
|
|
32
48
|
/** @deprecated since v14.9.0 - Use static methods of `crypto.Certificate` instead. */
|
|
33
49
|
(): Certificate;
|
|
34
|
-
|
|
35
50
|
/**
|
|
36
51
|
* @param spkac
|
|
37
52
|
* @returns The challenge component of the `spkac` data structure,
|
|
@@ -52,11 +67,9 @@ declare module 'crypto' {
|
|
|
52
67
|
*/
|
|
53
68
|
verifySpkac(spkac: NodeJS.ArrayBufferView): boolean;
|
|
54
69
|
};
|
|
55
|
-
|
|
56
70
|
namespace constants {
|
|
57
71
|
// https://nodejs.org/dist/latest-v10.x/docs/api/crypto.html#crypto_crypto_constants
|
|
58
72
|
const OPENSSL_VERSION_NUMBER: number;
|
|
59
|
-
|
|
60
73
|
/** Applies multiple bug workarounds within OpenSSL. See https://www.openssl.org/docs/man1.0.2/ssl/SSL_CTX_set_options.html for detail. */
|
|
61
74
|
const SSL_OP_ALL: number;
|
|
62
75
|
/** 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,7 +119,6 @@ declare module 'crypto' {
|
|
|
106
119
|
const SSL_OP_TLS_D5_BUG: number;
|
|
107
120
|
/** Instructs OpenSSL to disable version rollback attack detection. */
|
|
108
121
|
const SSL_OP_TLS_ROLLBACK_BUG: number;
|
|
109
|
-
|
|
110
122
|
const ENGINE_METHOD_RSA: number;
|
|
111
123
|
const ENGINE_METHOD_DSA: number;
|
|
112
124
|
const ENGINE_METHOD_DH: number;
|
|
@@ -118,14 +130,11 @@ declare module 'crypto' {
|
|
|
118
130
|
const ENGINE_METHOD_PKEY_ASN1_METHS: number;
|
|
119
131
|
const ENGINE_METHOD_ALL: number;
|
|
120
132
|
const ENGINE_METHOD_NONE: number;
|
|
121
|
-
|
|
122
133
|
const DH_CHECK_P_NOT_SAFE_PRIME: number;
|
|
123
134
|
const DH_CHECK_P_NOT_PRIME: number;
|
|
124
135
|
const DH_UNABLE_TO_CHECK_GENERATOR: number;
|
|
125
136
|
const DH_NOT_SUITABLE_GENERATOR: number;
|
|
126
|
-
|
|
127
137
|
const ALPN_ENABLED: number;
|
|
128
|
-
|
|
129
138
|
const RSA_PKCS1_PADDING: number;
|
|
130
139
|
const RSA_SSLV23_PADDING: number;
|
|
131
140
|
const RSA_NO_PADDING: number;
|
|
@@ -138,17 +147,14 @@ declare module 'crypto' {
|
|
|
138
147
|
const RSA_PSS_SALTLEN_MAX_SIGN: number;
|
|
139
148
|
/** Causes the salt length for RSA_PKCS1_PSS_PADDING to be determined automatically when verifying a signature. */
|
|
140
149
|
const RSA_PSS_SALTLEN_AUTO: number;
|
|
141
|
-
|
|
142
150
|
const POINT_CONVERSION_COMPRESSED: number;
|
|
143
151
|
const POINT_CONVERSION_UNCOMPRESSED: number;
|
|
144
152
|
const POINT_CONVERSION_HYBRID: number;
|
|
145
|
-
|
|
146
153
|
/** Specifies the built-in default cipher list used by Node.js (colon-separated values). */
|
|
147
154
|
const defaultCoreCipherList: string;
|
|
148
155
|
/** Specifies the active default cipher list used by the current Node.js process (colon-separated values). */
|
|
149
156
|
const defaultCipherList: string;
|
|
150
157
|
}
|
|
151
|
-
|
|
152
158
|
interface HashOptions extends stream.TransformOptions {
|
|
153
159
|
/**
|
|
154
160
|
* For XOF hash functions such as `shake256`, the
|
|
@@ -156,40 +162,318 @@ declare module 'crypto' {
|
|
|
156
162
|
*/
|
|
157
163
|
outputLength?: number | undefined;
|
|
158
164
|
}
|
|
159
|
-
|
|
160
165
|
/** @deprecated since v10.0.0 */
|
|
161
166
|
const fips: boolean;
|
|
162
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Creates and returns a `Hash` object that can be used to generate hash digests
|
|
169
|
+
* using the given `algorithm`. Optional `options` argument controls stream
|
|
170
|
+
* behavior. For XOF hash functions such as `'shake256'`, the `outputLength` option
|
|
171
|
+
* can be used to specify the desired output length in bytes.
|
|
172
|
+
*
|
|
173
|
+
* The `algorithm` is dependent on the available algorithms supported by the
|
|
174
|
+
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
|
|
175
|
+
* On recent releases of OpenSSL, `openssl list -digest-algorithms`(`openssl list-message-digest-algorithms` for older versions of OpenSSL) will
|
|
176
|
+
* display the available digest algorithms.
|
|
177
|
+
*
|
|
178
|
+
* Example: generating the sha256 sum of a file
|
|
179
|
+
*
|
|
180
|
+
* ```js
|
|
181
|
+
* import {
|
|
182
|
+
* createReadStream
|
|
183
|
+
* } from 'fs';
|
|
184
|
+
* import { argv } from 'process';
|
|
185
|
+
* const {
|
|
186
|
+
* createHash
|
|
187
|
+
* } = await import('crypto');
|
|
188
|
+
*
|
|
189
|
+
* const filename = argv[2];
|
|
190
|
+
*
|
|
191
|
+
* const hash = createHash('sha256');
|
|
192
|
+
*
|
|
193
|
+
* const input = createReadStream(filename);
|
|
194
|
+
* input.on('readable', () => {
|
|
195
|
+
* // Only one element is going to be produced by the
|
|
196
|
+
* // hash stream.
|
|
197
|
+
* const data = input.read();
|
|
198
|
+
* if (data)
|
|
199
|
+
* hash.update(data);
|
|
200
|
+
* else {
|
|
201
|
+
* console.log(`${hash.digest('hex')} ${filename}`);
|
|
202
|
+
* }
|
|
203
|
+
* });
|
|
204
|
+
* ```
|
|
205
|
+
* @since v0.1.92
|
|
206
|
+
* @param options `stream.transform` options
|
|
207
|
+
*/
|
|
163
208
|
function createHash(algorithm: string, options?: HashOptions): Hash;
|
|
209
|
+
/**
|
|
210
|
+
* Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
|
|
211
|
+
* Optional `options` argument controls stream behavior.
|
|
212
|
+
*
|
|
213
|
+
* The `algorithm` is dependent on the available algorithms supported by the
|
|
214
|
+
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
|
|
215
|
+
* On recent releases of OpenSSL, `openssl list -digest-algorithms`(`openssl list-message-digest-algorithms` for older versions of OpenSSL) will
|
|
216
|
+
* display the available digest algorithms.
|
|
217
|
+
*
|
|
218
|
+
* The `key` is the HMAC key used to generate the cryptographic HMAC hash. If it is
|
|
219
|
+
* a `KeyObject`, its type must be `secret`.
|
|
220
|
+
*
|
|
221
|
+
* Example: generating the sha256 HMAC of a file
|
|
222
|
+
*
|
|
223
|
+
* ```js
|
|
224
|
+
* import {
|
|
225
|
+
* createReadStream
|
|
226
|
+
* } from 'fs';
|
|
227
|
+
* import { argv } from 'process';
|
|
228
|
+
* const {
|
|
229
|
+
* createHmac
|
|
230
|
+
* } = await import('crypto');
|
|
231
|
+
*
|
|
232
|
+
* const filename = argv[2];
|
|
233
|
+
*
|
|
234
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
235
|
+
*
|
|
236
|
+
* const input = createReadStream(filename);
|
|
237
|
+
* input.on('readable', () => {
|
|
238
|
+
* // Only one element is going to be produced by the
|
|
239
|
+
* // hash stream.
|
|
240
|
+
* const data = input.read();
|
|
241
|
+
* if (data)
|
|
242
|
+
* hmac.update(data);
|
|
243
|
+
* else {
|
|
244
|
+
* console.log(`${hmac.digest('hex')} ${filename}`);
|
|
245
|
+
* }
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
* @since v0.1.94
|
|
249
|
+
* @param options `stream.transform` options
|
|
250
|
+
*/
|
|
164
251
|
function createHmac(algorithm: string, key: BinaryLike | KeyObject, options?: stream.TransformOptions): Hmac;
|
|
165
|
-
|
|
166
252
|
// https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
|
|
167
|
-
type BinaryToTextEncoding = 'base64' | 'hex';
|
|
253
|
+
type BinaryToTextEncoding = 'base64' | 'base64url' | 'hex';
|
|
168
254
|
type CharacterEncoding = 'utf8' | 'utf-8' | 'utf16le' | 'latin1';
|
|
169
255
|
type LegacyCharacterEncoding = 'ascii' | 'binary' | 'ucs2' | 'ucs-2';
|
|
170
|
-
|
|
171
256
|
type Encoding = BinaryToTextEncoding | CharacterEncoding | LegacyCharacterEncoding;
|
|
172
|
-
|
|
173
257
|
type ECDHKeyFormat = 'compressed' | 'uncompressed' | 'hybrid';
|
|
174
|
-
|
|
258
|
+
/**
|
|
259
|
+
* The `Hash` class is a utility for creating hash digests of data. It can be
|
|
260
|
+
* used in one of two ways:
|
|
261
|
+
*
|
|
262
|
+
* * As a `stream` that is both readable and writable, where data is written
|
|
263
|
+
* to produce a computed hash digest on the readable side, or
|
|
264
|
+
* * Using the `hash.update()` and `hash.digest()` methods to produce the
|
|
265
|
+
* computed hash.
|
|
266
|
+
*
|
|
267
|
+
* The {@link createHash} method is used to create `Hash` instances. `Hash`objects are not to be created directly using the `new` keyword.
|
|
268
|
+
*
|
|
269
|
+
* Example: Using `Hash` objects as streams:
|
|
270
|
+
*
|
|
271
|
+
* ```js
|
|
272
|
+
* const {
|
|
273
|
+
* createHash
|
|
274
|
+
* } = await import('crypto');
|
|
275
|
+
*
|
|
276
|
+
* const hash = createHash('sha256');
|
|
277
|
+
*
|
|
278
|
+
* hash.on('readable', () => {
|
|
279
|
+
* // Only one element is going to be produced by the
|
|
280
|
+
* // hash stream.
|
|
281
|
+
* const data = hash.read();
|
|
282
|
+
* if (data) {
|
|
283
|
+
* console.log(data.toString('hex'));
|
|
284
|
+
* // Prints:
|
|
285
|
+
* // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
|
|
286
|
+
* }
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* hash.write('some data to hash');
|
|
290
|
+
* hash.end();
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* Example: Using `Hash` and piped streams:
|
|
294
|
+
*
|
|
295
|
+
* ```js
|
|
296
|
+
* import { createReadStream } from 'fs';
|
|
297
|
+
* import { stdout } from 'process';
|
|
298
|
+
* const { createHash } = await import('crypto');
|
|
299
|
+
*
|
|
300
|
+
* const hash = createHash('sha256');
|
|
301
|
+
*
|
|
302
|
+
* const input = createReadStream('test.js');
|
|
303
|
+
* input.pipe(hash).setEncoding('hex').pipe(stdout);
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* Example: Using the `hash.update()` and `hash.digest()` methods:
|
|
307
|
+
*
|
|
308
|
+
* ```js
|
|
309
|
+
* const {
|
|
310
|
+
* createHash
|
|
311
|
+
* } = await import('crypto');
|
|
312
|
+
*
|
|
313
|
+
* const hash = createHash('sha256');
|
|
314
|
+
*
|
|
315
|
+
* hash.update('some data to hash');
|
|
316
|
+
* console.log(hash.digest('hex'));
|
|
317
|
+
* // Prints:
|
|
318
|
+
* // 6a2da20943931e9834fc12cfe5bb47bbd9ae43489a30726962b576f4e3993e50
|
|
319
|
+
* ```
|
|
320
|
+
* @since v0.1.92
|
|
321
|
+
*/
|
|
175
322
|
class Hash extends stream.Transform {
|
|
176
323
|
private constructor();
|
|
177
|
-
|
|
324
|
+
/**
|
|
325
|
+
* Creates a new `Hash` object that contains a deep copy of the internal state
|
|
326
|
+
* of the current `Hash` object.
|
|
327
|
+
*
|
|
328
|
+
* The optional `options` argument controls stream behavior. For XOF hash
|
|
329
|
+
* functions such as `'shake256'`, the `outputLength` option can be used to
|
|
330
|
+
* specify the desired output length in bytes.
|
|
331
|
+
*
|
|
332
|
+
* An error is thrown when an attempt is made to copy the `Hash` object after
|
|
333
|
+
* its `hash.digest()` method has been called.
|
|
334
|
+
*
|
|
335
|
+
* ```js
|
|
336
|
+
* // Calculate a rolling hash.
|
|
337
|
+
* const {
|
|
338
|
+
* createHash
|
|
339
|
+
* } = await import('crypto');
|
|
340
|
+
*
|
|
341
|
+
* const hash = createHash('sha256');
|
|
342
|
+
*
|
|
343
|
+
* hash.update('one');
|
|
344
|
+
* console.log(hash.copy().digest('hex'));
|
|
345
|
+
*
|
|
346
|
+
* hash.update('two');
|
|
347
|
+
* console.log(hash.copy().digest('hex'));
|
|
348
|
+
*
|
|
349
|
+
* hash.update('three');
|
|
350
|
+
* console.log(hash.copy().digest('hex'));
|
|
351
|
+
*
|
|
352
|
+
* // Etc.
|
|
353
|
+
* ```
|
|
354
|
+
* @since v13.1.0
|
|
355
|
+
* @param options `stream.transform` options
|
|
356
|
+
*/
|
|
357
|
+
copy(options?: stream.TransformOptions): Hash;
|
|
358
|
+
/**
|
|
359
|
+
* Updates the hash content with the given `data`, the encoding of which
|
|
360
|
+
* is given in `inputEncoding`.
|
|
361
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
362
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
363
|
+
*
|
|
364
|
+
* This can be called many times with new data as it is streamed.
|
|
365
|
+
* @since v0.1.92
|
|
366
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
367
|
+
*/
|
|
178
368
|
update(data: BinaryLike): Hash;
|
|
179
|
-
update(data: string,
|
|
369
|
+
update(data: string, inputEncoding: Encoding): Hash;
|
|
370
|
+
/**
|
|
371
|
+
* Calculates the digest of all of the data passed to be hashed (using the `hash.update()` method).
|
|
372
|
+
* If `encoding` is provided a string will be returned; otherwise
|
|
373
|
+
* a `Buffer` is returned.
|
|
374
|
+
*
|
|
375
|
+
* The `Hash` object can not be used again after `hash.digest()` method has been
|
|
376
|
+
* called. Multiple calls will cause an error to be thrown.
|
|
377
|
+
* @since v0.1.92
|
|
378
|
+
* @param encoding The `encoding` of the return value.
|
|
379
|
+
*/
|
|
180
380
|
digest(): Buffer;
|
|
181
381
|
digest(encoding: BinaryToTextEncoding): string;
|
|
182
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* The `Hmac` class is a utility for creating cryptographic HMAC digests. It can
|
|
385
|
+
* be used in one of two ways:
|
|
386
|
+
*
|
|
387
|
+
* * As a `stream` that is both readable and writable, where data is written
|
|
388
|
+
* to produce a computed HMAC digest on the readable side, or
|
|
389
|
+
* * Using the `hmac.update()` and `hmac.digest()` methods to produce the
|
|
390
|
+
* computed HMAC digest.
|
|
391
|
+
*
|
|
392
|
+
* The {@link createHmac} method is used to create `Hmac` instances. `Hmac`objects are not to be created directly using the `new` keyword.
|
|
393
|
+
*
|
|
394
|
+
* Example: Using `Hmac` objects as streams:
|
|
395
|
+
*
|
|
396
|
+
* ```js
|
|
397
|
+
* const {
|
|
398
|
+
* createHmac
|
|
399
|
+
* } = await import('crypto');
|
|
400
|
+
*
|
|
401
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
402
|
+
*
|
|
403
|
+
* hmac.on('readable', () => {
|
|
404
|
+
* // Only one element is going to be produced by the
|
|
405
|
+
* // hash stream.
|
|
406
|
+
* const data = hmac.read();
|
|
407
|
+
* if (data) {
|
|
408
|
+
* console.log(data.toString('hex'));
|
|
409
|
+
* // Prints:
|
|
410
|
+
* // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
|
|
411
|
+
* }
|
|
412
|
+
* });
|
|
413
|
+
*
|
|
414
|
+
* hmac.write('some data to hash');
|
|
415
|
+
* hmac.end();
|
|
416
|
+
* ```
|
|
417
|
+
*
|
|
418
|
+
* Example: Using `Hmac` and piped streams:
|
|
419
|
+
*
|
|
420
|
+
* ```js
|
|
421
|
+
* import { createReadStream } from 'fs';
|
|
422
|
+
* import { stdout } from 'process';
|
|
423
|
+
* const {
|
|
424
|
+
* createHmac
|
|
425
|
+
* } = await import('crypto');
|
|
426
|
+
*
|
|
427
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
428
|
+
*
|
|
429
|
+
* const input = createReadStream('test.js');
|
|
430
|
+
* input.pipe(hmac).pipe(stdout);
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* Example: Using the `hmac.update()` and `hmac.digest()` methods:
|
|
434
|
+
*
|
|
435
|
+
* ```js
|
|
436
|
+
* const {
|
|
437
|
+
* createHmac
|
|
438
|
+
* } = await import('crypto');
|
|
439
|
+
*
|
|
440
|
+
* const hmac = createHmac('sha256', 'a secret');
|
|
441
|
+
*
|
|
442
|
+
* hmac.update('some data to hash');
|
|
443
|
+
* console.log(hmac.digest('hex'));
|
|
444
|
+
* // Prints:
|
|
445
|
+
* // 7fd04df92f636fd450bc841c9418e5825c17f33ad9c87c518115a45971f7f77e
|
|
446
|
+
* ```
|
|
447
|
+
* @since v0.1.94
|
|
448
|
+
*/
|
|
183
449
|
class Hmac extends stream.Transform {
|
|
184
450
|
private constructor();
|
|
451
|
+
/**
|
|
452
|
+
* Updates the `Hmac` content with the given `data`, the encoding of which
|
|
453
|
+
* is given in `inputEncoding`.
|
|
454
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
455
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
456
|
+
*
|
|
457
|
+
* This can be called many times with new data as it is streamed.
|
|
458
|
+
* @since v0.1.94
|
|
459
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
460
|
+
*/
|
|
185
461
|
update(data: BinaryLike): Hmac;
|
|
186
|
-
update(data: string,
|
|
462
|
+
update(data: string, inputEncoding: Encoding): Hmac;
|
|
463
|
+
/**
|
|
464
|
+
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
|
|
465
|
+
* If `encoding` is
|
|
466
|
+
* provided a string is returned; otherwise a `Buffer` is returned;
|
|
467
|
+
*
|
|
468
|
+
* The `Hmac` object can not be used again after `hmac.digest()` has been
|
|
469
|
+
* called. Multiple calls to `hmac.digest()` will result in an error being thrown.
|
|
470
|
+
* @since v0.1.94
|
|
471
|
+
* @param encoding The `encoding` of the return value.
|
|
472
|
+
*/
|
|
187
473
|
digest(): Buffer;
|
|
188
474
|
digest(encoding: BinaryToTextEncoding): string;
|
|
189
475
|
}
|
|
190
|
-
|
|
191
476
|
type KeyObjectType = 'secret' | 'public' | 'private';
|
|
192
|
-
|
|
193
477
|
interface KeyExportOptions<T extends KeyFormat> {
|
|
194
478
|
type: 'pkcs1' | 'spki' | 'pkcs8' | 'sec1';
|
|
195
479
|
format: T;
|
|
@@ -215,7 +499,6 @@ declare module 'crypto' {
|
|
|
215
499
|
y?: string | undefined;
|
|
216
500
|
[key: string]: unknown;
|
|
217
501
|
}
|
|
218
|
-
|
|
219
502
|
interface AsymmetricKeyDetails {
|
|
220
503
|
/**
|
|
221
504
|
* Key size in bits (RSA, DSA).
|
|
@@ -225,6 +508,18 @@ declare module 'crypto' {
|
|
|
225
508
|
* Public exponent (RSA).
|
|
226
509
|
*/
|
|
227
510
|
publicExponent?: bigint | undefined;
|
|
511
|
+
/**
|
|
512
|
+
* Name of the message digest (RSA-PSS).
|
|
513
|
+
*/
|
|
514
|
+
hashAlgorithm?: string | undefined;
|
|
515
|
+
/**
|
|
516
|
+
* Name of the message digest used by MGF1 (RSA-PSS).
|
|
517
|
+
*/
|
|
518
|
+
mgf1HashAlgorithm?: string | undefined;
|
|
519
|
+
/**
|
|
520
|
+
* Minimal salt length in bytes (RSA-PSS).
|
|
521
|
+
*/
|
|
522
|
+
saltLength?: number | undefined;
|
|
228
523
|
/**
|
|
229
524
|
* Size of q in bits (DSA).
|
|
230
525
|
*/
|
|
@@ -234,13 +529,62 @@ declare module 'crypto' {
|
|
|
234
529
|
*/
|
|
235
530
|
namedCurve?: string | undefined;
|
|
236
531
|
}
|
|
237
|
-
|
|
238
532
|
interface JwkKeyExportOptions {
|
|
239
533
|
format: 'jwk';
|
|
240
534
|
}
|
|
241
|
-
|
|
535
|
+
/**
|
|
536
|
+
* Node.js uses a `KeyObject` class to represent a symmetric or asymmetric key,
|
|
537
|
+
* and each kind of key exposes different functions. The {@link createSecretKey}, {@link createPublicKey} and {@link createPrivateKey} methods are used to create `KeyObject`instances. `KeyObject`
|
|
538
|
+
* objects are not to be created directly using the `new`keyword.
|
|
539
|
+
*
|
|
540
|
+
* Most applications should consider using the new `KeyObject` API instead of
|
|
541
|
+
* passing keys as strings or `Buffer`s due to improved security features.
|
|
542
|
+
*
|
|
543
|
+
* `KeyObject` instances can be passed to other threads via `postMessage()`.
|
|
544
|
+
* The receiver obtains a cloned `KeyObject`, and the `KeyObject` does not need to
|
|
545
|
+
* be listed in the `transferList` argument.
|
|
546
|
+
* @since v11.6.0
|
|
547
|
+
*/
|
|
242
548
|
class KeyObject {
|
|
243
549
|
private constructor();
|
|
550
|
+
/**
|
|
551
|
+
* Example: Converting a `CryptoKey` instance to a `KeyObject`:
|
|
552
|
+
*
|
|
553
|
+
* ```js
|
|
554
|
+
* const { webcrypto, KeyObject } = await import('crypto');
|
|
555
|
+
* const { subtle } = webcrypto;
|
|
556
|
+
*
|
|
557
|
+
* const key = await subtle.generateKey({
|
|
558
|
+
* name: 'HMAC',
|
|
559
|
+
* hash: 'SHA-256',
|
|
560
|
+
* length: 256
|
|
561
|
+
* }, true, ['sign', 'verify']);
|
|
562
|
+
*
|
|
563
|
+
* const keyObject = KeyObject.from(key);
|
|
564
|
+
* console.log(keyObject.symmetricKeySize);
|
|
565
|
+
* // Prints: 32 (symmetric key size in bytes)
|
|
566
|
+
* ```
|
|
567
|
+
* @since v15.0.0
|
|
568
|
+
*/
|
|
569
|
+
static from(key: webcrypto.CryptoKey): KeyObject;
|
|
570
|
+
/**
|
|
571
|
+
* For asymmetric keys, this property represents the type of the key. Supported key
|
|
572
|
+
* types are:
|
|
573
|
+
*
|
|
574
|
+
* * `'rsa'` (OID 1.2.840.113549.1.1.1)
|
|
575
|
+
* * `'rsa-pss'` (OID 1.2.840.113549.1.1.10)
|
|
576
|
+
* * `'dsa'` (OID 1.2.840.10040.4.1)
|
|
577
|
+
* * `'ec'` (OID 1.2.840.10045.2.1)
|
|
578
|
+
* * `'x25519'` (OID 1.3.101.110)
|
|
579
|
+
* * `'x448'` (OID 1.3.101.111)
|
|
580
|
+
* * `'ed25519'` (OID 1.3.101.112)
|
|
581
|
+
* * `'ed448'` (OID 1.3.101.113)
|
|
582
|
+
* * `'dh'` (OID 1.2.840.113549.1.3.1)
|
|
583
|
+
*
|
|
584
|
+
* This property is `undefined` for unrecognized `KeyObject` types and symmetric
|
|
585
|
+
* keys.
|
|
586
|
+
* @since v11.6.0
|
|
587
|
+
*/
|
|
244
588
|
asymmetricKeyType?: KeyType | undefined;
|
|
245
589
|
/**
|
|
246
590
|
* For asymmetric keys, this property represents the size of the embedded key in
|
|
@@ -250,151 +594,649 @@ declare module 'crypto' {
|
|
|
250
594
|
/**
|
|
251
595
|
* This property exists only on asymmetric keys. Depending on the type of the key,
|
|
252
596
|
* this object contains information about the key. None of the information obtained
|
|
253
|
-
* through this property can be used to uniquely identify a key or to compromise
|
|
254
|
-
* security of the key.
|
|
597
|
+
* through this property can be used to uniquely identify a key or to compromise
|
|
598
|
+
* the security of the key.
|
|
599
|
+
*
|
|
600
|
+
* For RSA-PSS keys, if the key material contains a `RSASSA-PSS-params` sequence,
|
|
601
|
+
* the `hashAlgorithm`, `mgf1HashAlgorithm`, and `saltLength` properties will be
|
|
602
|
+
* set.
|
|
603
|
+
*
|
|
604
|
+
* Other key details might be exposed via this API using additional attributes.
|
|
605
|
+
* @since v15.7.0
|
|
255
606
|
*/
|
|
256
607
|
asymmetricKeyDetails?: AsymmetricKeyDetails | undefined;
|
|
608
|
+
/**
|
|
609
|
+
* For symmetric keys, the following encoding options can be used:
|
|
610
|
+
*
|
|
611
|
+
* For public keys, the following encoding options can be used:
|
|
612
|
+
*
|
|
613
|
+
* For private keys, the following encoding options can be used:
|
|
614
|
+
*
|
|
615
|
+
* The result type depends on the selected encoding format, when PEM the
|
|
616
|
+
* result is a string, when DER it will be a buffer containing the data
|
|
617
|
+
* encoded as DER, when [JWK](https://tools.ietf.org/html/rfc7517) it will be an object.
|
|
618
|
+
*
|
|
619
|
+
* When [JWK](https://tools.ietf.org/html/rfc7517) encoding format was selected, all other encoding options are
|
|
620
|
+
* ignored.
|
|
621
|
+
*
|
|
622
|
+
* PKCS#1, SEC1, and PKCS#8 type keys can be encrypted by using a combination of
|
|
623
|
+
* 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
|
|
624
|
+
* encrypted by specifying a `cipher`when the PEM `format` is used. For maximum compatibility, use PKCS#8 for
|
|
625
|
+
* encrypted private keys. Since PKCS#8 defines its own
|
|
626
|
+
* encryption mechanism, PEM-level encryption is not supported when encrypting
|
|
627
|
+
* 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
|
|
628
|
+
* PKCS#1 and SEC1 encryption.
|
|
629
|
+
* @since v11.6.0
|
|
630
|
+
*/
|
|
257
631
|
export(options: KeyExportOptions<'pem'>): string | Buffer;
|
|
258
632
|
export(options?: KeyExportOptions<'der'>): Buffer;
|
|
259
633
|
export(options?: JwkKeyExportOptions): JsonWebKey;
|
|
634
|
+
/**
|
|
635
|
+
* For secret keys, this property represents the size of the key in bytes. This
|
|
636
|
+
* property is `undefined` for asymmetric keys.
|
|
637
|
+
* @since v11.6.0
|
|
638
|
+
*/
|
|
260
639
|
symmetricKeySize?: number | undefined;
|
|
640
|
+
/**
|
|
641
|
+
* Depending on the type of this `KeyObject`, this property is either`'secret'` for secret (symmetric) keys, `'public'` for public (asymmetric) keys
|
|
642
|
+
* or `'private'` for private (asymmetric) keys.
|
|
643
|
+
* @since v11.6.0
|
|
644
|
+
*/
|
|
261
645
|
type: KeyObjectType;
|
|
262
646
|
}
|
|
263
|
-
|
|
264
647
|
type CipherCCMTypes = 'aes-128-ccm' | 'aes-192-ccm' | 'aes-256-ccm' | 'chacha20-poly1305';
|
|
265
648
|
type CipherGCMTypes = 'aes-128-gcm' | 'aes-192-gcm' | 'aes-256-gcm';
|
|
266
|
-
|
|
267
649
|
type BinaryLike = string | NodeJS.ArrayBufferView;
|
|
268
|
-
|
|
269
650
|
type CipherKey = BinaryLike | KeyObject;
|
|
270
|
-
|
|
271
651
|
interface CipherCCMOptions extends stream.TransformOptions {
|
|
272
652
|
authTagLength: number;
|
|
273
653
|
}
|
|
274
654
|
interface CipherGCMOptions extends stream.TransformOptions {
|
|
275
655
|
authTagLength?: number | undefined;
|
|
276
656
|
}
|
|
277
|
-
/**
|
|
657
|
+
/**
|
|
658
|
+
* Creates and returns a `Cipher` object that uses the given `algorithm` and`password`.
|
|
659
|
+
*
|
|
660
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
661
|
+
* cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
|
|
662
|
+
* 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
|
|
663
|
+
* tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
|
|
664
|
+
*
|
|
665
|
+
* The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
|
|
666
|
+
* recent OpenSSL releases, `openssl list -cipher-algorithms`(`openssl list-cipher-algorithms` for older versions of OpenSSL) will
|
|
667
|
+
* display the available cipher algorithms.
|
|
668
|
+
*
|
|
669
|
+
* The `password` is used to derive the cipher key and initialization vector (IV).
|
|
670
|
+
* The value must be either a `'latin1'` encoded string, a `Buffer`, a`TypedArray`, or a `DataView`.
|
|
671
|
+
*
|
|
672
|
+
* The implementation of `crypto.createCipher()` derives keys using the OpenSSL
|
|
673
|
+
* function [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) with the digest algorithm set to MD5, one
|
|
674
|
+
* iteration, and no salt. The lack of salt allows dictionary attacks as the same
|
|
675
|
+
* password always creates the same key. The low iteration count and
|
|
676
|
+
* non-cryptographically secure hash algorithm allow passwords to be tested very
|
|
677
|
+
* rapidly.
|
|
678
|
+
*
|
|
679
|
+
* In line with OpenSSL's recommendation to use a more modern algorithm instead of [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) it is recommended that
|
|
680
|
+
* developers derive a key and IV on
|
|
681
|
+
* their own using {@link scrypt} and to use {@link createCipheriv} to create the `Cipher` object. Users should not use ciphers with counter mode
|
|
682
|
+
* (e.g. CTR, GCM, or CCM) in `crypto.createCipher()`. A warning is emitted when
|
|
683
|
+
* they are used in order to avoid the risk of IV reuse that causes
|
|
684
|
+
* vulnerabilities. For the case when IV is reused in GCM, see [Nonce-Disrespecting Adversaries](https://github.com/nonce-disrespect/nonce-disrespect) for details.
|
|
685
|
+
* @since v0.1.94
|
|
686
|
+
* @deprecated Since v10.0.0 - Use {@link createCipheriv} instead.
|
|
687
|
+
* @param options `stream.transform` options
|
|
688
|
+
*/
|
|
278
689
|
function createCipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): CipherCCM;
|
|
279
690
|
/** @deprecated since v10.0.0 use `createCipheriv()` */
|
|
280
691
|
function createCipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): CipherGCM;
|
|
281
692
|
/** @deprecated since v10.0.0 use `createCipheriv()` */
|
|
282
693
|
function createCipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Cipher;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
694
|
+
/**
|
|
695
|
+
* Creates and returns a `Cipher` object, with the given `algorithm`, `key` and
|
|
696
|
+
* initialization vector (`iv`).
|
|
697
|
+
*
|
|
698
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
699
|
+
* cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
|
|
700
|
+
* 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
|
|
701
|
+
* tag that will be returned by `getAuthTag()` and defaults to 16 bytes.
|
|
702
|
+
*
|
|
703
|
+
* The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
|
|
704
|
+
* recent OpenSSL releases, `openssl list -cipher-algorithms`(`openssl list-cipher-algorithms` for older versions of OpenSSL) will
|
|
705
|
+
* display the available cipher algorithms.
|
|
706
|
+
*
|
|
707
|
+
* 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
|
|
708
|
+
* strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
|
|
709
|
+
* a `KeyObject` of type `secret`. If the cipher does not need
|
|
710
|
+
* an initialization vector, `iv` may be `null`.
|
|
711
|
+
*
|
|
712
|
+
* When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
713
|
+
*
|
|
714
|
+
* Initialization vectors should be unpredictable and unique; ideally, they will be
|
|
715
|
+
* cryptographically random. They do not have to be secret: IVs are typically just
|
|
716
|
+
* added to ciphertext messages unencrypted. It may sound contradictory that
|
|
717
|
+
* something has to be unpredictable and unique, but does not have to be secret;
|
|
718
|
+
* remember that an attacker must not be able to predict ahead of time what a
|
|
719
|
+
* given IV will be.
|
|
720
|
+
* @since v0.1.94
|
|
721
|
+
* @param options `stream.transform` options
|
|
722
|
+
*/
|
|
723
|
+
function createCipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike | null, options: CipherCCMOptions): CipherCCM;
|
|
724
|
+
function createCipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike | null, options?: CipherGCMOptions): CipherGCM;
|
|
725
|
+
function createCipheriv(algorithm: string, key: CipherKey, iv: BinaryLike | null, options?: stream.TransformOptions): Cipher;
|
|
726
|
+
/**
|
|
727
|
+
* Instances of the `Cipher` class are used to encrypt data. The class can be
|
|
728
|
+
* used in one of two ways:
|
|
729
|
+
*
|
|
730
|
+
* * As a `stream` that is both readable and writable, where plain unencrypted
|
|
731
|
+
* data is written to produce encrypted data on the readable side, or
|
|
732
|
+
* * Using the `cipher.update()` and `cipher.final()` methods to produce
|
|
733
|
+
* the encrypted data.
|
|
734
|
+
*
|
|
735
|
+
* The {@link createCipher} or {@link createCipheriv} methods are
|
|
736
|
+
* used to create `Cipher` instances. `Cipher` objects are not to be created
|
|
737
|
+
* directly using the `new` keyword.
|
|
738
|
+
*
|
|
739
|
+
* Example: Using `Cipher` objects as streams:
|
|
740
|
+
*
|
|
741
|
+
* ```js
|
|
742
|
+
* const {
|
|
743
|
+
* scrypt,
|
|
744
|
+
* randomFill,
|
|
745
|
+
* createCipheriv
|
|
746
|
+
* } = await import('crypto');
|
|
747
|
+
*
|
|
748
|
+
* const algorithm = 'aes-192-cbc';
|
|
749
|
+
* const password = 'Password used to generate key';
|
|
750
|
+
*
|
|
751
|
+
* // First, we'll generate the key. The key length is dependent on the algorithm.
|
|
752
|
+
* // In this case for aes192, it is 24 bytes (192 bits).
|
|
753
|
+
* scrypt(password, 'salt', 24, (err, key) => {
|
|
754
|
+
* if (err) throw err;
|
|
755
|
+
* // Then, we'll generate a random initialization vector
|
|
756
|
+
* randomFill(new Uint8Array(16), (err, iv) => {
|
|
757
|
+
* if (err) throw err;
|
|
758
|
+
*
|
|
759
|
+
* // Once we have the key and iv, we can create and use the cipher...
|
|
760
|
+
* const cipher = createCipheriv(algorithm, key, iv);
|
|
761
|
+
*
|
|
762
|
+
* let encrypted = '';
|
|
763
|
+
* cipher.setEncoding('hex');
|
|
764
|
+
*
|
|
765
|
+
* cipher.on('data', (chunk) => encrypted += chunk);
|
|
766
|
+
* cipher.on('end', () => console.log(encrypted));
|
|
767
|
+
*
|
|
768
|
+
* cipher.write('some clear text data');
|
|
769
|
+
* cipher.end();
|
|
770
|
+
* });
|
|
771
|
+
* });
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* Example: Using `Cipher` and piped streams:
|
|
775
|
+
*
|
|
776
|
+
* ```js
|
|
777
|
+
* import {
|
|
778
|
+
* createReadStream,
|
|
779
|
+
* createWriteStream,
|
|
780
|
+
* } from 'fs';
|
|
781
|
+
*
|
|
782
|
+
* import {
|
|
783
|
+
* pipeline
|
|
784
|
+
* } from 'stream';
|
|
785
|
+
*
|
|
786
|
+
* const {
|
|
787
|
+
* scrypt,
|
|
788
|
+
* randomFill,
|
|
789
|
+
* createCipheriv
|
|
790
|
+
* } = await import('crypto');
|
|
791
|
+
*
|
|
792
|
+
* const algorithm = 'aes-192-cbc';
|
|
793
|
+
* const password = 'Password used to generate key';
|
|
794
|
+
*
|
|
795
|
+
* // First, we'll generate the key. The key length is dependent on the algorithm.
|
|
796
|
+
* // In this case for aes192, it is 24 bytes (192 bits).
|
|
797
|
+
* scrypt(password, 'salt', 24, (err, key) => {
|
|
798
|
+
* if (err) throw err;
|
|
799
|
+
* // Then, we'll generate a random initialization vector
|
|
800
|
+
* randomFill(new Uint8Array(16), (err, iv) => {
|
|
801
|
+
* if (err) throw err;
|
|
802
|
+
*
|
|
803
|
+
* const cipher = createCipheriv(algorithm, key, iv);
|
|
804
|
+
*
|
|
805
|
+
* const input = createReadStream('test.js');
|
|
806
|
+
* const output = createWriteStream('test.enc');
|
|
807
|
+
*
|
|
808
|
+
* pipeline(input, cipher, output, (err) => {
|
|
809
|
+
* if (err) throw err;
|
|
810
|
+
* });
|
|
811
|
+
* });
|
|
812
|
+
* });
|
|
813
|
+
* ```
|
|
814
|
+
*
|
|
815
|
+
* Example: Using the `cipher.update()` and `cipher.final()` methods:
|
|
816
|
+
*
|
|
817
|
+
* ```js
|
|
818
|
+
* const {
|
|
819
|
+
* scrypt,
|
|
820
|
+
* randomFill,
|
|
821
|
+
* createCipheriv
|
|
822
|
+
* } = await import('crypto');
|
|
823
|
+
*
|
|
824
|
+
* const algorithm = 'aes-192-cbc';
|
|
825
|
+
* const password = 'Password used to generate key';
|
|
826
|
+
*
|
|
827
|
+
* // First, we'll generate the key. The key length is dependent on the algorithm.
|
|
828
|
+
* // In this case for aes192, it is 24 bytes (192 bits).
|
|
829
|
+
* scrypt(password, 'salt', 24, (err, key) => {
|
|
830
|
+
* if (err) throw err;
|
|
831
|
+
* // Then, we'll generate a random initialization vector
|
|
832
|
+
* randomFill(new Uint8Array(16), (err, iv) => {
|
|
833
|
+
* if (err) throw err;
|
|
834
|
+
*
|
|
835
|
+
* const cipher = createCipheriv(algorithm, key, iv);
|
|
836
|
+
*
|
|
837
|
+
* let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
|
|
838
|
+
* encrypted += cipher.final('hex');
|
|
839
|
+
* console.log(encrypted);
|
|
840
|
+
* });
|
|
841
|
+
* });
|
|
842
|
+
* ```
|
|
843
|
+
* @since v0.1.94
|
|
844
|
+
*/
|
|
303
845
|
class Cipher extends stream.Transform {
|
|
304
846
|
private constructor();
|
|
847
|
+
/**
|
|
848
|
+
* Updates the cipher with `data`. If the `inputEncoding` argument is given,
|
|
849
|
+
* 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`,
|
|
850
|
+
* `TypedArray`, or `DataView`, then`inputEncoding` is ignored.
|
|
851
|
+
*
|
|
852
|
+
* The `outputEncoding` specifies the output format of the enciphered
|
|
853
|
+
* data. If the `outputEncoding`is specified, a string using the specified encoding is returned. If no`outputEncoding` is provided, a `Buffer` is returned.
|
|
854
|
+
*
|
|
855
|
+
* 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
|
|
856
|
+
* thrown.
|
|
857
|
+
* @since v0.1.94
|
|
858
|
+
* @param inputEncoding The `encoding` of the data.
|
|
859
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
860
|
+
*/
|
|
305
861
|
update(data: BinaryLike): Buffer;
|
|
306
|
-
update(data: string,
|
|
307
|
-
update(data: NodeJS.ArrayBufferView,
|
|
308
|
-
update(data: string,
|
|
862
|
+
update(data: string, inputEncoding: Encoding): Buffer;
|
|
863
|
+
update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string;
|
|
864
|
+
update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string;
|
|
865
|
+
/**
|
|
866
|
+
* Once the `cipher.final()` method has been called, the `Cipher` object can no
|
|
867
|
+
* longer be used to encrypt data. Attempts to call `cipher.final()` more than
|
|
868
|
+
* once will result in an error being thrown.
|
|
869
|
+
* @since v0.1.94
|
|
870
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
871
|
+
* @return Any remaining enciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
|
|
872
|
+
*/
|
|
309
873
|
final(): Buffer;
|
|
310
|
-
final(
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
874
|
+
final(outputEncoding: BufferEncoding): string;
|
|
875
|
+
/**
|
|
876
|
+
* When using block encryption algorithms, the `Cipher` class will automatically
|
|
877
|
+
* add padding to the input data to the appropriate block size. To disable the
|
|
878
|
+
* default padding call `cipher.setAutoPadding(false)`.
|
|
879
|
+
*
|
|
880
|
+
* When `autoPadding` is `false`, the length of the entire input data must be a
|
|
881
|
+
* multiple of the cipher's block size or `cipher.final()` will throw an error.
|
|
882
|
+
* Disabling automatic padding is useful for non-standard padding, for instance
|
|
883
|
+
* using `0x0` instead of PKCS padding.
|
|
884
|
+
*
|
|
885
|
+
* The `cipher.setAutoPadding()` method must be called before `cipher.final()`.
|
|
886
|
+
* @since v0.7.1
|
|
887
|
+
* @param [autoPadding=true]
|
|
888
|
+
* @return for method chaining.
|
|
889
|
+
*/
|
|
890
|
+
setAutoPadding(autoPadding?: boolean): this;
|
|
314
891
|
}
|
|
315
892
|
interface CipherCCM extends Cipher {
|
|
316
|
-
setAAD(
|
|
893
|
+
setAAD(
|
|
894
|
+
buffer: NodeJS.ArrayBufferView,
|
|
895
|
+
options: {
|
|
896
|
+
plaintextLength: number;
|
|
897
|
+
}
|
|
898
|
+
): this;
|
|
317
899
|
getAuthTag(): Buffer;
|
|
318
900
|
}
|
|
319
901
|
interface CipherGCM extends Cipher {
|
|
320
|
-
setAAD(
|
|
902
|
+
setAAD(
|
|
903
|
+
buffer: NodeJS.ArrayBufferView,
|
|
904
|
+
options?: {
|
|
905
|
+
plaintextLength: number;
|
|
906
|
+
}
|
|
907
|
+
): this;
|
|
321
908
|
getAuthTag(): Buffer;
|
|
322
909
|
}
|
|
323
|
-
/**
|
|
910
|
+
/**
|
|
911
|
+
* Creates and returns a `Decipher` object that uses the given `algorithm` and`password` (key).
|
|
912
|
+
*
|
|
913
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
914
|
+
* cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
|
|
915
|
+
* authentication tag in bytes, see `CCM mode`.
|
|
916
|
+
*
|
|
917
|
+
* The implementation of `crypto.createDecipher()` derives keys using the OpenSSL
|
|
918
|
+
* function [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) with the digest algorithm set to MD5, one
|
|
919
|
+
* iteration, and no salt. The lack of salt allows dictionary attacks as the same
|
|
920
|
+
* password always creates the same key. The low iteration count and
|
|
921
|
+
* non-cryptographically secure hash algorithm allow passwords to be tested very
|
|
922
|
+
* rapidly.
|
|
923
|
+
*
|
|
924
|
+
* In line with OpenSSL's recommendation to use a more modern algorithm instead of [`EVP_BytesToKey`](https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html) it is recommended that
|
|
925
|
+
* developers derive a key and IV on
|
|
926
|
+
* their own using {@link scrypt} and to use {@link createDecipheriv} to create the `Decipher` object.
|
|
927
|
+
* @since v0.1.94
|
|
928
|
+
* @deprecated Since v10.0.0 - Use {@link createDecipheriv} instead.
|
|
929
|
+
* @param options `stream.transform` options
|
|
930
|
+
*/
|
|
324
931
|
function createDecipher(algorithm: CipherCCMTypes, password: BinaryLike, options: CipherCCMOptions): DecipherCCM;
|
|
325
932
|
/** @deprecated since v10.0.0 use `createDecipheriv()` */
|
|
326
933
|
function createDecipher(algorithm: CipherGCMTypes, password: BinaryLike, options?: CipherGCMOptions): DecipherGCM;
|
|
327
934
|
/** @deprecated since v10.0.0 use `createDecipheriv()` */
|
|
328
935
|
function createDecipher(algorithm: string, password: BinaryLike, options?: stream.TransformOptions): Decipher;
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
936
|
+
/**
|
|
937
|
+
* Creates and returns a `Decipher` object that uses the given `algorithm`, `key`and initialization vector (`iv`).
|
|
938
|
+
*
|
|
939
|
+
* The `options` argument controls stream behavior and is optional except when a
|
|
940
|
+
* cipher in CCM or OCB mode is used (e.g. `'aes-128-ccm'`). In that case, the`authTagLength` option is required and specifies the length of the
|
|
941
|
+
* 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
|
|
942
|
+
* to those with the specified length.
|
|
943
|
+
*
|
|
944
|
+
* The `algorithm` is dependent on OpenSSL, examples are `'aes192'`, etc. On
|
|
945
|
+
* recent OpenSSL releases, `openssl list -cipher-algorithms`(`openssl list-cipher-algorithms` for older versions of OpenSSL) will
|
|
946
|
+
* display the available cipher algorithms.
|
|
947
|
+
*
|
|
948
|
+
* 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
|
|
949
|
+
* strings,`Buffers`, `TypedArray`, or `DataView`s. The `key` may optionally be
|
|
950
|
+
* a `KeyObject` of type `secret`. If the cipher does not need
|
|
951
|
+
* an initialization vector, `iv` may be `null`.
|
|
952
|
+
*
|
|
953
|
+
* When passing strings for `key` or `iv`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
954
|
+
*
|
|
955
|
+
* Initialization vectors should be unpredictable and unique; ideally, they will be
|
|
956
|
+
* cryptographically random. They do not have to be secret: IVs are typically just
|
|
957
|
+
* added to ciphertext messages unencrypted. It may sound contradictory that
|
|
958
|
+
* something has to be unpredictable and unique, but does not have to be secret;
|
|
959
|
+
* remember that an attacker must not be able to predict ahead of time what a given
|
|
960
|
+
* IV will be.
|
|
961
|
+
* @since v0.1.94
|
|
962
|
+
* @param options `stream.transform` options
|
|
963
|
+
*/
|
|
964
|
+
function createDecipheriv(algorithm: CipherCCMTypes, key: CipherKey, iv: BinaryLike | null, options: CipherCCMOptions): DecipherCCM;
|
|
965
|
+
function createDecipheriv(algorithm: CipherGCMTypes, key: CipherKey, iv: BinaryLike | null, options?: CipherGCMOptions): DecipherGCM;
|
|
966
|
+
function createDecipheriv(algorithm: string, key: CipherKey, iv: BinaryLike | null, options?: stream.TransformOptions): Decipher;
|
|
967
|
+
/**
|
|
968
|
+
* Instances of the `Decipher` class are used to decrypt data. The class can be
|
|
969
|
+
* used in one of two ways:
|
|
970
|
+
*
|
|
971
|
+
* * As a `stream` that is both readable and writable, where plain encrypted
|
|
972
|
+
* data is written to produce unencrypted data on the readable side, or
|
|
973
|
+
* * Using the `decipher.update()` and `decipher.final()` methods to
|
|
974
|
+
* produce the unencrypted data.
|
|
975
|
+
*
|
|
976
|
+
* The {@link createDecipher} or {@link createDecipheriv} methods are
|
|
977
|
+
* used to create `Decipher` instances. `Decipher` objects are not to be created
|
|
978
|
+
* directly using the `new` keyword.
|
|
979
|
+
*
|
|
980
|
+
* Example: Using `Decipher` objects as streams:
|
|
981
|
+
*
|
|
982
|
+
* ```js
|
|
983
|
+
* import { Buffer } from 'buffer';
|
|
984
|
+
* const {
|
|
985
|
+
* scryptSync,
|
|
986
|
+
* createDecipheriv
|
|
987
|
+
* } = await import('crypto');
|
|
988
|
+
*
|
|
989
|
+
* const algorithm = 'aes-192-cbc';
|
|
990
|
+
* const password = 'Password used to generate key';
|
|
991
|
+
* // Key length is dependent on the algorithm. In this case for aes192, it is
|
|
992
|
+
* // 24 bytes (192 bits).
|
|
993
|
+
* // Use the async `crypto.scrypt()` instead.
|
|
994
|
+
* const key = scryptSync(password, 'salt', 24);
|
|
995
|
+
* // The IV is usually passed along with the ciphertext.
|
|
996
|
+
* const iv = Buffer.alloc(16, 0); // Initialization vector.
|
|
997
|
+
*
|
|
998
|
+
* const decipher = createDecipheriv(algorithm, key, iv);
|
|
999
|
+
*
|
|
1000
|
+
* let decrypted = '';
|
|
1001
|
+
* decipher.on('readable', () => {
|
|
1002
|
+
* while (null !== (chunk = decipher.read())) {
|
|
1003
|
+
* decrypted += chunk.toString('utf8');
|
|
1004
|
+
* }
|
|
1005
|
+
* });
|
|
1006
|
+
* decipher.on('end', () => {
|
|
1007
|
+
* console.log(decrypted);
|
|
1008
|
+
* // Prints: some clear text data
|
|
1009
|
+
* });
|
|
1010
|
+
*
|
|
1011
|
+
* // Encrypted with same algorithm, key and iv.
|
|
1012
|
+
* const encrypted =
|
|
1013
|
+
* 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
|
|
1014
|
+
* decipher.write(encrypted, 'hex');
|
|
1015
|
+
* decipher.end();
|
|
1016
|
+
* ```
|
|
1017
|
+
*
|
|
1018
|
+
* Example: Using `Decipher` and piped streams:
|
|
1019
|
+
*
|
|
1020
|
+
* ```js
|
|
1021
|
+
* import {
|
|
1022
|
+
* createReadStream,
|
|
1023
|
+
* createWriteStream,
|
|
1024
|
+
* } from 'fs';
|
|
1025
|
+
* import { Buffer } from 'buffer';
|
|
1026
|
+
* const {
|
|
1027
|
+
* scryptSync,
|
|
1028
|
+
* createDecipheriv
|
|
1029
|
+
* } = await import('crypto');
|
|
1030
|
+
*
|
|
1031
|
+
* const algorithm = 'aes-192-cbc';
|
|
1032
|
+
* const password = 'Password used to generate key';
|
|
1033
|
+
* // Use the async `crypto.scrypt()` instead.
|
|
1034
|
+
* const key = scryptSync(password, 'salt', 24);
|
|
1035
|
+
* // The IV is usually passed along with the ciphertext.
|
|
1036
|
+
* const iv = Buffer.alloc(16, 0); // Initialization vector.
|
|
1037
|
+
*
|
|
1038
|
+
* const decipher = createDecipheriv(algorithm, key, iv);
|
|
1039
|
+
*
|
|
1040
|
+
* const input = createReadStream('test.enc');
|
|
1041
|
+
* const output = createWriteStream('test.js');
|
|
1042
|
+
*
|
|
1043
|
+
* input.pipe(decipher).pipe(output);
|
|
1044
|
+
* ```
|
|
1045
|
+
*
|
|
1046
|
+
* Example: Using the `decipher.update()` and `decipher.final()` methods:
|
|
1047
|
+
*
|
|
1048
|
+
* ```js
|
|
1049
|
+
* import { Buffer } from 'buffer';
|
|
1050
|
+
* const {
|
|
1051
|
+
* scryptSync,
|
|
1052
|
+
* createDecipheriv
|
|
1053
|
+
* } = await import('crypto');
|
|
1054
|
+
*
|
|
1055
|
+
* const algorithm = 'aes-192-cbc';
|
|
1056
|
+
* const password = 'Password used to generate key';
|
|
1057
|
+
* // Use the async `crypto.scrypt()` instead.
|
|
1058
|
+
* const key = scryptSync(password, 'salt', 24);
|
|
1059
|
+
* // The IV is usually passed along with the ciphertext.
|
|
1060
|
+
* const iv = Buffer.alloc(16, 0); // Initialization vector.
|
|
1061
|
+
*
|
|
1062
|
+
* const decipher = createDecipheriv(algorithm, key, iv);
|
|
1063
|
+
*
|
|
1064
|
+
* // Encrypted using same algorithm, key and iv.
|
|
1065
|
+
* const encrypted =
|
|
1066
|
+
* 'e5f79c5915c02171eec6b212d5520d44480993d7d622a7c4c2da32f6efda0ffa';
|
|
1067
|
+
* let decrypted = decipher.update(encrypted, 'hex', 'utf8');
|
|
1068
|
+
* decrypted += decipher.final('utf8');
|
|
1069
|
+
* console.log(decrypted);
|
|
1070
|
+
* // Prints: some clear text data
|
|
1071
|
+
* ```
|
|
1072
|
+
* @since v0.1.94
|
|
1073
|
+
*/
|
|
349
1074
|
class Decipher extends stream.Transform {
|
|
350
1075
|
private constructor();
|
|
1076
|
+
/**
|
|
1077
|
+
* Updates the decipher with `data`. If the `inputEncoding` argument is given,
|
|
1078
|
+
* 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
|
|
1079
|
+
* ignored.
|
|
1080
|
+
*
|
|
1081
|
+
* The `outputEncoding` specifies the output format of the enciphered
|
|
1082
|
+
* data. If the `outputEncoding`is specified, a string using the specified encoding is returned. If no`outputEncoding` is provided, a `Buffer` is returned.
|
|
1083
|
+
*
|
|
1084
|
+
* 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
|
|
1085
|
+
* being thrown.
|
|
1086
|
+
* @since v0.1.94
|
|
1087
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
1088
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
1089
|
+
*/
|
|
351
1090
|
update(data: NodeJS.ArrayBufferView): Buffer;
|
|
352
|
-
update(data: string,
|
|
353
|
-
update(data: NodeJS.ArrayBufferView,
|
|
354
|
-
update(data: string,
|
|
1091
|
+
update(data: string, inputEncoding: Encoding): Buffer;
|
|
1092
|
+
update(data: NodeJS.ArrayBufferView, inputEncoding: undefined, outputEncoding: Encoding): string;
|
|
1093
|
+
update(data: string, inputEncoding: Encoding | undefined, outputEncoding: Encoding): string;
|
|
1094
|
+
/**
|
|
1095
|
+
* Once the `decipher.final()` method has been called, the `Decipher` object can
|
|
1096
|
+
* no longer be used to decrypt data. Attempts to call `decipher.final()` more
|
|
1097
|
+
* than once will result in an error being thrown.
|
|
1098
|
+
* @since v0.1.94
|
|
1099
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
1100
|
+
* @return Any remaining deciphered contents. If `outputEncoding` is specified, a string is returned. If an `outputEncoding` is not provided, a {@link Buffer} is returned.
|
|
1101
|
+
*/
|
|
355
1102
|
final(): Buffer;
|
|
356
|
-
final(
|
|
1103
|
+
final(outputEncoding: BufferEncoding): string;
|
|
1104
|
+
/**
|
|
1105
|
+
* 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
|
|
1106
|
+
* removing padding.
|
|
1107
|
+
*
|
|
1108
|
+
* Turning auto padding off will only work if the input data's length is a
|
|
1109
|
+
* multiple of the ciphers block size.
|
|
1110
|
+
*
|
|
1111
|
+
* The `decipher.setAutoPadding()` method must be called before `decipher.final()`.
|
|
1112
|
+
* @since v0.7.1
|
|
1113
|
+
* @param [autoPadding=true]
|
|
1114
|
+
* @return for method chaining.
|
|
1115
|
+
*/
|
|
357
1116
|
setAutoPadding(auto_padding?: boolean): this;
|
|
358
|
-
// setAuthTag(tag: NodeJS.ArrayBufferView): this;
|
|
359
|
-
// setAAD(buffer: NodeJS.ArrayBufferView): this;
|
|
360
1117
|
}
|
|
361
1118
|
interface DecipherCCM extends Decipher {
|
|
362
1119
|
setAuthTag(buffer: NodeJS.ArrayBufferView): this;
|
|
363
|
-
setAAD(
|
|
1120
|
+
setAAD(
|
|
1121
|
+
buffer: NodeJS.ArrayBufferView,
|
|
1122
|
+
options: {
|
|
1123
|
+
plaintextLength: number;
|
|
1124
|
+
}
|
|
1125
|
+
): this;
|
|
364
1126
|
}
|
|
365
1127
|
interface DecipherGCM extends Decipher {
|
|
366
1128
|
setAuthTag(buffer: NodeJS.ArrayBufferView): this;
|
|
367
|
-
setAAD(
|
|
1129
|
+
setAAD(
|
|
1130
|
+
buffer: NodeJS.ArrayBufferView,
|
|
1131
|
+
options?: {
|
|
1132
|
+
plaintextLength: number;
|
|
1133
|
+
}
|
|
1134
|
+
): this;
|
|
368
1135
|
}
|
|
369
|
-
|
|
370
1136
|
interface PrivateKeyInput {
|
|
371
1137
|
key: string | Buffer;
|
|
372
1138
|
format?: KeyFormat | undefined;
|
|
373
1139
|
type?: 'pkcs1' | 'pkcs8' | 'sec1' | undefined;
|
|
374
1140
|
passphrase?: string | Buffer | undefined;
|
|
375
1141
|
}
|
|
376
|
-
|
|
377
1142
|
interface PublicKeyInput {
|
|
378
1143
|
key: string | Buffer;
|
|
379
1144
|
format?: KeyFormat | undefined;
|
|
380
1145
|
type?: 'pkcs1' | 'spki' | undefined;
|
|
381
1146
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
1147
|
+
/**
|
|
1148
|
+
* Asynchronously generates a new random secret key of the given `length`. The`type` will determine which validations will be performed on the `length`.
|
|
1149
|
+
*
|
|
1150
|
+
* ```js
|
|
1151
|
+
* const {
|
|
1152
|
+
* generateKey
|
|
1153
|
+
* } = await import('crypto');
|
|
1154
|
+
*
|
|
1155
|
+
* generateKey('hmac', { length: 64 }, (err, key) => {
|
|
1156
|
+
* if (err) throw err;
|
|
1157
|
+
* console.log(key.export().toString('hex')); // 46e..........620
|
|
1158
|
+
* });
|
|
1159
|
+
* ```
|
|
1160
|
+
* @since v15.0.0
|
|
1161
|
+
* @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
|
|
1162
|
+
*/
|
|
1163
|
+
function generateKey(
|
|
1164
|
+
type: 'hmac' | 'aes',
|
|
1165
|
+
options: {
|
|
1166
|
+
length: number;
|
|
1167
|
+
},
|
|
1168
|
+
callback: (err: Error | null, key: KeyObject) => void
|
|
1169
|
+
): void;
|
|
1170
|
+
/**
|
|
1171
|
+
* Synchronously generates a new random secret key of the given `length`. The`type` will determine which validations will be performed on the `length`.
|
|
1172
|
+
*
|
|
1173
|
+
* ```js
|
|
1174
|
+
* const {
|
|
1175
|
+
* generateKeySync
|
|
1176
|
+
* } = await import('crypto');
|
|
1177
|
+
*
|
|
1178
|
+
* const key = generateKeySync('hmac', { length: 64 });
|
|
1179
|
+
* console.log(key.export().toString('hex')); // e89..........41e
|
|
1180
|
+
* ```
|
|
1181
|
+
* @since v15.0.0
|
|
1182
|
+
* @param type The intended use of the generated secret key. Currently accepted values are `'hmac'` and `'aes'`.
|
|
1183
|
+
*/
|
|
1184
|
+
function generateKeySync(
|
|
1185
|
+
type: 'hmac' | 'aes',
|
|
1186
|
+
options: {
|
|
1187
|
+
length: number;
|
|
1188
|
+
}
|
|
1189
|
+
): KeyObject;
|
|
385
1190
|
interface JsonWebKeyInput {
|
|
386
1191
|
key: JsonWebKey;
|
|
387
1192
|
format: 'jwk';
|
|
388
1193
|
}
|
|
389
|
-
|
|
1194
|
+
/**
|
|
1195
|
+
* Creates and returns a new key object containing a private key. If `key` is a
|
|
1196
|
+
* string or `Buffer`, `format` is assumed to be `'pem'`; otherwise, `key`must be an object with the properties described above.
|
|
1197
|
+
*
|
|
1198
|
+
* If the private key is encrypted, a `passphrase` must be specified. The length
|
|
1199
|
+
* of the passphrase is limited to 1024 bytes.
|
|
1200
|
+
* @since v11.6.0
|
|
1201
|
+
*/
|
|
390
1202
|
function createPrivateKey(key: PrivateKeyInput | string | Buffer | JsonWebKeyInput): KeyObject;
|
|
1203
|
+
/**
|
|
1204
|
+
* Creates and returns a new key object containing a public key. If `key` is a
|
|
1205
|
+
* 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;
|
|
1206
|
+
* otherwise, `key` must be an object with the properties described above.
|
|
1207
|
+
*
|
|
1208
|
+
* If the format is `'pem'`, the `'key'` may also be an X.509 certificate.
|
|
1209
|
+
*
|
|
1210
|
+
* Because public keys can be derived from private keys, a private key may be
|
|
1211
|
+
* 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
|
|
1212
|
+
* returned `KeyObject` will be `'public'` and that the private key cannot be
|
|
1213
|
+
* extracted from the returned `KeyObject`. Similarly, if a `KeyObject` with type`'private'` is given, a new `KeyObject` with type `'public'` will be returned
|
|
1214
|
+
* and it will be impossible to extract the private key from the returned object.
|
|
1215
|
+
* @since v11.6.0
|
|
1216
|
+
*/
|
|
391
1217
|
function createPublicKey(key: PublicKeyInput | string | Buffer | KeyObject | JsonWebKeyInput): KeyObject;
|
|
1218
|
+
/**
|
|
1219
|
+
* Creates and returns a new key object containing a secret key for symmetric
|
|
1220
|
+
* encryption or `Hmac`.
|
|
1221
|
+
* @since v11.6.0
|
|
1222
|
+
* @param encoding The string encoding when `key` is a string.
|
|
1223
|
+
*/
|
|
392
1224
|
function createSecretKey(key: NodeJS.ArrayBufferView): KeyObject;
|
|
393
|
-
|
|
1225
|
+
function createSecretKey(key: string, encoding: BufferEncoding): KeyObject;
|
|
1226
|
+
/**
|
|
1227
|
+
* Creates and returns a `Sign` object that uses the given `algorithm`. Use {@link getHashes} to obtain the names of the available digest algorithms.
|
|
1228
|
+
* Optional `options` argument controls the `stream.Writable` behavior.
|
|
1229
|
+
*
|
|
1230
|
+
* In some cases, a `Sign` instance can be created using the name of a signature
|
|
1231
|
+
* algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
|
|
1232
|
+
* the corresponding digest algorithm. This does not work for all signature
|
|
1233
|
+
* algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
|
|
1234
|
+
* algorithm names.
|
|
1235
|
+
* @since v0.1.92
|
|
1236
|
+
* @param options `stream.Writable` options
|
|
1237
|
+
*/
|
|
394
1238
|
function createSign(algorithm: string, options?: stream.WritableOptions): Sign;
|
|
395
|
-
|
|
396
1239
|
type DSAEncoding = 'der' | 'ieee-p1363';
|
|
397
|
-
|
|
398
1240
|
interface SigningOptions {
|
|
399
1241
|
/**
|
|
400
1242
|
* @See crypto.constants.RSA_PKCS1_PADDING
|
|
@@ -403,132 +1245,670 @@ declare module 'crypto' {
|
|
|
403
1245
|
saltLength?: number | undefined;
|
|
404
1246
|
dsaEncoding?: DSAEncoding | undefined;
|
|
405
1247
|
}
|
|
406
|
-
|
|
407
|
-
interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions { }
|
|
1248
|
+
interface SignPrivateKeyInput extends PrivateKeyInput, SigningOptions {}
|
|
408
1249
|
interface SignKeyObjectInput extends SigningOptions {
|
|
409
1250
|
key: KeyObject;
|
|
410
1251
|
}
|
|
411
|
-
interface VerifyPublicKeyInput extends PublicKeyInput, SigningOptions {
|
|
1252
|
+
interface VerifyPublicKeyInput extends PublicKeyInput, SigningOptions {}
|
|
412
1253
|
interface VerifyKeyObjectInput extends SigningOptions {
|
|
413
1254
|
key: KeyObject;
|
|
414
1255
|
}
|
|
415
|
-
|
|
416
1256
|
type KeyLike = string | Buffer | KeyObject;
|
|
417
|
-
|
|
1257
|
+
/**
|
|
1258
|
+
* The `Sign` class is a utility for generating signatures. It can be used in one
|
|
1259
|
+
* of two ways:
|
|
1260
|
+
*
|
|
1261
|
+
* * 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
|
|
1262
|
+
* * Using the `sign.update()` and `sign.sign()` methods to produce the
|
|
1263
|
+
* signature.
|
|
1264
|
+
*
|
|
1265
|
+
* The {@link createSign} method is used to create `Sign` instances. The
|
|
1266
|
+
* argument is the string name of the hash function to use. `Sign` objects are not
|
|
1267
|
+
* to be created directly using the `new` keyword.
|
|
1268
|
+
*
|
|
1269
|
+
* Example: Using `Sign` and `Verify` objects as streams:
|
|
1270
|
+
*
|
|
1271
|
+
* ```js
|
|
1272
|
+
* const {
|
|
1273
|
+
* generateKeyPairSync,
|
|
1274
|
+
* createSign,
|
|
1275
|
+
* createVerify
|
|
1276
|
+
* } = await import('crypto');
|
|
1277
|
+
*
|
|
1278
|
+
* const { privateKey, publicKey } = generateKeyPairSync('ec', {
|
|
1279
|
+
* namedCurve: 'sect239k1'
|
|
1280
|
+
* });
|
|
1281
|
+
*
|
|
1282
|
+
* const sign = createSign('SHA256');
|
|
1283
|
+
* sign.write('some data to sign');
|
|
1284
|
+
* sign.end();
|
|
1285
|
+
* const signature = sign.sign(privateKey, 'hex');
|
|
1286
|
+
*
|
|
1287
|
+
* const verify = createVerify('SHA256');
|
|
1288
|
+
* verify.write('some data to sign');
|
|
1289
|
+
* verify.end();
|
|
1290
|
+
* console.log(verify.verify(publicKey, signature, 'hex'));
|
|
1291
|
+
* // Prints: true
|
|
1292
|
+
* ```
|
|
1293
|
+
*
|
|
1294
|
+
* Example: Using the `sign.update()` and `verify.update()` methods:
|
|
1295
|
+
*
|
|
1296
|
+
* ```js
|
|
1297
|
+
* const {
|
|
1298
|
+
* generateKeyPairSync,
|
|
1299
|
+
* createSign,
|
|
1300
|
+
* createVerify
|
|
1301
|
+
* } = await import('crypto');
|
|
1302
|
+
*
|
|
1303
|
+
* const { privateKey, publicKey } = generateKeyPairSync('rsa', {
|
|
1304
|
+
* modulusLength: 2048,
|
|
1305
|
+
* });
|
|
1306
|
+
*
|
|
1307
|
+
* const sign = createSign('SHA256');
|
|
1308
|
+
* sign.update('some data to sign');
|
|
1309
|
+
* sign.end();
|
|
1310
|
+
* const signature = sign.sign(privateKey);
|
|
1311
|
+
*
|
|
1312
|
+
* const verify = createVerify('SHA256');
|
|
1313
|
+
* verify.update('some data to sign');
|
|
1314
|
+
* verify.end();
|
|
1315
|
+
* console.log(verify.verify(publicKey, signature));
|
|
1316
|
+
* // Prints: true
|
|
1317
|
+
* ```
|
|
1318
|
+
* @since v0.1.92
|
|
1319
|
+
*/
|
|
418
1320
|
class Sign extends stream.Writable {
|
|
419
1321
|
private constructor();
|
|
420
|
-
|
|
1322
|
+
/**
|
|
1323
|
+
* Updates the `Sign` content with the given `data`, the encoding of which
|
|
1324
|
+
* is given in `inputEncoding`.
|
|
1325
|
+
* If `encoding` is not provided, and the `data` is a string, an
|
|
1326
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
1327
|
+
*
|
|
1328
|
+
* This can be called many times with new data as it is streamed.
|
|
1329
|
+
* @since v0.1.92
|
|
1330
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
1331
|
+
*/
|
|
421
1332
|
update(data: BinaryLike): this;
|
|
422
|
-
update(data: string,
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
1333
|
+
update(data: string, inputEncoding: Encoding): this;
|
|
1334
|
+
/**
|
|
1335
|
+
* Calculates the signature on all the data passed through using either `sign.update()` or `sign.write()`.
|
|
1336
|
+
*
|
|
1337
|
+
* If `privateKey` is not a `KeyObject`, this function behaves as if`privateKey` had been passed to {@link createPrivateKey}. If it is an
|
|
1338
|
+
* object, the following additional properties can be passed:
|
|
1339
|
+
*
|
|
1340
|
+
* If `outputEncoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
1341
|
+
*
|
|
1342
|
+
* The `Sign` object can not be again used after `sign.sign()` method has been
|
|
1343
|
+
* called. Multiple calls to `sign.sign()` will result in an error being thrown.
|
|
1344
|
+
* @since v0.1.92
|
|
1345
|
+
*/
|
|
1346
|
+
sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput): Buffer;
|
|
1347
|
+
sign(privateKey: KeyLike | SignKeyObjectInput | SignPrivateKeyInput, outputFormat: BinaryToTextEncoding): string;
|
|
428
1348
|
}
|
|
429
|
-
|
|
1349
|
+
/**
|
|
1350
|
+
* Creates and returns a `Verify` object that uses the given algorithm.
|
|
1351
|
+
* Use {@link getHashes} to obtain an array of names of the available
|
|
1352
|
+
* signing algorithms. Optional `options` argument controls the`stream.Writable` behavior.
|
|
1353
|
+
*
|
|
1354
|
+
* In some cases, a `Verify` instance can be created using the name of a signature
|
|
1355
|
+
* algorithm, such as `'RSA-SHA256'`, instead of a digest algorithm. This will use
|
|
1356
|
+
* the corresponding digest algorithm. This does not work for all signature
|
|
1357
|
+
* algorithms, such as `'ecdsa-with-SHA256'`, so it is best to always use digest
|
|
1358
|
+
* algorithm names.
|
|
1359
|
+
* @since v0.1.92
|
|
1360
|
+
* @param options `stream.Writable` options
|
|
1361
|
+
*/
|
|
430
1362
|
function createVerify(algorithm: string, options?: stream.WritableOptions): Verify;
|
|
1363
|
+
/**
|
|
1364
|
+
* The `Verify` class is a utility for verifying signatures. It can be used in one
|
|
1365
|
+
* of two ways:
|
|
1366
|
+
*
|
|
1367
|
+
* * As a writable `stream` where written data is used to validate against the
|
|
1368
|
+
* supplied signature, or
|
|
1369
|
+
* * Using the `verify.update()` and `verify.verify()` methods to verify
|
|
1370
|
+
* the signature.
|
|
1371
|
+
*
|
|
1372
|
+
* The {@link createVerify} method is used to create `Verify` instances.`Verify` objects are not to be created directly using the `new` keyword.
|
|
1373
|
+
*
|
|
1374
|
+
* See `Sign` for examples.
|
|
1375
|
+
* @since v0.1.92
|
|
1376
|
+
*/
|
|
431
1377
|
class Verify extends stream.Writable {
|
|
432
1378
|
private constructor();
|
|
433
|
-
|
|
1379
|
+
/**
|
|
1380
|
+
* Updates the `Verify` content with the given `data`, the encoding of which
|
|
1381
|
+
* is given in `inputEncoding`.
|
|
1382
|
+
* If `inputEncoding` is not provided, and the `data` is a string, an
|
|
1383
|
+
* encoding of `'utf8'` is enforced. If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
|
|
1384
|
+
*
|
|
1385
|
+
* This can be called many times with new data as it is streamed.
|
|
1386
|
+
* @since v0.1.92
|
|
1387
|
+
* @param inputEncoding The `encoding` of the `data` string.
|
|
1388
|
+
*/
|
|
434
1389
|
update(data: BinaryLike): Verify;
|
|
435
|
-
update(data: string,
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
1390
|
+
update(data: string, inputEncoding: Encoding): Verify;
|
|
1391
|
+
/**
|
|
1392
|
+
* Verifies the provided data using the given `object` and `signature`.
|
|
1393
|
+
*
|
|
1394
|
+
* If `object` is not a `KeyObject`, this function behaves as if`object` had been passed to {@link createPublicKey}. If it is an
|
|
1395
|
+
* object, the following additional properties can be passed:
|
|
1396
|
+
*
|
|
1397
|
+
* The `signature` argument is the previously calculated signature for the data, in
|
|
1398
|
+
* the `signatureEncoding`.
|
|
1399
|
+
* If a `signatureEncoding` is specified, the `signature` is expected to be a
|
|
1400
|
+
* string; otherwise `signature` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
|
|
1401
|
+
*
|
|
1402
|
+
* The `verify` object can not be used again after `verify.verify()` has been
|
|
1403
|
+
* called. Multiple calls to `verify.verify()` will result in an error being
|
|
1404
|
+
* thrown.
|
|
1405
|
+
*
|
|
1406
|
+
* Because public keys can be derived from private keys, a private key may
|
|
1407
|
+
* be passed instead of a public key.
|
|
1408
|
+
* @since v0.1.92
|
|
1409
|
+
*/
|
|
1410
|
+
verify(object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput, signature: NodeJS.ArrayBufferView): boolean;
|
|
1411
|
+
verify(object: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput, signature: string, signature_format?: BinaryToTextEncoding): boolean;
|
|
447
1412
|
}
|
|
448
|
-
|
|
1413
|
+
/**
|
|
1414
|
+
* Creates a `DiffieHellman` key exchange object using the supplied `prime` and an
|
|
1415
|
+
* optional specific `generator`.
|
|
1416
|
+
*
|
|
1417
|
+
* The `generator` argument can be a number, string, or `Buffer`. If`generator` is not specified, the value `2` is used.
|
|
1418
|
+
*
|
|
1419
|
+
* If `primeEncoding` is specified, `prime` is expected to be a string; otherwise
|
|
1420
|
+
* a `Buffer`, `TypedArray`, or `DataView` is expected.
|
|
1421
|
+
*
|
|
1422
|
+
* If `generatorEncoding` is specified, `generator` is expected to be a string;
|
|
1423
|
+
* otherwise a number, `Buffer`, `TypedArray`, or `DataView` is expected.
|
|
1424
|
+
* @since v0.11.12
|
|
1425
|
+
* @param primeEncoding The `encoding` of the `prime` string.
|
|
1426
|
+
* @param [generator=2]
|
|
1427
|
+
* @param generatorEncoding The `encoding` of the `generator` string.
|
|
1428
|
+
*/
|
|
1429
|
+
function createDiffieHellman(primeLength: number, generator?: number | NodeJS.ArrayBufferView): DiffieHellman;
|
|
449
1430
|
function createDiffieHellman(prime: NodeJS.ArrayBufferView): DiffieHellman;
|
|
450
|
-
function createDiffieHellman(prime: string,
|
|
451
|
-
function createDiffieHellman(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
1431
|
+
function createDiffieHellman(prime: string, primeEncoding: BinaryToTextEncoding): DiffieHellman;
|
|
1432
|
+
function createDiffieHellman(prime: string, primeEncoding: BinaryToTextEncoding, generator: number | NodeJS.ArrayBufferView): DiffieHellman;
|
|
1433
|
+
function createDiffieHellman(prime: string, primeEncoding: BinaryToTextEncoding, generator: string, generatorEncoding: BinaryToTextEncoding): DiffieHellman;
|
|
1434
|
+
/**
|
|
1435
|
+
* The `DiffieHellman` class is a utility for creating Diffie-Hellman key
|
|
1436
|
+
* exchanges.
|
|
1437
|
+
*
|
|
1438
|
+
* Instances of the `DiffieHellman` class can be created using the {@link createDiffieHellman} function.
|
|
1439
|
+
*
|
|
1440
|
+
* ```js
|
|
1441
|
+
* import assert from 'assert';
|
|
1442
|
+
*
|
|
1443
|
+
* const {
|
|
1444
|
+
* createDiffieHellman
|
|
1445
|
+
* } = await import('crypto');
|
|
1446
|
+
*
|
|
1447
|
+
* // Generate Alice's keys...
|
|
1448
|
+
* const alice = createDiffieHellman(2048);
|
|
1449
|
+
* const aliceKey = alice.generateKeys();
|
|
1450
|
+
*
|
|
1451
|
+
* // Generate Bob's keys...
|
|
1452
|
+
* const bob = createDiffieHellman(alice.getPrime(), alice.getGenerator());
|
|
1453
|
+
* const bobKey = bob.generateKeys();
|
|
1454
|
+
*
|
|
1455
|
+
* // Exchange and generate the secret...
|
|
1456
|
+
* const aliceSecret = alice.computeSecret(bobKey);
|
|
1457
|
+
* const bobSecret = bob.computeSecret(aliceKey);
|
|
1458
|
+
*
|
|
1459
|
+
* // OK
|
|
1460
|
+
* assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
|
|
1461
|
+
* ```
|
|
1462
|
+
* @since v0.5.0
|
|
1463
|
+
*/
|
|
462
1464
|
class DiffieHellman {
|
|
463
1465
|
private constructor();
|
|
1466
|
+
/**
|
|
1467
|
+
* Generates private and public Diffie-Hellman key values, and returns
|
|
1468
|
+
* the public key in the specified `encoding`. This key should be
|
|
1469
|
+
* transferred to the other party.
|
|
1470
|
+
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
1471
|
+
* @since v0.5.0
|
|
1472
|
+
* @param encoding The `encoding` of the return value.
|
|
1473
|
+
*/
|
|
464
1474
|
generateKeys(): Buffer;
|
|
465
1475
|
generateKeys(encoding: BinaryToTextEncoding): string;
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
1476
|
+
/**
|
|
1477
|
+
* Computes the shared secret using `otherPublicKey` as the other
|
|
1478
|
+
* party's public key and returns the computed shared secret. The supplied
|
|
1479
|
+
* key is interpreted using the specified `inputEncoding`, and secret is
|
|
1480
|
+
* encoded using specified `outputEncoding`.
|
|
1481
|
+
* If the `inputEncoding` is not
|
|
1482
|
+
* provided, `otherPublicKey` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
|
|
1483
|
+
*
|
|
1484
|
+
* If `outputEncoding` is given a string is returned; otherwise, a `Buffer` is returned.
|
|
1485
|
+
* @since v0.5.0
|
|
1486
|
+
* @param inputEncoding The `encoding` of an `otherPublicKey` string.
|
|
1487
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
1488
|
+
*/
|
|
1489
|
+
computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer;
|
|
1490
|
+
computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer;
|
|
1491
|
+
computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string;
|
|
1492
|
+
computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding: BinaryToTextEncoding): string;
|
|
1493
|
+
/**
|
|
1494
|
+
* Returns the Diffie-Hellman prime in the specified `encoding`.
|
|
1495
|
+
* If `encoding` is provided a string is
|
|
1496
|
+
* returned; otherwise a `Buffer` is returned.
|
|
1497
|
+
* @since v0.5.0
|
|
1498
|
+
* @param encoding The `encoding` of the return value.
|
|
1499
|
+
*/
|
|
474
1500
|
getPrime(): Buffer;
|
|
475
1501
|
getPrime(encoding: BinaryToTextEncoding): string;
|
|
1502
|
+
/**
|
|
1503
|
+
* Returns the Diffie-Hellman generator in the specified `encoding`.
|
|
1504
|
+
* If `encoding` is provided a string is
|
|
1505
|
+
* returned; otherwise a `Buffer` is returned.
|
|
1506
|
+
* @since v0.5.0
|
|
1507
|
+
* @param encoding The `encoding` of the return value.
|
|
1508
|
+
*/
|
|
476
1509
|
getGenerator(): Buffer;
|
|
477
1510
|
getGenerator(encoding: BinaryToTextEncoding): string;
|
|
1511
|
+
/**
|
|
1512
|
+
* Returns the Diffie-Hellman public key in the specified `encoding`.
|
|
1513
|
+
* If `encoding` is provided a
|
|
1514
|
+
* string is returned; otherwise a `Buffer` is returned.
|
|
1515
|
+
* @since v0.5.0
|
|
1516
|
+
* @param encoding The `encoding` of the return value.
|
|
1517
|
+
*/
|
|
478
1518
|
getPublicKey(): Buffer;
|
|
479
1519
|
getPublicKey(encoding: BinaryToTextEncoding): string;
|
|
1520
|
+
/**
|
|
1521
|
+
* Returns the Diffie-Hellman private key in the specified `encoding`.
|
|
1522
|
+
* If `encoding` is provided a
|
|
1523
|
+
* string is returned; otherwise a `Buffer` is returned.
|
|
1524
|
+
* @since v0.5.0
|
|
1525
|
+
* @param encoding The `encoding` of the return value.
|
|
1526
|
+
*/
|
|
480
1527
|
getPrivateKey(): Buffer;
|
|
481
1528
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
1529
|
+
/**
|
|
1530
|
+
* Sets the Diffie-Hellman public key. If the `encoding` argument is provided,`publicKey` is expected
|
|
1531
|
+
* to be a string. If no `encoding` is provided, `publicKey` is expected
|
|
1532
|
+
* to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1533
|
+
* @since v0.5.0
|
|
1534
|
+
* @param encoding The `encoding` of the `publicKey` string.
|
|
1535
|
+
*/
|
|
1536
|
+
setPublicKey(publicKey: NodeJS.ArrayBufferView): void;
|
|
1537
|
+
setPublicKey(publicKey: string, encoding: BufferEncoding): void;
|
|
1538
|
+
/**
|
|
1539
|
+
* Sets the Diffie-Hellman private key. If the `encoding` argument is provided,`privateKey` is expected
|
|
1540
|
+
* to be a string. If no `encoding` is provided, `privateKey` is expected
|
|
1541
|
+
* to be a `Buffer`, `TypedArray`, or `DataView`.
|
|
1542
|
+
* @since v0.5.0
|
|
1543
|
+
* @param encoding The `encoding` of the `privateKey` string.
|
|
1544
|
+
*/
|
|
1545
|
+
setPrivateKey(privateKey: NodeJS.ArrayBufferView): void;
|
|
1546
|
+
setPrivateKey(privateKey: string, encoding: BufferEncoding): void;
|
|
1547
|
+
/**
|
|
1548
|
+
* A bit field containing any warnings and/or errors resulting from a check
|
|
1549
|
+
* performed during initialization of the `DiffieHellman` object.
|
|
1550
|
+
*
|
|
1551
|
+
* The following values are valid for this property (as defined in `constants`module):
|
|
1552
|
+
*
|
|
1553
|
+
* * `DH_CHECK_P_NOT_SAFE_PRIME`
|
|
1554
|
+
* * `DH_CHECK_P_NOT_PRIME`
|
|
1555
|
+
* * `DH_UNABLE_TO_CHECK_GENERATOR`
|
|
1556
|
+
* * `DH_NOT_SUITABLE_GENERATOR`
|
|
1557
|
+
* @since v0.11.12
|
|
1558
|
+
*/
|
|
486
1559
|
verifyError: number;
|
|
487
1560
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
1561
|
+
/**
|
|
1562
|
+
* Creates a predefined `DiffieHellmanGroup` key exchange object. The
|
|
1563
|
+
* supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in [RFC 2412](https://www.rfc-editor.org/rfc/rfc2412.txt), but see `Caveats`) and `'modp14'`, `'modp15'`,`'modp16'`, `'modp17'`,
|
|
1564
|
+
* `'modp18'` (defined in [RFC 3526](https://www.rfc-editor.org/rfc/rfc3526.txt)). The
|
|
1565
|
+
* returned object mimics the interface of objects created by {@link createDiffieHellman}, but will not allow changing
|
|
1566
|
+
* the keys (with `diffieHellman.setPublicKey()`, for example). The
|
|
1567
|
+
* advantage of using this method is that the parties do not have to
|
|
1568
|
+
* generate nor exchange a group modulus beforehand, saving both processor
|
|
1569
|
+
* and communication time.
|
|
1570
|
+
*
|
|
1571
|
+
* Example (obtaining a shared secret):
|
|
1572
|
+
*
|
|
1573
|
+
* ```js
|
|
1574
|
+
* const {
|
|
1575
|
+
* getDiffieHellman
|
|
1576
|
+
* } = await import('crypto');
|
|
1577
|
+
* const alice = getDiffieHellman('modp14');
|
|
1578
|
+
* const bob = getDiffieHellman('modp14');
|
|
1579
|
+
*
|
|
1580
|
+
* alice.generateKeys();
|
|
1581
|
+
* bob.generateKeys();
|
|
1582
|
+
*
|
|
1583
|
+
* const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
|
|
1584
|
+
* const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
|
|
1585
|
+
*
|
|
1586
|
+
* // aliceSecret and bobSecret should be the same
|
|
1587
|
+
* console.log(aliceSecret === bobSecret);
|
|
1588
|
+
* ```
|
|
1589
|
+
* @since v0.7.5
|
|
1590
|
+
*/
|
|
1591
|
+
function getDiffieHellman(groupName: string): DiffieHellman;
|
|
1592
|
+
/**
|
|
1593
|
+
* Provides an asynchronous Password-Based Key Derivation Function 2 (PBKDF2)
|
|
1594
|
+
* implementation. A selected HMAC digest algorithm specified by `digest` is
|
|
1595
|
+
* applied to derive a key of the requested byte length (`keylen`) from the`password`, `salt` and `iterations`.
|
|
1596
|
+
*
|
|
1597
|
+
* The supplied `callback` function is called with two arguments: `err` and`derivedKey`. If an error occurs while deriving the key, `err` will be set;
|
|
1598
|
+
* otherwise `err` will be `null`. By default, the successfully generated`derivedKey` will be passed to the callback as a `Buffer`. An error will be
|
|
1599
|
+
* thrown if any of the input arguments specify invalid values or types.
|
|
1600
|
+
*
|
|
1601
|
+
* If `digest` is `null`, `'sha1'` will be used. This behavior is deprecated,
|
|
1602
|
+
* please specify a `digest` explicitly.
|
|
1603
|
+
*
|
|
1604
|
+
* The `iterations` argument must be a number set as high as possible. The
|
|
1605
|
+
* higher the number of iterations, the more secure the derived key will be,
|
|
1606
|
+
* but will take a longer amount of time to complete.
|
|
1607
|
+
*
|
|
1608
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
1609
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
1610
|
+
*
|
|
1611
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1612
|
+
*
|
|
1613
|
+
* ```js
|
|
1614
|
+
* const {
|
|
1615
|
+
* pbkdf2
|
|
1616
|
+
* } = await import('crypto');
|
|
1617
|
+
*
|
|
1618
|
+
* pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
|
|
1619
|
+
* if (err) throw err;
|
|
1620
|
+
* console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
|
|
1621
|
+
* });
|
|
1622
|
+
* ```
|
|
1623
|
+
*
|
|
1624
|
+
* The `crypto.DEFAULT_ENCODING` property can be used to change the way the`derivedKey` is passed to the callback. This property, however, has been
|
|
1625
|
+
* deprecated and use should be avoided.
|
|
1626
|
+
*
|
|
1627
|
+
* ```js
|
|
1628
|
+
* import crypto from 'crypto';
|
|
1629
|
+
* crypto.DEFAULT_ENCODING = 'hex';
|
|
1630
|
+
* crypto.pbkdf2('secret', 'salt', 100000, 512, 'sha512', (err, derivedKey) => {
|
|
1631
|
+
* if (err) throw err;
|
|
1632
|
+
* console.log(derivedKey); // '3745e48...aa39b34'
|
|
1633
|
+
* });
|
|
1634
|
+
* ```
|
|
1635
|
+
*
|
|
1636
|
+
* An array of supported digest functions can be retrieved using {@link getHashes}.
|
|
1637
|
+
*
|
|
1638
|
+
* This API uses libuv's threadpool, which can have surprising and
|
|
1639
|
+
* negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
|
|
1640
|
+
* @since v0.5.5
|
|
1641
|
+
*/
|
|
1642
|
+
function pbkdf2(password: BinaryLike, salt: BinaryLike, iterations: number, keylen: number, digest: string, callback: (err: Error | null, derivedKey: Buffer) => void): void;
|
|
1643
|
+
/**
|
|
1644
|
+
* Provides a synchronous Password-Based Key Derivation Function 2 (PBKDF2)
|
|
1645
|
+
* implementation. A selected HMAC digest algorithm specified by `digest` is
|
|
1646
|
+
* applied to derive a key of the requested byte length (`keylen`) from the`password`, `salt` and `iterations`.
|
|
1647
|
+
*
|
|
1648
|
+
* If an error occurs an `Error` will be thrown, otherwise the derived key will be
|
|
1649
|
+
* returned as a `Buffer`.
|
|
1650
|
+
*
|
|
1651
|
+
* If `digest` is `null`, `'sha1'` will be used. This behavior is deprecated,
|
|
1652
|
+
* please specify a `digest` explicitly.
|
|
1653
|
+
*
|
|
1654
|
+
* The `iterations` argument must be a number set as high as possible. The
|
|
1655
|
+
* higher the number of iterations, the more secure the derived key will be,
|
|
1656
|
+
* but will take a longer amount of time to complete.
|
|
1657
|
+
*
|
|
1658
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
1659
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
1660
|
+
*
|
|
1661
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1662
|
+
*
|
|
1663
|
+
* ```js
|
|
1664
|
+
* const {
|
|
1665
|
+
* pbkdf2Sync
|
|
1666
|
+
* } = await import('crypto');
|
|
1667
|
+
*
|
|
1668
|
+
* const key = pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
|
|
1669
|
+
* console.log(key.toString('hex')); // '3745e48...08d59ae'
|
|
1670
|
+
* ```
|
|
1671
|
+
*
|
|
1672
|
+
* The `crypto.DEFAULT_ENCODING` property may be used to change the way the`derivedKey` is returned. This property, however, is deprecated and use
|
|
1673
|
+
* should be avoided.
|
|
1674
|
+
*
|
|
1675
|
+
* ```js
|
|
1676
|
+
* import crypto from 'crypto';
|
|
1677
|
+
* crypto.DEFAULT_ENCODING = 'hex';
|
|
1678
|
+
* const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 512, 'sha512');
|
|
1679
|
+
* console.log(key); // '3745e48...aa39b34'
|
|
1680
|
+
* ```
|
|
1681
|
+
*
|
|
1682
|
+
* An array of supported digest functions can be retrieved using {@link getHashes}.
|
|
1683
|
+
* @since v0.9.3
|
|
1684
|
+
*/
|
|
1685
|
+
function pbkdf2Sync(password: BinaryLike, salt: BinaryLike, iterations: number, keylen: number, digest: string): Buffer;
|
|
1686
|
+
/**
|
|
1687
|
+
* Generates cryptographically strong pseudorandom data. The `size` argument
|
|
1688
|
+
* is a number indicating the number of bytes to generate.
|
|
1689
|
+
*
|
|
1690
|
+
* If a `callback` function is provided, the bytes are generated asynchronously
|
|
1691
|
+
* and the `callback` function is invoked with two arguments: `err` and `buf`.
|
|
1692
|
+
* If an error occurs, `err` will be an `Error` object; otherwise it is `null`. The`buf` argument is a `Buffer` containing the generated bytes.
|
|
1693
|
+
*
|
|
1694
|
+
* ```js
|
|
1695
|
+
* // Asynchronous
|
|
1696
|
+
* const {
|
|
1697
|
+
* randomBytes
|
|
1698
|
+
* } = await import('crypto');
|
|
1699
|
+
*
|
|
1700
|
+
* randomBytes(256, (err, buf) => {
|
|
1701
|
+
* if (err) throw err;
|
|
1702
|
+
* console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
|
|
1703
|
+
* });
|
|
1704
|
+
* ```
|
|
1705
|
+
*
|
|
1706
|
+
* If the `callback` function is not provided, the random bytes are generated
|
|
1707
|
+
* synchronously and returned as a `Buffer`. An error will be thrown if
|
|
1708
|
+
* there is a problem generating the bytes.
|
|
1709
|
+
*
|
|
1710
|
+
* ```js
|
|
1711
|
+
* // Synchronous
|
|
1712
|
+
* const {
|
|
1713
|
+
* randomBytes
|
|
1714
|
+
* } = await import('crypto');
|
|
1715
|
+
*
|
|
1716
|
+
* const buf = randomBytes(256);
|
|
1717
|
+
* console.log(
|
|
1718
|
+
* `${buf.length} bytes of random data: ${buf.toString('hex')}`);
|
|
1719
|
+
* ```
|
|
1720
|
+
*
|
|
1721
|
+
* The `crypto.randomBytes()` method will not complete until there is
|
|
1722
|
+
* sufficient entropy available.
|
|
1723
|
+
* This should normally never take longer than a few milliseconds. The only time
|
|
1724
|
+
* when generating the random bytes may conceivably block for a longer period of
|
|
1725
|
+
* time is right after boot, when the whole system is still low on entropy.
|
|
1726
|
+
*
|
|
1727
|
+
* This API uses libuv's threadpool, which can have surprising and
|
|
1728
|
+
* negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
|
|
1729
|
+
*
|
|
1730
|
+
* The asynchronous version of `crypto.randomBytes()` is carried out in a single
|
|
1731
|
+
* threadpool request. To minimize threadpool task length variation, partition
|
|
1732
|
+
* large `randomBytes` requests when doing so as part of fulfilling a client
|
|
1733
|
+
* request.
|
|
1734
|
+
* @since v0.5.8
|
|
1735
|
+
* @param size The number of bytes to generate. The `size` must not be larger than `2**31 - 1`.
|
|
1736
|
+
* @return if the `callback` function is not provided.
|
|
1737
|
+
*/
|
|
505
1738
|
function randomBytes(size: number): Buffer;
|
|
506
1739
|
function randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
|
|
507
1740
|
function pseudoRandomBytes(size: number): Buffer;
|
|
508
1741
|
function pseudoRandomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void;
|
|
509
|
-
|
|
1742
|
+
/**
|
|
1743
|
+
* Return a random integer `n` such that `min <= n < max`. This
|
|
1744
|
+
* implementation avoids [modulo bias](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Modulo_bias).
|
|
1745
|
+
*
|
|
1746
|
+
* The range (`max - min`) must be less than 248. `min` and `max` must
|
|
1747
|
+
* be [safe integers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).
|
|
1748
|
+
*
|
|
1749
|
+
* If the `callback` function is not provided, the random integer is
|
|
1750
|
+
* generated synchronously.
|
|
1751
|
+
*
|
|
1752
|
+
* ```js
|
|
1753
|
+
* // Asynchronous
|
|
1754
|
+
* const {
|
|
1755
|
+
* randomInt
|
|
1756
|
+
* } = await import('crypto');
|
|
1757
|
+
*
|
|
1758
|
+
* randomInt(3, (err, n) => {
|
|
1759
|
+
* if (err) throw err;
|
|
1760
|
+
* console.log(`Random number chosen from (0, 1, 2): ${n}`);
|
|
1761
|
+
* });
|
|
1762
|
+
* ```
|
|
1763
|
+
*
|
|
1764
|
+
* ```js
|
|
1765
|
+
* // Synchronous
|
|
1766
|
+
* const {
|
|
1767
|
+
* randomInt
|
|
1768
|
+
* } = await import('crypto');
|
|
1769
|
+
*
|
|
1770
|
+
* const n = randomInt(3);
|
|
1771
|
+
* console.log(`Random number chosen from (0, 1, 2): ${n}`);
|
|
1772
|
+
* ```
|
|
1773
|
+
*
|
|
1774
|
+
* ```js
|
|
1775
|
+
* // With `min` argument
|
|
1776
|
+
* const {
|
|
1777
|
+
* randomInt
|
|
1778
|
+
* } = await import('crypto');
|
|
1779
|
+
*
|
|
1780
|
+
* const n = randomInt(1, 7);
|
|
1781
|
+
* console.log(`The dice rolled: ${n}`);
|
|
1782
|
+
* ```
|
|
1783
|
+
* @since v14.10.0, v12.19.0
|
|
1784
|
+
* @param [min=0] Start of random range (inclusive).
|
|
1785
|
+
* @param max End of random range (exclusive).
|
|
1786
|
+
* @param callback `function(err, n) {}`.
|
|
1787
|
+
*/
|
|
510
1788
|
function randomInt(max: number): number;
|
|
511
1789
|
function randomInt(min: number, max: number): number;
|
|
512
1790
|
function randomInt(max: number, callback: (err: Error | null, value: number) => void): void;
|
|
513
1791
|
function randomInt(min: number, max: number, callback: (err: Error | null, value: number) => void): void;
|
|
514
|
-
|
|
1792
|
+
/**
|
|
1793
|
+
* Synchronous version of {@link randomFill}.
|
|
1794
|
+
*
|
|
1795
|
+
* ```js
|
|
1796
|
+
* import { Buffer } from 'buffer';
|
|
1797
|
+
* const { randomFillSync } = await import('crypto');
|
|
1798
|
+
*
|
|
1799
|
+
* const buf = Buffer.alloc(10);
|
|
1800
|
+
* console.log(randomFillSync(buf).toString('hex'));
|
|
1801
|
+
*
|
|
1802
|
+
* randomFillSync(buf, 5);
|
|
1803
|
+
* console.log(buf.toString('hex'));
|
|
1804
|
+
*
|
|
1805
|
+
* // The above is equivalent to the following:
|
|
1806
|
+
* randomFillSync(buf, 5, 5);
|
|
1807
|
+
* console.log(buf.toString('hex'));
|
|
1808
|
+
* ```
|
|
1809
|
+
*
|
|
1810
|
+
* Any `ArrayBuffer`, `TypedArray` or `DataView` instance may be passed as`buffer`.
|
|
1811
|
+
*
|
|
1812
|
+
* ```js
|
|
1813
|
+
* import { Buffer } from 'buffer';
|
|
1814
|
+
* const { randomFillSync } = await import('crypto');
|
|
1815
|
+
*
|
|
1816
|
+
* const a = new Uint32Array(10);
|
|
1817
|
+
* console.log(Buffer.from(randomFillSync(a).buffer,
|
|
1818
|
+
* a.byteOffset, a.byteLength).toString('hex'));
|
|
1819
|
+
*
|
|
1820
|
+
* const b = new DataView(new ArrayBuffer(10));
|
|
1821
|
+
* console.log(Buffer.from(randomFillSync(b).buffer,
|
|
1822
|
+
* b.byteOffset, b.byteLength).toString('hex'));
|
|
1823
|
+
*
|
|
1824
|
+
* const c = new ArrayBuffer(10);
|
|
1825
|
+
* console.log(Buffer.from(randomFillSync(c)).toString('hex'));
|
|
1826
|
+
* ```
|
|
1827
|
+
* @since v7.10.0, v6.13.0
|
|
1828
|
+
* @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
|
|
1829
|
+
* @param [offset=0]
|
|
1830
|
+
* @param [size=buffer.length - offset]
|
|
1831
|
+
* @return The object passed as `buffer` argument.
|
|
1832
|
+
*/
|
|
515
1833
|
function randomFillSync<T extends NodeJS.ArrayBufferView>(buffer: T, offset?: number, size?: number): T;
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
1834
|
+
/**
|
|
1835
|
+
* This function is similar to {@link randomBytes} but requires the first
|
|
1836
|
+
* argument to be a `Buffer` that will be filled. It also
|
|
1837
|
+
* requires that a callback is passed in.
|
|
1838
|
+
*
|
|
1839
|
+
* If the `callback` function is not provided, an error will be thrown.
|
|
1840
|
+
*
|
|
1841
|
+
* ```js
|
|
1842
|
+
* import { Buffer } from 'buffer';
|
|
1843
|
+
* const { randomFill } = await import('crypto');
|
|
1844
|
+
*
|
|
1845
|
+
* const buf = Buffer.alloc(10);
|
|
1846
|
+
* randomFill(buf, (err, buf) => {
|
|
1847
|
+
* if (err) throw err;
|
|
1848
|
+
* console.log(buf.toString('hex'));
|
|
1849
|
+
* });
|
|
1850
|
+
*
|
|
1851
|
+
* randomFill(buf, 5, (err, buf) => {
|
|
1852
|
+
* if (err) throw err;
|
|
1853
|
+
* console.log(buf.toString('hex'));
|
|
1854
|
+
* });
|
|
1855
|
+
*
|
|
1856
|
+
* // The above is equivalent to the following:
|
|
1857
|
+
* randomFill(buf, 5, 5, (err, buf) => {
|
|
1858
|
+
* if (err) throw err;
|
|
1859
|
+
* console.log(buf.toString('hex'));
|
|
1860
|
+
* });
|
|
1861
|
+
* ```
|
|
1862
|
+
*
|
|
1863
|
+
* Any `ArrayBuffer`, `TypedArray`, or `DataView` instance may be passed as`buffer`.
|
|
1864
|
+
*
|
|
1865
|
+
* While this includes instances of `Float32Array` and `Float64Array`, this
|
|
1866
|
+
* function should not be used to generate random floating-point numbers. The
|
|
1867
|
+
* result may contain `+Infinity`, `-Infinity`, and `NaN`, and even if the array
|
|
1868
|
+
* contains finite numbers only, they are not drawn from a uniform random
|
|
1869
|
+
* distribution and have no meaningful lower or upper bounds.
|
|
1870
|
+
*
|
|
1871
|
+
* ```js
|
|
1872
|
+
* import { Buffer } from 'buffer';
|
|
1873
|
+
* const { randomFill } = await import('crypto');
|
|
1874
|
+
*
|
|
1875
|
+
* const a = new Uint32Array(10);
|
|
1876
|
+
* randomFill(a, (err, buf) => {
|
|
1877
|
+
* if (err) throw err;
|
|
1878
|
+
* console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
|
|
1879
|
+
* .toString('hex'));
|
|
1880
|
+
* });
|
|
1881
|
+
*
|
|
1882
|
+
* const b = new DataView(new ArrayBuffer(10));
|
|
1883
|
+
* randomFill(b, (err, buf) => {
|
|
1884
|
+
* if (err) throw err;
|
|
1885
|
+
* console.log(Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)
|
|
1886
|
+
* .toString('hex'));
|
|
1887
|
+
* });
|
|
1888
|
+
*
|
|
1889
|
+
* const c = new ArrayBuffer(10);
|
|
1890
|
+
* randomFill(c, (err, buf) => {
|
|
1891
|
+
* if (err) throw err;
|
|
1892
|
+
* console.log(Buffer.from(buf).toString('hex'));
|
|
1893
|
+
* });
|
|
1894
|
+
* ```
|
|
1895
|
+
*
|
|
1896
|
+
* This API uses libuv's threadpool, which can have surprising and
|
|
1897
|
+
* negative performance implications for some applications; see the `UV_THREADPOOL_SIZE` documentation for more information.
|
|
1898
|
+
*
|
|
1899
|
+
* The asynchronous version of `crypto.randomFill()` is carried out in a single
|
|
1900
|
+
* threadpool request. To minimize threadpool task length variation, partition
|
|
1901
|
+
* large `randomFill` requests when doing so as part of fulfilling a client
|
|
1902
|
+
* request.
|
|
1903
|
+
* @since v7.10.0, v6.13.0
|
|
1904
|
+
* @param buffer Must be supplied. The size of the provided `buffer` must not be larger than `2**31 - 1`.
|
|
1905
|
+
* @param [offset=0]
|
|
1906
|
+
* @param [size=buffer.length - offset]
|
|
1907
|
+
* @param callback `function(err, buf) {}`.
|
|
1908
|
+
*/
|
|
1909
|
+
function randomFill<T extends NodeJS.ArrayBufferView>(buffer: T, callback: (err: Error | null, buf: T) => void): void;
|
|
1910
|
+
function randomFill<T extends NodeJS.ArrayBufferView>(buffer: T, offset: number, callback: (err: Error | null, buf: T) => void): void;
|
|
1911
|
+
function randomFill<T extends NodeJS.ArrayBufferView>(buffer: T, offset: number, size: number, callback: (err: Error | null, buf: T) => void): void;
|
|
532
1912
|
interface ScryptOptions {
|
|
533
1913
|
cost?: number | undefined;
|
|
534
1914
|
blockSize?: number | undefined;
|
|
@@ -538,21 +1918,73 @@ declare module 'crypto' {
|
|
|
538
1918
|
p?: number | undefined;
|
|
539
1919
|
maxmem?: number | undefined;
|
|
540
1920
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
1921
|
+
/**
|
|
1922
|
+
* Provides an asynchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
|
|
1923
|
+
* key derivation function that is designed to be expensive computationally and
|
|
1924
|
+
* memory-wise in order to make brute-force attacks unrewarding.
|
|
1925
|
+
*
|
|
1926
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
1927
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
1928
|
+
*
|
|
1929
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1930
|
+
*
|
|
1931
|
+
* 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
|
|
1932
|
+
* callback as a `Buffer`.
|
|
1933
|
+
*
|
|
1934
|
+
* An exception is thrown when any of the input arguments specify invalid values
|
|
1935
|
+
* or types.
|
|
1936
|
+
*
|
|
1937
|
+
* ```js
|
|
1938
|
+
* const {
|
|
1939
|
+
* scrypt
|
|
1940
|
+
* } = await import('crypto');
|
|
1941
|
+
*
|
|
1942
|
+
* // Using the factory defaults.
|
|
1943
|
+
* scrypt('password', 'salt', 64, (err, derivedKey) => {
|
|
1944
|
+
* if (err) throw err;
|
|
1945
|
+
* console.log(derivedKey.toString('hex')); // '3745e48...08d59ae'
|
|
1946
|
+
* });
|
|
1947
|
+
* // Using a custom N parameter. Must be a power of two.
|
|
1948
|
+
* scrypt('password', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
|
|
1949
|
+
* if (err) throw err;
|
|
1950
|
+
* console.log(derivedKey.toString('hex')); // '3745e48...aa39b34'
|
|
1951
|
+
* });
|
|
1952
|
+
* ```
|
|
1953
|
+
* @since v10.5.0
|
|
1954
|
+
*/
|
|
1955
|
+
function scrypt(password: BinaryLike, salt: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: Buffer) => void): void;
|
|
1956
|
+
function scrypt(password: BinaryLike, salt: BinaryLike, keylen: number, options: ScryptOptions, callback: (err: Error | null, derivedKey: Buffer) => void): void;
|
|
1957
|
+
/**
|
|
1958
|
+
* Provides a synchronous [scrypt](https://en.wikipedia.org/wiki/Scrypt) implementation. Scrypt is a password-based
|
|
1959
|
+
* key derivation function that is designed to be expensive computationally and
|
|
1960
|
+
* memory-wise in order to make brute-force attacks unrewarding.
|
|
1961
|
+
*
|
|
1962
|
+
* The `salt` should be as unique as possible. It is recommended that a salt is
|
|
1963
|
+
* random and at least 16 bytes long. See [NIST SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf) for details.
|
|
1964
|
+
*
|
|
1965
|
+
* When passing strings for `password` or `salt`, please consider `caveats when using strings as inputs to cryptographic APIs`.
|
|
1966
|
+
*
|
|
1967
|
+
* An exception is thrown when key derivation fails, otherwise the derived key is
|
|
1968
|
+
* returned as a `Buffer`.
|
|
1969
|
+
*
|
|
1970
|
+
* An exception is thrown when any of the input arguments specify invalid values
|
|
1971
|
+
* or types.
|
|
1972
|
+
*
|
|
1973
|
+
* ```js
|
|
1974
|
+
* const {
|
|
1975
|
+
* scryptSync
|
|
1976
|
+
* } = await import('crypto');
|
|
1977
|
+
* // Using the factory defaults.
|
|
1978
|
+
*
|
|
1979
|
+
* const key1 = scryptSync('password', 'salt', 64);
|
|
1980
|
+
* console.log(key1.toString('hex')); // '3745e48...08d59ae'
|
|
1981
|
+
* // Using a custom N parameter. Must be a power of two.
|
|
1982
|
+
* const key2 = scryptSync('password', 'salt', 64, { N: 1024 });
|
|
1983
|
+
* console.log(key2.toString('hex')); // '3745e48...aa39b34'
|
|
1984
|
+
* ```
|
|
1985
|
+
* @since v10.5.0
|
|
1986
|
+
*/
|
|
554
1987
|
function scryptSync(password: BinaryLike, salt: BinaryLike, keylen: number, options?: ScryptOptions): Buffer;
|
|
555
|
-
|
|
556
1988
|
interface RsaPublicKey {
|
|
557
1989
|
key: KeyLike;
|
|
558
1990
|
padding?: number | undefined;
|
|
@@ -567,124 +1999,344 @@ declare module 'crypto' {
|
|
|
567
1999
|
oaepLabel?: NodeJS.TypedArray | undefined;
|
|
568
2000
|
padding?: number | undefined;
|
|
569
2001
|
}
|
|
2002
|
+
/**
|
|
2003
|
+
* Encrypts the content of `buffer` with `key` and returns a new `Buffer` with encrypted content. The returned data can be decrypted using
|
|
2004
|
+
* the corresponding private key, for example using {@link privateDecrypt}.
|
|
2005
|
+
*
|
|
2006
|
+
* If `key` is not a `KeyObject`, this function behaves as if`key` had been passed to {@link createPublicKey}. If it is an
|
|
2007
|
+
* object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_OAEP_PADDING`.
|
|
2008
|
+
*
|
|
2009
|
+
* Because RSA public keys can be derived from private keys, a private key may
|
|
2010
|
+
* be passed instead of a public key.
|
|
2011
|
+
* @since v0.11.14
|
|
2012
|
+
*/
|
|
570
2013
|
function publicEncrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
2014
|
+
/**
|
|
2015
|
+
* Decrypts `buffer` with `key`.`buffer` was previously encrypted using
|
|
2016
|
+
* the corresponding private key, for example using {@link privateEncrypt}.
|
|
2017
|
+
*
|
|
2018
|
+
* If `key` is not a `KeyObject`, this function behaves as if`key` had been passed to {@link createPublicKey}. If it is an
|
|
2019
|
+
* object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_PADDING`.
|
|
2020
|
+
*
|
|
2021
|
+
* Because RSA public keys can be derived from private keys, a private key may
|
|
2022
|
+
* be passed instead of a public key.
|
|
2023
|
+
* @since v1.1.0
|
|
2024
|
+
*/
|
|
571
2025
|
function publicDecrypt(key: RsaPublicKey | RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
572
|
-
|
|
573
|
-
|
|
2026
|
+
/**
|
|
2027
|
+
* Decrypts `buffer` with `privateKey`. `buffer` was previously encrypted using
|
|
2028
|
+
* the corresponding public key, for example using {@link publicEncrypt}.
|
|
2029
|
+
*
|
|
2030
|
+
* If `privateKey` is not a `KeyObject`, this function behaves as if`privateKey` had been passed to {@link createPrivateKey}. If it is an
|
|
2031
|
+
* object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_OAEP_PADDING`.
|
|
2032
|
+
* @since v0.11.14
|
|
2033
|
+
*/
|
|
2034
|
+
function privateDecrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
2035
|
+
/**
|
|
2036
|
+
* Encrypts `buffer` with `privateKey`. The returned data can be decrypted using
|
|
2037
|
+
* the corresponding public key, for example using {@link publicDecrypt}.
|
|
2038
|
+
*
|
|
2039
|
+
* If `privateKey` is not a `KeyObject`, this function behaves as if`privateKey` had been passed to {@link createPrivateKey}. If it is an
|
|
2040
|
+
* object, the `padding` property can be passed. Otherwise, this function uses`RSA_PKCS1_PADDING`.
|
|
2041
|
+
* @since v1.1.0
|
|
2042
|
+
*/
|
|
2043
|
+
function privateEncrypt(privateKey: RsaPrivateKey | KeyLike, buffer: NodeJS.ArrayBufferView): Buffer;
|
|
2044
|
+
/**
|
|
2045
|
+
* ```js
|
|
2046
|
+
* const {
|
|
2047
|
+
* getCiphers
|
|
2048
|
+
* } = await import('crypto');
|
|
2049
|
+
*
|
|
2050
|
+
* console.log(getCiphers()); // ['aes-128-cbc', 'aes-128-ccm', ...]
|
|
2051
|
+
* ```
|
|
2052
|
+
* @since v0.9.3
|
|
2053
|
+
* @return An array with the names of the supported cipher algorithms.
|
|
2054
|
+
*/
|
|
574
2055
|
function getCiphers(): string[];
|
|
2056
|
+
/**
|
|
2057
|
+
* ```js
|
|
2058
|
+
* const {
|
|
2059
|
+
* getCurves
|
|
2060
|
+
* } = await import('crypto');
|
|
2061
|
+
*
|
|
2062
|
+
* console.log(getCurves()); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
|
|
2063
|
+
* ```
|
|
2064
|
+
* @since v2.3.0
|
|
2065
|
+
* @return An array with the names of the supported elliptic curves.
|
|
2066
|
+
*/
|
|
575
2067
|
function getCurves(): string[];
|
|
2068
|
+
/**
|
|
2069
|
+
* @since v10.0.0
|
|
2070
|
+
* @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}.
|
|
2071
|
+
*/
|
|
576
2072
|
function getFips(): 1 | 0;
|
|
2073
|
+
/**
|
|
2074
|
+
* ```js
|
|
2075
|
+
* const {
|
|
2076
|
+
* getHashes
|
|
2077
|
+
* } = await import('crypto');
|
|
2078
|
+
*
|
|
2079
|
+
* console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
|
|
2080
|
+
* ```
|
|
2081
|
+
* @since v0.9.3
|
|
2082
|
+
* @return An array of the names of the supported hash algorithms, such as `'RSA-SHA256'`. Hash algorithms are also called "digest" algorithms.
|
|
2083
|
+
*/
|
|
577
2084
|
function getHashes(): string[];
|
|
2085
|
+
/**
|
|
2086
|
+
* The `ECDH` class is a utility for creating Elliptic Curve Diffie-Hellman (ECDH)
|
|
2087
|
+
* key exchanges.
|
|
2088
|
+
*
|
|
2089
|
+
* Instances of the `ECDH` class can be created using the {@link createECDH} function.
|
|
2090
|
+
*
|
|
2091
|
+
* ```js
|
|
2092
|
+
* import assert from 'assert';
|
|
2093
|
+
*
|
|
2094
|
+
* const {
|
|
2095
|
+
* createECDH
|
|
2096
|
+
* } = await import('crypto');
|
|
2097
|
+
*
|
|
2098
|
+
* // Generate Alice's keys...
|
|
2099
|
+
* const alice = createECDH('secp521r1');
|
|
2100
|
+
* const aliceKey = alice.generateKeys();
|
|
2101
|
+
*
|
|
2102
|
+
* // Generate Bob's keys...
|
|
2103
|
+
* const bob = createECDH('secp521r1');
|
|
2104
|
+
* const bobKey = bob.generateKeys();
|
|
2105
|
+
*
|
|
2106
|
+
* // Exchange and generate the secret...
|
|
2107
|
+
* const aliceSecret = alice.computeSecret(bobKey);
|
|
2108
|
+
* const bobSecret = bob.computeSecret(aliceKey);
|
|
2109
|
+
*
|
|
2110
|
+
* assert.strictEqual(aliceSecret.toString('hex'), bobSecret.toString('hex'));
|
|
2111
|
+
* // OK
|
|
2112
|
+
* ```
|
|
2113
|
+
* @since v0.11.14
|
|
2114
|
+
*/
|
|
578
2115
|
class ECDH {
|
|
579
2116
|
private constructor();
|
|
2117
|
+
/**
|
|
2118
|
+
* Converts the EC Diffie-Hellman public key specified by `key` and `curve` to the
|
|
2119
|
+
* format specified by `format`. The `format` argument specifies point encoding
|
|
2120
|
+
* and can be `'compressed'`, `'uncompressed'` or `'hybrid'`. The supplied key is
|
|
2121
|
+
* interpreted using the specified `inputEncoding`, and the returned key is encoded
|
|
2122
|
+
* using the specified `outputEncoding`.
|
|
2123
|
+
*
|
|
2124
|
+
* Use {@link getCurves} to obtain a list of available curve names.
|
|
2125
|
+
* On recent OpenSSL releases, `openssl ecparam -list_curves` will also display
|
|
2126
|
+
* the name and description of each available elliptic curve.
|
|
2127
|
+
*
|
|
2128
|
+
* If `format` is not specified the point will be returned in `'uncompressed'`format.
|
|
2129
|
+
*
|
|
2130
|
+
* If the `inputEncoding` is not provided, `key` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
|
|
2131
|
+
*
|
|
2132
|
+
* Example (uncompressing a key):
|
|
2133
|
+
*
|
|
2134
|
+
* ```js
|
|
2135
|
+
* const {
|
|
2136
|
+
* createECDH,
|
|
2137
|
+
* ECDH
|
|
2138
|
+
* } = await import('crypto');
|
|
2139
|
+
*
|
|
2140
|
+
* const ecdh = createECDH('secp256k1');
|
|
2141
|
+
* ecdh.generateKeys();
|
|
2142
|
+
*
|
|
2143
|
+
* const compressedKey = ecdh.getPublicKey('hex', 'compressed');
|
|
2144
|
+
*
|
|
2145
|
+
* const uncompressedKey = ECDH.convertKey(compressedKey,
|
|
2146
|
+
* 'secp256k1',
|
|
2147
|
+
* 'hex',
|
|
2148
|
+
* 'hex',
|
|
2149
|
+
* 'uncompressed');
|
|
2150
|
+
*
|
|
2151
|
+
* // The converted key and the uncompressed public key should be the same
|
|
2152
|
+
* console.log(uncompressedKey === ecdh.getPublicKey('hex'));
|
|
2153
|
+
* ```
|
|
2154
|
+
* @since v10.0.0
|
|
2155
|
+
* @param inputEncoding The `encoding` of the `key` string.
|
|
2156
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
2157
|
+
* @param [format='uncompressed']
|
|
2158
|
+
*/
|
|
580
2159
|
static convertKey(
|
|
581
2160
|
key: BinaryLike,
|
|
582
2161
|
curve: string,
|
|
583
2162
|
inputEncoding?: BinaryToTextEncoding,
|
|
584
|
-
outputEncoding?: 'latin1' | 'hex' | 'base64',
|
|
585
|
-
format?: 'uncompressed' | 'compressed' | 'hybrid'
|
|
2163
|
+
outputEncoding?: 'latin1' | 'hex' | 'base64' | 'base64url',
|
|
2164
|
+
format?: 'uncompressed' | 'compressed' | 'hybrid'
|
|
586
2165
|
): Buffer | string;
|
|
2166
|
+
/**
|
|
2167
|
+
* Generates private and public EC Diffie-Hellman key values, and returns
|
|
2168
|
+
* the public key in the specified `format` and `encoding`. This key should be
|
|
2169
|
+
* transferred to the other party.
|
|
2170
|
+
*
|
|
2171
|
+
* 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.
|
|
2172
|
+
*
|
|
2173
|
+
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned.
|
|
2174
|
+
* @since v0.11.14
|
|
2175
|
+
* @param encoding The `encoding` of the return value.
|
|
2176
|
+
* @param [format='uncompressed']
|
|
2177
|
+
*/
|
|
587
2178
|
generateKeys(): Buffer;
|
|
588
2179
|
generateKeys(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
2180
|
+
/**
|
|
2181
|
+
* Computes the shared secret using `otherPublicKey` as the other
|
|
2182
|
+
* party's public key and returns the computed shared secret. The supplied
|
|
2183
|
+
* key is interpreted using specified `inputEncoding`, and the returned secret
|
|
2184
|
+
* is encoded using the specified `outputEncoding`.
|
|
2185
|
+
* If the `inputEncoding` is not
|
|
2186
|
+
* provided, `otherPublicKey` is expected to be a `Buffer`, `TypedArray`, or`DataView`.
|
|
2187
|
+
*
|
|
2188
|
+
* If `outputEncoding` is given a string will be returned; otherwise a `Buffer` is returned.
|
|
2189
|
+
*
|
|
2190
|
+
* `ecdh.computeSecret` will throw an`ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY` error when `otherPublicKey`lies outside of the elliptic curve. Since `otherPublicKey` is
|
|
2191
|
+
* usually supplied from a remote user over an insecure network,
|
|
2192
|
+
* be sure to handle this exception accordingly.
|
|
2193
|
+
* @since v0.11.14
|
|
2194
|
+
* @param inputEncoding The `encoding` of the `otherPublicKey` string.
|
|
2195
|
+
* @param outputEncoding The `encoding` of the return value.
|
|
2196
|
+
*/
|
|
2197
|
+
computeSecret(otherPublicKey: NodeJS.ArrayBufferView): Buffer;
|
|
2198
|
+
computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding): Buffer;
|
|
2199
|
+
computeSecret(otherPublicKey: NodeJS.ArrayBufferView, outputEncoding: BinaryToTextEncoding): string;
|
|
2200
|
+
computeSecret(otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding: BinaryToTextEncoding): string;
|
|
2201
|
+
/**
|
|
2202
|
+
* If `encoding` is specified, a string is returned; otherwise a `Buffer` is
|
|
2203
|
+
* returned.
|
|
2204
|
+
* @since v0.11.14
|
|
2205
|
+
* @param encoding The `encoding` of the return value.
|
|
2206
|
+
* @return The EC Diffie-Hellman in the specified `encoding`.
|
|
2207
|
+
*/
|
|
597
2208
|
getPrivateKey(): Buffer;
|
|
598
2209
|
getPrivateKey(encoding: BinaryToTextEncoding): string;
|
|
2210
|
+
/**
|
|
2211
|
+
* 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.
|
|
2212
|
+
*
|
|
2213
|
+
* If `encoding` is specified, a string is returned; otherwise a `Buffer` is
|
|
2214
|
+
* returned.
|
|
2215
|
+
* @since v0.11.14
|
|
2216
|
+
* @param encoding The `encoding` of the return value.
|
|
2217
|
+
* @param [format='uncompressed']
|
|
2218
|
+
* @return The EC Diffie-Hellman public key in the specified `encoding` and `format`.
|
|
2219
|
+
*/
|
|
599
2220
|
getPublicKey(): Buffer;
|
|
600
2221
|
getPublicKey(encoding: BinaryToTextEncoding, format?: ECDHKeyFormat): string;
|
|
601
|
-
|
|
602
|
-
|
|
2222
|
+
/**
|
|
2223
|
+
* Sets the EC Diffie-Hellman private key.
|
|
2224
|
+
* If `encoding` is provided, `privateKey` is expected
|
|
2225
|
+
* to be a string; otherwise `privateKey` is expected to be a `Buffer`,`TypedArray`, or `DataView`.
|
|
2226
|
+
*
|
|
2227
|
+
* If `privateKey` is not valid for the curve specified when the `ECDH` object was
|
|
2228
|
+
* created, an error is thrown. Upon setting the private key, the associated
|
|
2229
|
+
* public point (key) is also generated and set in the `ECDH` object.
|
|
2230
|
+
* @since v0.11.14
|
|
2231
|
+
* @param encoding The `encoding` of the `privateKey` string.
|
|
2232
|
+
*/
|
|
2233
|
+
setPrivateKey(privateKey: NodeJS.ArrayBufferView): void;
|
|
2234
|
+
setPrivateKey(privateKey: string, encoding: BinaryToTextEncoding): void;
|
|
603
2235
|
}
|
|
604
|
-
|
|
2236
|
+
/**
|
|
2237
|
+
* Creates an Elliptic Curve Diffie-Hellman (`ECDH`) key exchange object using a
|
|
2238
|
+
* predefined curve specified by the `curveName` string. Use {@link getCurves} to obtain a list of available curve names. On recent
|
|
2239
|
+
* OpenSSL releases, `openssl ecparam -list_curves` will also display the name
|
|
2240
|
+
* and description of each available elliptic curve.
|
|
2241
|
+
* @since v0.11.14
|
|
2242
|
+
*/
|
|
2243
|
+
function createECDH(curveName: string): ECDH;
|
|
2244
|
+
/**
|
|
2245
|
+
* This function is based on a constant-time algorithm.
|
|
2246
|
+
* Returns true if `a` is equal to `b`, without leaking timing information that
|
|
2247
|
+
* would allow an attacker to guess one of the values. This is suitable for
|
|
2248
|
+
* comparing HMAC digests or secret values like authentication cookies or [capability urls](https://www.w3.org/TR/capability-urls/).
|
|
2249
|
+
*
|
|
2250
|
+
* `a` and `b` must both be `Buffer`s, `TypedArray`s, or `DataView`s, and they
|
|
2251
|
+
* must have the same byte length.
|
|
2252
|
+
*
|
|
2253
|
+
* If at least one of `a` and `b` is a `TypedArray` with more than one byte per
|
|
2254
|
+
* entry, such as `Uint16Array`, the result will be computed using the platform
|
|
2255
|
+
* byte order.
|
|
2256
|
+
*
|
|
2257
|
+
* Use of `crypto.timingSafeEqual` does not guarantee that the _surrounding_ code
|
|
2258
|
+
* is timing-safe. Care should be taken to ensure that the surrounding code does
|
|
2259
|
+
* not introduce timing vulnerabilities.
|
|
2260
|
+
* @since v6.6.0
|
|
2261
|
+
*/
|
|
605
2262
|
function timingSafeEqual(a: NodeJS.ArrayBufferView, b: NodeJS.ArrayBufferView): boolean;
|
|
606
2263
|
/** @deprecated since v10.0.0 */
|
|
607
2264
|
const DEFAULT_ENCODING: BufferEncoding;
|
|
608
|
-
|
|
609
|
-
type KeyType = 'rsa' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
2265
|
+
type KeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
610
2266
|
type KeyFormat = 'pem' | 'der';
|
|
611
|
-
|
|
612
2267
|
interface BasePrivateKeyEncodingOptions<T extends KeyFormat> {
|
|
613
2268
|
format: T;
|
|
614
2269
|
cipher?: string | undefined;
|
|
615
2270
|
passphrase?: string | undefined;
|
|
616
2271
|
}
|
|
617
|
-
|
|
618
2272
|
interface KeyPairKeyObjectResult {
|
|
619
2273
|
publicKey: KeyObject;
|
|
620
2274
|
privateKey: KeyObject;
|
|
621
2275
|
}
|
|
622
|
-
|
|
623
|
-
interface
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
interface ED448KeyPairKeyObjectOptions {
|
|
630
|
-
/**
|
|
631
|
-
* No options.
|
|
632
|
-
*/
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
interface X25519KeyPairKeyObjectOptions {
|
|
2276
|
+
interface ED25519KeyPairKeyObjectOptions {}
|
|
2277
|
+
interface ED448KeyPairKeyObjectOptions {}
|
|
2278
|
+
interface X25519KeyPairKeyObjectOptions {}
|
|
2279
|
+
interface X448KeyPairKeyObjectOptions {}
|
|
2280
|
+
interface ECKeyPairKeyObjectOptions {
|
|
636
2281
|
/**
|
|
637
|
-
*
|
|
2282
|
+
* Name of the curve to use
|
|
638
2283
|
*/
|
|
2284
|
+
namedCurve: string;
|
|
639
2285
|
}
|
|
640
|
-
|
|
641
|
-
interface X448KeyPairKeyObjectOptions {
|
|
2286
|
+
interface RSAKeyPairKeyObjectOptions {
|
|
642
2287
|
/**
|
|
643
|
-
*
|
|
2288
|
+
* Key size in bits
|
|
644
2289
|
*/
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
interface ECKeyPairKeyObjectOptions {
|
|
2290
|
+
modulusLength: number;
|
|
648
2291
|
/**
|
|
649
|
-
*
|
|
2292
|
+
* Public exponent
|
|
2293
|
+
* @default 0x10001
|
|
650
2294
|
*/
|
|
651
|
-
|
|
2295
|
+
publicExponent?: number | undefined;
|
|
652
2296
|
}
|
|
653
|
-
|
|
654
|
-
interface RSAKeyPairKeyObjectOptions {
|
|
2297
|
+
interface RSAPSSKeyPairKeyObjectOptions {
|
|
655
2298
|
/**
|
|
656
2299
|
* Key size in bits
|
|
657
2300
|
*/
|
|
658
2301
|
modulusLength: number;
|
|
659
|
-
|
|
660
2302
|
/**
|
|
2303
|
+
* Public exponent
|
|
661
2304
|
* @default 0x10001
|
|
662
2305
|
*/
|
|
663
2306
|
publicExponent?: number | undefined;
|
|
2307
|
+
/**
|
|
2308
|
+
* Name of the message digest
|
|
2309
|
+
*/
|
|
2310
|
+
hashAlgorithm?: string;
|
|
2311
|
+
/**
|
|
2312
|
+
* Name of the message digest used by MGF1
|
|
2313
|
+
*/
|
|
2314
|
+
mgf1HashAlgorithm?: string;
|
|
2315
|
+
/**
|
|
2316
|
+
* Minimal salt length in bytes
|
|
2317
|
+
*/
|
|
2318
|
+
saltLength?: string;
|
|
664
2319
|
}
|
|
665
|
-
|
|
666
2320
|
interface DSAKeyPairKeyObjectOptions {
|
|
667
2321
|
/**
|
|
668
2322
|
* Key size in bits
|
|
669
2323
|
*/
|
|
670
2324
|
modulusLength: number;
|
|
671
|
-
|
|
672
2325
|
/**
|
|
673
2326
|
* Size of q in bits
|
|
674
2327
|
*/
|
|
675
2328
|
divisorLength: number;
|
|
676
2329
|
}
|
|
677
|
-
|
|
678
2330
|
interface RSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
679
2331
|
/**
|
|
680
2332
|
* Key size in bits
|
|
681
2333
|
*/
|
|
682
2334
|
modulusLength: number;
|
|
683
2335
|
/**
|
|
2336
|
+
* Public exponent
|
|
684
2337
|
* @default 0x10001
|
|
685
2338
|
*/
|
|
686
2339
|
publicExponent?: number | undefined;
|
|
687
|
-
|
|
688
2340
|
publicKeyEncoding: {
|
|
689
2341
|
type: 'pkcs1' | 'spki';
|
|
690
2342
|
format: PubF;
|
|
@@ -693,7 +2345,36 @@ declare module 'crypto' {
|
|
|
693
2345
|
type: 'pkcs1' | 'pkcs8';
|
|
694
2346
|
};
|
|
695
2347
|
}
|
|
696
|
-
|
|
2348
|
+
interface RSAPSSKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
2349
|
+
/**
|
|
2350
|
+
* Key size in bits
|
|
2351
|
+
*/
|
|
2352
|
+
modulusLength: number;
|
|
2353
|
+
/**
|
|
2354
|
+
* Public exponent
|
|
2355
|
+
* @default 0x10001
|
|
2356
|
+
*/
|
|
2357
|
+
publicExponent?: number | undefined;
|
|
2358
|
+
/**
|
|
2359
|
+
* Name of the message digest
|
|
2360
|
+
*/
|
|
2361
|
+
hashAlgorithm?: string;
|
|
2362
|
+
/**
|
|
2363
|
+
* Name of the message digest used by MGF1
|
|
2364
|
+
*/
|
|
2365
|
+
mgf1HashAlgorithm?: string;
|
|
2366
|
+
/**
|
|
2367
|
+
* Minimal salt length in bytes
|
|
2368
|
+
*/
|
|
2369
|
+
saltLength?: string;
|
|
2370
|
+
publicKeyEncoding: {
|
|
2371
|
+
type: 'spki';
|
|
2372
|
+
format: PubF;
|
|
2373
|
+
};
|
|
2374
|
+
privateKeyEncoding: BasePrivateKeyEncodingOptions<PrivF> & {
|
|
2375
|
+
type: 'pkcs8';
|
|
2376
|
+
};
|
|
2377
|
+
}
|
|
697
2378
|
interface DSAKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
698
2379
|
/**
|
|
699
2380
|
* Key size in bits
|
|
@@ -703,7 +2384,6 @@ declare module 'crypto' {
|
|
|
703
2384
|
* Size of q in bits
|
|
704
2385
|
*/
|
|
705
2386
|
divisorLength: number;
|
|
706
|
-
|
|
707
2387
|
publicKeyEncoding: {
|
|
708
2388
|
type: 'spki';
|
|
709
2389
|
format: PubF;
|
|
@@ -712,13 +2392,11 @@ declare module 'crypto' {
|
|
|
712
2392
|
type: 'pkcs8';
|
|
713
2393
|
};
|
|
714
2394
|
}
|
|
715
|
-
|
|
716
2395
|
interface ECKeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
717
2396
|
/**
|
|
718
2397
|
* Name of the curve to use.
|
|
719
2398
|
*/
|
|
720
2399
|
namedCurve: string;
|
|
721
|
-
|
|
722
2400
|
publicKeyEncoding: {
|
|
723
2401
|
type: 'pkcs1' | 'spki';
|
|
724
2402
|
format: PubF;
|
|
@@ -727,7 +2405,6 @@ declare module 'crypto' {
|
|
|
727
2405
|
type: 'sec1' | 'pkcs8';
|
|
728
2406
|
};
|
|
729
2407
|
}
|
|
730
|
-
|
|
731
2408
|
interface ED25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
732
2409
|
publicKeyEncoding: {
|
|
733
2410
|
type: 'spki';
|
|
@@ -737,7 +2414,6 @@ declare module 'crypto' {
|
|
|
737
2414
|
type: 'pkcs8';
|
|
738
2415
|
};
|
|
739
2416
|
}
|
|
740
|
-
|
|
741
2417
|
interface ED448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
742
2418
|
publicKeyEncoding: {
|
|
743
2419
|
type: 'spki';
|
|
@@ -747,7 +2423,6 @@ declare module 'crypto' {
|
|
|
747
2423
|
type: 'pkcs8';
|
|
748
2424
|
};
|
|
749
2425
|
}
|
|
750
|
-
|
|
751
2426
|
interface X25519KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
752
2427
|
publicKeyEncoding: {
|
|
753
2428
|
type: 'spki';
|
|
@@ -757,7 +2432,6 @@ declare module 'crypto' {
|
|
|
757
2432
|
type: 'pkcs8';
|
|
758
2433
|
};
|
|
759
2434
|
}
|
|
760
|
-
|
|
761
2435
|
interface X448KeyPairOptions<PubF extends KeyFormat, PrivF extends KeyFormat> {
|
|
762
2436
|
publicKeyEncoding: {
|
|
763
2437
|
type: 'spki';
|
|
@@ -767,488 +2441,440 @@ declare module 'crypto' {
|
|
|
767
2441
|
type: 'pkcs8';
|
|
768
2442
|
};
|
|
769
2443
|
}
|
|
770
|
-
|
|
771
2444
|
interface KeyPairSyncResult<T1 extends string | Buffer, T2 extends string | Buffer> {
|
|
772
2445
|
publicKey: T1;
|
|
773
2446
|
privateKey: T2;
|
|
774
2447
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
2448
|
+
/**
|
|
2449
|
+
* Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC,
|
|
2450
|
+
* Ed25519, Ed448, X25519, X448, and DH are currently supported.
|
|
2451
|
+
*
|
|
2452
|
+
* If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
|
|
2453
|
+
* behaves as if `keyObject.export()` had been called on its result. Otherwise,
|
|
2454
|
+
* the respective part of the key is returned as a `KeyObject`.
|
|
2455
|
+
*
|
|
2456
|
+
* When encoding public keys, it is recommended to use `'spki'`. When encoding
|
|
2457
|
+
* private keys, it is recommended to use `'pkcs8'` with a strong passphrase,
|
|
2458
|
+
* and to keep the passphrase confidential.
|
|
2459
|
+
*
|
|
2460
|
+
* ```js
|
|
2461
|
+
* const {
|
|
2462
|
+
* generateKeyPairSync
|
|
2463
|
+
* } = await import('crypto');
|
|
2464
|
+
*
|
|
2465
|
+
* const {
|
|
2466
|
+
* publicKey,
|
|
2467
|
+
* privateKey,
|
|
2468
|
+
* } = generateKeyPairSync('rsa', {
|
|
2469
|
+
* modulusLength: 4096,
|
|
2470
|
+
* publicKeyEncoding: {
|
|
2471
|
+
* type: 'spki',
|
|
2472
|
+
* format: 'pem'
|
|
2473
|
+
* },
|
|
2474
|
+
* privateKeyEncoding: {
|
|
2475
|
+
* type: 'pkcs8',
|
|
2476
|
+
* format: 'pem',
|
|
2477
|
+
* cipher: 'aes-256-cbc',
|
|
2478
|
+
* passphrase: 'top secret'
|
|
2479
|
+
* }
|
|
2480
|
+
* });
|
|
2481
|
+
* ```
|
|
2482
|
+
*
|
|
2483
|
+
* The return value `{ publicKey, privateKey }` represents the generated key pair.
|
|
2484
|
+
* When PEM encoding was selected, the respective key will be a string, otherwise
|
|
2485
|
+
* it will be a buffer containing the data encoded as DER.
|
|
2486
|
+
* @since v10.12.0
|
|
2487
|
+
* @param type Must be `'rsa'`, `'rsa-pss'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'`, `'x448'`, or `'dh'`.
|
|
2488
|
+
*/
|
|
2489
|
+
function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2490
|
+
function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2491
|
+
function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2492
|
+
function generateKeyPairSync(type: 'rsa', options: RSAKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
792
2493
|
function generateKeyPairSync(type: 'rsa', options: RSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
793
|
-
|
|
794
|
-
function generateKeyPairSync(
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
function generateKeyPairSync(
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
): KeyPairSyncResult<
|
|
802
|
-
function generateKeyPairSync(
|
|
803
|
-
type: 'dsa',
|
|
804
|
-
options: DSAKeyPairOptions<'der', 'pem'>,
|
|
805
|
-
): KeyPairSyncResult<Buffer, string>;
|
|
806
|
-
function generateKeyPairSync(
|
|
807
|
-
type: 'dsa',
|
|
808
|
-
options: DSAKeyPairOptions<'der', 'der'>,
|
|
809
|
-
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2494
|
+
function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2495
|
+
function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2496
|
+
function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2497
|
+
function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
2498
|
+
function generateKeyPairSync(type: 'rsa-pss', options: RSAPSSKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
2499
|
+
function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2500
|
+
function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2501
|
+
function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2502
|
+
function generateKeyPairSync(type: 'dsa', options: DSAKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
810
2503
|
function generateKeyPairSync(type: 'dsa', options: DSAKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
811
|
-
|
|
812
|
-
function generateKeyPairSync(
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
): KeyPairSyncResult<string, string>;
|
|
816
|
-
function generateKeyPairSync(
|
|
817
|
-
type: 'ec',
|
|
818
|
-
options: ECKeyPairOptions<'pem', 'der'>,
|
|
819
|
-
): KeyPairSyncResult<string, Buffer>;
|
|
820
|
-
function generateKeyPairSync(
|
|
821
|
-
type: 'ec',
|
|
822
|
-
options: ECKeyPairOptions<'der', 'pem'>,
|
|
823
|
-
): KeyPairSyncResult<Buffer, string>;
|
|
824
|
-
function generateKeyPairSync(
|
|
825
|
-
type: 'ec',
|
|
826
|
-
options: ECKeyPairOptions<'der', 'der'>,
|
|
827
|
-
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2504
|
+
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2505
|
+
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2506
|
+
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2507
|
+
function generateKeyPairSync(type: 'ec', options: ECKeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
828
2508
|
function generateKeyPairSync(type: 'ec', options: ECKeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
829
|
-
|
|
830
|
-
function generateKeyPairSync(
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
): KeyPairSyncResult<string, string>;
|
|
834
|
-
function generateKeyPairSync(
|
|
835
|
-
type: 'ed25519',
|
|
836
|
-
options: ED25519KeyPairOptions<'pem', 'der'>,
|
|
837
|
-
): KeyPairSyncResult<string, Buffer>;
|
|
838
|
-
function generateKeyPairSync(
|
|
839
|
-
type: 'ed25519',
|
|
840
|
-
options: ED25519KeyPairOptions<'der', 'pem'>,
|
|
841
|
-
): KeyPairSyncResult<Buffer, string>;
|
|
842
|
-
function generateKeyPairSync(
|
|
843
|
-
type: 'ed25519',
|
|
844
|
-
options: ED25519KeyPairOptions<'der', 'der'>,
|
|
845
|
-
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2509
|
+
function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2510
|
+
function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2511
|
+
function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2512
|
+
function generateKeyPairSync(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
846
2513
|
function generateKeyPairSync(type: 'ed25519', options?: ED25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
847
|
-
|
|
848
|
-
function generateKeyPairSync(
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
): KeyPairSyncResult<string, string>;
|
|
852
|
-
function generateKeyPairSync(
|
|
853
|
-
type: 'ed448',
|
|
854
|
-
options: ED448KeyPairOptions<'pem', 'der'>,
|
|
855
|
-
): KeyPairSyncResult<string, Buffer>;
|
|
856
|
-
function generateKeyPairSync(
|
|
857
|
-
type: 'ed448',
|
|
858
|
-
options: ED448KeyPairOptions<'der', 'pem'>,
|
|
859
|
-
): KeyPairSyncResult<Buffer, string>;
|
|
860
|
-
function generateKeyPairSync(
|
|
861
|
-
type: 'ed448',
|
|
862
|
-
options: ED448KeyPairOptions<'der', 'der'>,
|
|
863
|
-
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2514
|
+
function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2515
|
+
function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2516
|
+
function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2517
|
+
function generateKeyPairSync(type: 'ed448', options: ED448KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
864
2518
|
function generateKeyPairSync(type: 'ed448', options?: ED448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
865
|
-
|
|
866
|
-
function generateKeyPairSync(
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
): KeyPairSyncResult<string, string>;
|
|
870
|
-
function generateKeyPairSync(
|
|
871
|
-
type: 'x25519',
|
|
872
|
-
options: X25519KeyPairOptions<'pem', 'der'>,
|
|
873
|
-
): KeyPairSyncResult<string, Buffer>;
|
|
874
|
-
function generateKeyPairSync(
|
|
875
|
-
type: 'x25519',
|
|
876
|
-
options: X25519KeyPairOptions<'der', 'pem'>,
|
|
877
|
-
): KeyPairSyncResult<Buffer, string>;
|
|
878
|
-
function generateKeyPairSync(
|
|
879
|
-
type: 'x25519',
|
|
880
|
-
options: X25519KeyPairOptions<'der', 'der'>,
|
|
881
|
-
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2519
|
+
function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2520
|
+
function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2521
|
+
function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2522
|
+
function generateKeyPairSync(type: 'x25519', options: X25519KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
882
2523
|
function generateKeyPairSync(type: 'x25519', options?: X25519KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
883
|
-
|
|
884
|
-
function generateKeyPairSync(
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
): KeyPairSyncResult<string, string>;
|
|
888
|
-
function generateKeyPairSync(
|
|
889
|
-
type: 'x448',
|
|
890
|
-
options: X448KeyPairOptions<'pem', 'der'>,
|
|
891
|
-
): KeyPairSyncResult<string, Buffer>;
|
|
892
|
-
function generateKeyPairSync(
|
|
893
|
-
type: 'x448',
|
|
894
|
-
options: X448KeyPairOptions<'der', 'pem'>,
|
|
895
|
-
): KeyPairSyncResult<Buffer, string>;
|
|
896
|
-
function generateKeyPairSync(
|
|
897
|
-
type: 'x448',
|
|
898
|
-
options: X448KeyPairOptions<'der', 'der'>,
|
|
899
|
-
): KeyPairSyncResult<Buffer, Buffer>;
|
|
2524
|
+
function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'pem', 'pem'>): KeyPairSyncResult<string, string>;
|
|
2525
|
+
function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'pem', 'der'>): KeyPairSyncResult<string, Buffer>;
|
|
2526
|
+
function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'der', 'pem'>): KeyPairSyncResult<Buffer, string>;
|
|
2527
|
+
function generateKeyPairSync(type: 'x448', options: X448KeyPairOptions<'der', 'der'>): KeyPairSyncResult<Buffer, Buffer>;
|
|
900
2528
|
function generateKeyPairSync(type: 'x448', options?: X448KeyPairKeyObjectOptions): KeyPairKeyObjectResult;
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
): void;
|
|
943
|
-
function generateKeyPair(
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
): void;
|
|
948
|
-
function generateKeyPair(
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
): void;
|
|
953
|
-
|
|
954
|
-
function generateKeyPair(
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
): void;
|
|
959
|
-
function generateKeyPair(
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
): void;
|
|
964
|
-
function generateKeyPair(
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
): void;
|
|
969
|
-
function generateKeyPair(
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
): void;
|
|
974
|
-
function generateKeyPair(
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
): void;
|
|
979
|
-
|
|
980
|
-
function generateKeyPair(
|
|
981
|
-
type: 'ed25519',
|
|
982
|
-
options: ED25519KeyPairOptions<'pem', 'pem'>,
|
|
983
|
-
callback: (err: Error | null, publicKey: string, privateKey: string) => void,
|
|
984
|
-
): void;
|
|
985
|
-
function generateKeyPair(
|
|
986
|
-
type: 'ed25519',
|
|
987
|
-
options: ED25519KeyPairOptions<'pem', 'der'>,
|
|
988
|
-
callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
|
|
989
|
-
): void;
|
|
990
|
-
function generateKeyPair(
|
|
991
|
-
type: 'ed25519',
|
|
992
|
-
options: ED25519KeyPairOptions<'der', 'pem'>,
|
|
993
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
|
|
994
|
-
): void;
|
|
995
|
-
function generateKeyPair(
|
|
996
|
-
type: 'ed25519',
|
|
997
|
-
options: ED25519KeyPairOptions<'der', 'der'>,
|
|
998
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
|
|
999
|
-
): void;
|
|
1000
|
-
function generateKeyPair(
|
|
1001
|
-
type: 'ed25519',
|
|
1002
|
-
options: ED25519KeyPairKeyObjectOptions | undefined,
|
|
1003
|
-
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1004
|
-
): void;
|
|
1005
|
-
|
|
1006
|
-
function generateKeyPair(
|
|
1007
|
-
type: 'ed448',
|
|
1008
|
-
options: ED448KeyPairOptions<'pem', 'pem'>,
|
|
1009
|
-
callback: (err: Error | null, publicKey: string, privateKey: string) => void,
|
|
1010
|
-
): void;
|
|
1011
|
-
function generateKeyPair(
|
|
1012
|
-
type: 'ed448',
|
|
1013
|
-
options: ED448KeyPairOptions<'pem', 'der'>,
|
|
1014
|
-
callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
|
|
1015
|
-
): void;
|
|
1016
|
-
function generateKeyPair(
|
|
1017
|
-
type: 'ed448',
|
|
1018
|
-
options: ED448KeyPairOptions<'der', 'pem'>,
|
|
1019
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
|
|
1020
|
-
): void;
|
|
1021
|
-
function generateKeyPair(
|
|
1022
|
-
type: 'ed448',
|
|
1023
|
-
options: ED448KeyPairOptions<'der', 'der'>,
|
|
1024
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
|
|
1025
|
-
): void;
|
|
1026
|
-
function generateKeyPair(
|
|
1027
|
-
type: 'ed448',
|
|
1028
|
-
options: ED448KeyPairKeyObjectOptions | undefined,
|
|
1029
|
-
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1030
|
-
): void;
|
|
1031
|
-
|
|
1032
|
-
function generateKeyPair(
|
|
1033
|
-
type: 'x25519',
|
|
1034
|
-
options: X25519KeyPairOptions<'pem', 'pem'>,
|
|
1035
|
-
callback: (err: Error | null, publicKey: string, privateKey: string) => void,
|
|
1036
|
-
): void;
|
|
1037
|
-
function generateKeyPair(
|
|
1038
|
-
type: 'x25519',
|
|
1039
|
-
options: X25519KeyPairOptions<'pem', 'der'>,
|
|
1040
|
-
callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
|
|
1041
|
-
): void;
|
|
1042
|
-
function generateKeyPair(
|
|
1043
|
-
type: 'x25519',
|
|
1044
|
-
options: X25519KeyPairOptions<'der', 'pem'>,
|
|
1045
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
|
|
1046
|
-
): void;
|
|
1047
|
-
function generateKeyPair(
|
|
1048
|
-
type: 'x25519',
|
|
1049
|
-
options: X25519KeyPairOptions<'der', 'der'>,
|
|
1050
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
|
|
1051
|
-
): void;
|
|
1052
|
-
function generateKeyPair(
|
|
1053
|
-
type: 'x25519',
|
|
1054
|
-
options: X25519KeyPairKeyObjectOptions | undefined,
|
|
1055
|
-
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1056
|
-
): void;
|
|
1057
|
-
|
|
1058
|
-
function generateKeyPair(
|
|
1059
|
-
type: 'x448',
|
|
1060
|
-
options: X448KeyPairOptions<'pem', 'pem'>,
|
|
1061
|
-
callback: (err: Error | null, publicKey: string, privateKey: string) => void,
|
|
1062
|
-
): void;
|
|
1063
|
-
function generateKeyPair(
|
|
1064
|
-
type: 'x448',
|
|
1065
|
-
options: X448KeyPairOptions<'pem', 'der'>,
|
|
1066
|
-
callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void,
|
|
1067
|
-
): void;
|
|
1068
|
-
function generateKeyPair(
|
|
1069
|
-
type: 'x448',
|
|
1070
|
-
options: X448KeyPairOptions<'der', 'pem'>,
|
|
1071
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void,
|
|
1072
|
-
): void;
|
|
1073
|
-
function generateKeyPair(
|
|
1074
|
-
type: 'x448',
|
|
1075
|
-
options: X448KeyPairOptions<'der', 'der'>,
|
|
1076
|
-
callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void,
|
|
1077
|
-
): void;
|
|
1078
|
-
function generateKeyPair(
|
|
1079
|
-
type: 'x448',
|
|
1080
|
-
options: X448KeyPairKeyObjectOptions | undefined,
|
|
1081
|
-
callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void,
|
|
1082
|
-
): void;
|
|
1083
|
-
|
|
2529
|
+
/**
|
|
2530
|
+
* Generates a new asymmetric key pair of the given `type`. RSA, RSA-PSS, DSA, EC,
|
|
2531
|
+
* Ed25519, Ed448, X25519, X448, and DH are currently supported.
|
|
2532
|
+
*
|
|
2533
|
+
* If a `publicKeyEncoding` or `privateKeyEncoding` was specified, this function
|
|
2534
|
+
* behaves as if `keyObject.export()` had been called on its result. Otherwise,
|
|
2535
|
+
* the respective part of the key is returned as a `KeyObject`.
|
|
2536
|
+
*
|
|
2537
|
+
* It is recommended to encode public keys as `'spki'` and private keys as`'pkcs8'` with encryption for long-term storage:
|
|
2538
|
+
*
|
|
2539
|
+
* ```js
|
|
2540
|
+
* const {
|
|
2541
|
+
* generateKeyPair
|
|
2542
|
+
* } = await import('crypto');
|
|
2543
|
+
*
|
|
2544
|
+
* generateKeyPair('rsa', {
|
|
2545
|
+
* modulusLength: 4096,
|
|
2546
|
+
* publicKeyEncoding: {
|
|
2547
|
+
* type: 'spki',
|
|
2548
|
+
* format: 'pem'
|
|
2549
|
+
* },
|
|
2550
|
+
* privateKeyEncoding: {
|
|
2551
|
+
* type: 'pkcs8',
|
|
2552
|
+
* format: 'pem',
|
|
2553
|
+
* cipher: 'aes-256-cbc',
|
|
2554
|
+
* passphrase: 'top secret'
|
|
2555
|
+
* }
|
|
2556
|
+
* }, (err, publicKey, privateKey) => {
|
|
2557
|
+
* // Handle errors and use the generated key pair.
|
|
2558
|
+
* });
|
|
2559
|
+
* ```
|
|
2560
|
+
*
|
|
2561
|
+
* On completion, `callback` will be called with `err` set to `undefined` and`publicKey` / `privateKey` representing the generated key pair.
|
|
2562
|
+
*
|
|
2563
|
+
* If this method is invoked as its `util.promisify()` ed version, it returns
|
|
2564
|
+
* a `Promise` for an `Object` with `publicKey` and `privateKey` properties.
|
|
2565
|
+
* @since v10.12.0
|
|
2566
|
+
* @param type Must be `'rsa'`, `'rsa-pss'`, `'dsa'`, `'ec'`, `'ed25519'`, `'ed448'`, `'x25519'`, `'x448'`, or `'dh'`.
|
|
2567
|
+
*/
|
|
2568
|
+
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2569
|
+
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2570
|
+
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2571
|
+
function generateKeyPair(type: 'rsa', options: RSAKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2572
|
+
function generateKeyPair(type: 'rsa', options: RSAKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2573
|
+
function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2574
|
+
function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2575
|
+
function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2576
|
+
function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2577
|
+
function generateKeyPair(type: 'rsa-pss', options: RSAPSSKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2578
|
+
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2579
|
+
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2580
|
+
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2581
|
+
function generateKeyPair(type: 'dsa', options: DSAKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2582
|
+
function generateKeyPair(type: 'dsa', options: DSAKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2583
|
+
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2584
|
+
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2585
|
+
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2586
|
+
function generateKeyPair(type: 'ec', options: ECKeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2587
|
+
function generateKeyPair(type: 'ec', options: ECKeyPairKeyObjectOptions, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2588
|
+
function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2589
|
+
function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2590
|
+
function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2591
|
+
function generateKeyPair(type: 'ed25519', options: ED25519KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2592
|
+
function generateKeyPair(type: 'ed25519', options: ED25519KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2593
|
+
function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2594
|
+
function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2595
|
+
function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2596
|
+
function generateKeyPair(type: 'ed448', options: ED448KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2597
|
+
function generateKeyPair(type: 'ed448', options: ED448KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2598
|
+
function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2599
|
+
function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2600
|
+
function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2601
|
+
function generateKeyPair(type: 'x25519', options: X25519KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2602
|
+
function generateKeyPair(type: 'x25519', options: X25519KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
2603
|
+
function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'pem', 'pem'>, callback: (err: Error | null, publicKey: string, privateKey: string) => void): void;
|
|
2604
|
+
function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'pem', 'der'>, callback: (err: Error | null, publicKey: string, privateKey: Buffer) => void): void;
|
|
2605
|
+
function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'der', 'pem'>, callback: (err: Error | null, publicKey: Buffer, privateKey: string) => void): void;
|
|
2606
|
+
function generateKeyPair(type: 'x448', options: X448KeyPairOptions<'der', 'der'>, callback: (err: Error | null, publicKey: Buffer, privateKey: Buffer) => void): void;
|
|
2607
|
+
function generateKeyPair(type: 'x448', options: X448KeyPairKeyObjectOptions | undefined, callback: (err: Error | null, publicKey: KeyObject, privateKey: KeyObject) => void): void;
|
|
1084
2608
|
namespace generateKeyPair {
|
|
1085
2609
|
function __promisify__(
|
|
1086
2610
|
type: 'rsa',
|
|
1087
|
-
options: RSAKeyPairOptions<'pem', 'pem'
|
|
1088
|
-
): Promise<{
|
|
2611
|
+
options: RSAKeyPairOptions<'pem', 'pem'>
|
|
2612
|
+
): Promise<{
|
|
2613
|
+
publicKey: string;
|
|
2614
|
+
privateKey: string;
|
|
2615
|
+
}>;
|
|
1089
2616
|
function __promisify__(
|
|
1090
2617
|
type: 'rsa',
|
|
1091
|
-
options: RSAKeyPairOptions<'pem', 'der'
|
|
1092
|
-
): Promise<{
|
|
2618
|
+
options: RSAKeyPairOptions<'pem', 'der'>
|
|
2619
|
+
): Promise<{
|
|
2620
|
+
publicKey: string;
|
|
2621
|
+
privateKey: Buffer;
|
|
2622
|
+
}>;
|
|
1093
2623
|
function __promisify__(
|
|
1094
2624
|
type: 'rsa',
|
|
1095
|
-
options: RSAKeyPairOptions<'der', 'pem'
|
|
1096
|
-
): Promise<{
|
|
2625
|
+
options: RSAKeyPairOptions<'der', 'pem'>
|
|
2626
|
+
): Promise<{
|
|
2627
|
+
publicKey: Buffer;
|
|
2628
|
+
privateKey: string;
|
|
2629
|
+
}>;
|
|
1097
2630
|
function __promisify__(
|
|
1098
2631
|
type: 'rsa',
|
|
1099
|
-
options: RSAKeyPairOptions<'der', 'der'
|
|
1100
|
-
): Promise<{
|
|
2632
|
+
options: RSAKeyPairOptions<'der', 'der'>
|
|
2633
|
+
): Promise<{
|
|
2634
|
+
publicKey: Buffer;
|
|
2635
|
+
privateKey: Buffer;
|
|
2636
|
+
}>;
|
|
1101
2637
|
function __promisify__(type: 'rsa', options: RSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1102
|
-
|
|
2638
|
+
function __promisify__(
|
|
2639
|
+
type: 'rsa-pss',
|
|
2640
|
+
options: RSAPSSKeyPairOptions<'pem', 'pem'>
|
|
2641
|
+
): Promise<{
|
|
2642
|
+
publicKey: string;
|
|
2643
|
+
privateKey: string;
|
|
2644
|
+
}>;
|
|
2645
|
+
function __promisify__(
|
|
2646
|
+
type: 'rsa-pss',
|
|
2647
|
+
options: RSAPSSKeyPairOptions<'pem', 'der'>
|
|
2648
|
+
): Promise<{
|
|
2649
|
+
publicKey: string;
|
|
2650
|
+
privateKey: Buffer;
|
|
2651
|
+
}>;
|
|
2652
|
+
function __promisify__(
|
|
2653
|
+
type: 'rsa-pss',
|
|
2654
|
+
options: RSAPSSKeyPairOptions<'der', 'pem'>
|
|
2655
|
+
): Promise<{
|
|
2656
|
+
publicKey: Buffer;
|
|
2657
|
+
privateKey: string;
|
|
2658
|
+
}>;
|
|
2659
|
+
function __promisify__(
|
|
2660
|
+
type: 'rsa-pss',
|
|
2661
|
+
options: RSAPSSKeyPairOptions<'der', 'der'>
|
|
2662
|
+
): Promise<{
|
|
2663
|
+
publicKey: Buffer;
|
|
2664
|
+
privateKey: Buffer;
|
|
2665
|
+
}>;
|
|
2666
|
+
function __promisify__(type: 'rsa-pss', options: RSAPSSKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1103
2667
|
function __promisify__(
|
|
1104
2668
|
type: 'dsa',
|
|
1105
|
-
options: DSAKeyPairOptions<'pem', 'pem'
|
|
1106
|
-
): Promise<{
|
|
2669
|
+
options: DSAKeyPairOptions<'pem', 'pem'>
|
|
2670
|
+
): Promise<{
|
|
2671
|
+
publicKey: string;
|
|
2672
|
+
privateKey: string;
|
|
2673
|
+
}>;
|
|
1107
2674
|
function __promisify__(
|
|
1108
2675
|
type: 'dsa',
|
|
1109
|
-
options: DSAKeyPairOptions<'pem', 'der'
|
|
1110
|
-
): Promise<{
|
|
2676
|
+
options: DSAKeyPairOptions<'pem', 'der'>
|
|
2677
|
+
): Promise<{
|
|
2678
|
+
publicKey: string;
|
|
2679
|
+
privateKey: Buffer;
|
|
2680
|
+
}>;
|
|
1111
2681
|
function __promisify__(
|
|
1112
2682
|
type: 'dsa',
|
|
1113
|
-
options: DSAKeyPairOptions<'der', 'pem'
|
|
1114
|
-
): Promise<{
|
|
2683
|
+
options: DSAKeyPairOptions<'der', 'pem'>
|
|
2684
|
+
): Promise<{
|
|
2685
|
+
publicKey: Buffer;
|
|
2686
|
+
privateKey: string;
|
|
2687
|
+
}>;
|
|
1115
2688
|
function __promisify__(
|
|
1116
2689
|
type: 'dsa',
|
|
1117
|
-
options: DSAKeyPairOptions<'der', 'der'
|
|
1118
|
-
): Promise<{
|
|
2690
|
+
options: DSAKeyPairOptions<'der', 'der'>
|
|
2691
|
+
): Promise<{
|
|
2692
|
+
publicKey: Buffer;
|
|
2693
|
+
privateKey: Buffer;
|
|
2694
|
+
}>;
|
|
1119
2695
|
function __promisify__(type: 'dsa', options: DSAKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1120
|
-
|
|
1121
2696
|
function __promisify__(
|
|
1122
2697
|
type: 'ec',
|
|
1123
|
-
options: ECKeyPairOptions<'pem', 'pem'
|
|
1124
|
-
): Promise<{
|
|
2698
|
+
options: ECKeyPairOptions<'pem', 'pem'>
|
|
2699
|
+
): Promise<{
|
|
2700
|
+
publicKey: string;
|
|
2701
|
+
privateKey: string;
|
|
2702
|
+
}>;
|
|
1125
2703
|
function __promisify__(
|
|
1126
2704
|
type: 'ec',
|
|
1127
|
-
options: ECKeyPairOptions<'pem', 'der'
|
|
1128
|
-
): Promise<{
|
|
2705
|
+
options: ECKeyPairOptions<'pem', 'der'>
|
|
2706
|
+
): Promise<{
|
|
2707
|
+
publicKey: string;
|
|
2708
|
+
privateKey: Buffer;
|
|
2709
|
+
}>;
|
|
1129
2710
|
function __promisify__(
|
|
1130
2711
|
type: 'ec',
|
|
1131
|
-
options: ECKeyPairOptions<'der', 'pem'
|
|
1132
|
-
): Promise<{
|
|
2712
|
+
options: ECKeyPairOptions<'der', 'pem'>
|
|
2713
|
+
): Promise<{
|
|
2714
|
+
publicKey: Buffer;
|
|
2715
|
+
privateKey: string;
|
|
2716
|
+
}>;
|
|
1133
2717
|
function __promisify__(
|
|
1134
2718
|
type: 'ec',
|
|
1135
|
-
options: ECKeyPairOptions<'der', 'der'
|
|
1136
|
-
): Promise<{
|
|
2719
|
+
options: ECKeyPairOptions<'der', 'der'>
|
|
2720
|
+
): Promise<{
|
|
2721
|
+
publicKey: Buffer;
|
|
2722
|
+
privateKey: Buffer;
|
|
2723
|
+
}>;
|
|
1137
2724
|
function __promisify__(type: 'ec', options: ECKeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1138
|
-
|
|
1139
|
-
function __promisify__(
|
|
1140
|
-
type: 'ed25519',
|
|
1141
|
-
options: ED25519KeyPairOptions<'pem', 'pem'>,
|
|
1142
|
-
): Promise<{ publicKey: string; privateKey: string }>;
|
|
1143
2725
|
function __promisify__(
|
|
1144
2726
|
type: 'ed25519',
|
|
1145
|
-
options: ED25519KeyPairOptions<'pem', '
|
|
1146
|
-
): Promise<{
|
|
2727
|
+
options: ED25519KeyPairOptions<'pem', 'pem'>
|
|
2728
|
+
): Promise<{
|
|
2729
|
+
publicKey: string;
|
|
2730
|
+
privateKey: string;
|
|
2731
|
+
}>;
|
|
1147
2732
|
function __promisify__(
|
|
1148
2733
|
type: 'ed25519',
|
|
1149
|
-
options: ED25519KeyPairOptions<'
|
|
1150
|
-
): Promise<{
|
|
2734
|
+
options: ED25519KeyPairOptions<'pem', 'der'>
|
|
2735
|
+
): Promise<{
|
|
2736
|
+
publicKey: string;
|
|
2737
|
+
privateKey: Buffer;
|
|
2738
|
+
}>;
|
|
1151
2739
|
function __promisify__(
|
|
1152
2740
|
type: 'ed25519',
|
|
1153
|
-
options: ED25519KeyPairOptions<'der', '
|
|
1154
|
-
): Promise<{
|
|
2741
|
+
options: ED25519KeyPairOptions<'der', 'pem'>
|
|
2742
|
+
): Promise<{
|
|
2743
|
+
publicKey: Buffer;
|
|
2744
|
+
privateKey: string;
|
|
2745
|
+
}>;
|
|
1155
2746
|
function __promisify__(
|
|
1156
2747
|
type: 'ed25519',
|
|
1157
|
-
options
|
|
1158
|
-
): Promise<
|
|
1159
|
-
|
|
2748
|
+
options: ED25519KeyPairOptions<'der', 'der'>
|
|
2749
|
+
): Promise<{
|
|
2750
|
+
publicKey: Buffer;
|
|
2751
|
+
privateKey: Buffer;
|
|
2752
|
+
}>;
|
|
2753
|
+
function __promisify__(type: 'ed25519', options?: ED25519KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1160
2754
|
function __promisify__(
|
|
1161
2755
|
type: 'ed448',
|
|
1162
|
-
options: ED448KeyPairOptions<'pem', 'pem'
|
|
1163
|
-
): Promise<{
|
|
2756
|
+
options: ED448KeyPairOptions<'pem', 'pem'>
|
|
2757
|
+
): Promise<{
|
|
2758
|
+
publicKey: string;
|
|
2759
|
+
privateKey: string;
|
|
2760
|
+
}>;
|
|
1164
2761
|
function __promisify__(
|
|
1165
2762
|
type: 'ed448',
|
|
1166
|
-
options: ED448KeyPairOptions<'pem', 'der'
|
|
1167
|
-
): Promise<{
|
|
2763
|
+
options: ED448KeyPairOptions<'pem', 'der'>
|
|
2764
|
+
): Promise<{
|
|
2765
|
+
publicKey: string;
|
|
2766
|
+
privateKey: Buffer;
|
|
2767
|
+
}>;
|
|
1168
2768
|
function __promisify__(
|
|
1169
2769
|
type: 'ed448',
|
|
1170
|
-
options: ED448KeyPairOptions<'der', 'pem'
|
|
1171
|
-
): Promise<{
|
|
2770
|
+
options: ED448KeyPairOptions<'der', 'pem'>
|
|
2771
|
+
): Promise<{
|
|
2772
|
+
publicKey: Buffer;
|
|
2773
|
+
privateKey: string;
|
|
2774
|
+
}>;
|
|
1172
2775
|
function __promisify__(
|
|
1173
2776
|
type: 'ed448',
|
|
1174
|
-
options: ED448KeyPairOptions<'der', 'der'
|
|
1175
|
-
): Promise<{
|
|
2777
|
+
options: ED448KeyPairOptions<'der', 'der'>
|
|
2778
|
+
): Promise<{
|
|
2779
|
+
publicKey: Buffer;
|
|
2780
|
+
privateKey: Buffer;
|
|
2781
|
+
}>;
|
|
1176
2782
|
function __promisify__(type: 'ed448', options?: ED448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1177
|
-
|
|
1178
|
-
function __promisify__(
|
|
1179
|
-
type: 'x25519',
|
|
1180
|
-
options: X25519KeyPairOptions<'pem', 'pem'>,
|
|
1181
|
-
): Promise<{ publicKey: string; privateKey: string }>;
|
|
1182
2783
|
function __promisify__(
|
|
1183
2784
|
type: 'x25519',
|
|
1184
|
-
options: X25519KeyPairOptions<'pem', '
|
|
1185
|
-
): Promise<{
|
|
2785
|
+
options: X25519KeyPairOptions<'pem', 'pem'>
|
|
2786
|
+
): Promise<{
|
|
2787
|
+
publicKey: string;
|
|
2788
|
+
privateKey: string;
|
|
2789
|
+
}>;
|
|
1186
2790
|
function __promisify__(
|
|
1187
2791
|
type: 'x25519',
|
|
1188
|
-
options: X25519KeyPairOptions<'
|
|
1189
|
-
): Promise<{
|
|
2792
|
+
options: X25519KeyPairOptions<'pem', 'der'>
|
|
2793
|
+
): Promise<{
|
|
2794
|
+
publicKey: string;
|
|
2795
|
+
privateKey: Buffer;
|
|
2796
|
+
}>;
|
|
1190
2797
|
function __promisify__(
|
|
1191
2798
|
type: 'x25519',
|
|
1192
|
-
options: X25519KeyPairOptions<'der', '
|
|
1193
|
-
): Promise<{
|
|
2799
|
+
options: X25519KeyPairOptions<'der', 'pem'>
|
|
2800
|
+
): Promise<{
|
|
2801
|
+
publicKey: Buffer;
|
|
2802
|
+
privateKey: string;
|
|
2803
|
+
}>;
|
|
1194
2804
|
function __promisify__(
|
|
1195
2805
|
type: 'x25519',
|
|
1196
|
-
options
|
|
1197
|
-
): Promise<
|
|
1198
|
-
|
|
2806
|
+
options: X25519KeyPairOptions<'der', 'der'>
|
|
2807
|
+
): Promise<{
|
|
2808
|
+
publicKey: Buffer;
|
|
2809
|
+
privateKey: Buffer;
|
|
2810
|
+
}>;
|
|
2811
|
+
function __promisify__(type: 'x25519', options?: X25519KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1199
2812
|
function __promisify__(
|
|
1200
2813
|
type: 'x448',
|
|
1201
|
-
options: X448KeyPairOptions<'pem', 'pem'
|
|
1202
|
-
): Promise<{
|
|
2814
|
+
options: X448KeyPairOptions<'pem', 'pem'>
|
|
2815
|
+
): Promise<{
|
|
2816
|
+
publicKey: string;
|
|
2817
|
+
privateKey: string;
|
|
2818
|
+
}>;
|
|
1203
2819
|
function __promisify__(
|
|
1204
2820
|
type: 'x448',
|
|
1205
|
-
options: X448KeyPairOptions<'pem', 'der'
|
|
1206
|
-
): Promise<{
|
|
2821
|
+
options: X448KeyPairOptions<'pem', 'der'>
|
|
2822
|
+
): Promise<{
|
|
2823
|
+
publicKey: string;
|
|
2824
|
+
privateKey: Buffer;
|
|
2825
|
+
}>;
|
|
1207
2826
|
function __promisify__(
|
|
1208
2827
|
type: 'x448',
|
|
1209
|
-
options: X448KeyPairOptions<'der', 'pem'
|
|
1210
|
-
): Promise<{
|
|
2828
|
+
options: X448KeyPairOptions<'der', 'pem'>
|
|
2829
|
+
): Promise<{
|
|
2830
|
+
publicKey: Buffer;
|
|
2831
|
+
privateKey: string;
|
|
2832
|
+
}>;
|
|
1211
2833
|
function __promisify__(
|
|
1212
2834
|
type: 'x448',
|
|
1213
|
-
options: X448KeyPairOptions<'der', 'der'
|
|
1214
|
-
): Promise<{
|
|
2835
|
+
options: X448KeyPairOptions<'der', 'der'>
|
|
2836
|
+
): Promise<{
|
|
2837
|
+
publicKey: Buffer;
|
|
2838
|
+
privateKey: Buffer;
|
|
2839
|
+
}>;
|
|
1215
2840
|
function __promisify__(type: 'x448', options?: X448KeyPairKeyObjectOptions): Promise<KeyPairKeyObjectResult>;
|
|
1216
2841
|
}
|
|
1217
|
-
|
|
1218
2842
|
/**
|
|
1219
2843
|
* Calculates and returns the signature for `data` using the given private key and
|
|
1220
2844
|
* algorithm. If `algorithm` is `null` or `undefined`, then the algorithm is
|
|
1221
2845
|
* dependent upon the key type (especially Ed25519 and Ed448).
|
|
1222
2846
|
*
|
|
1223
2847
|
* If `key` is not a `KeyObject`, this function behaves as if `key` had been
|
|
1224
|
-
* passed to
|
|
2848
|
+
* passed to {@link createPrivateKey}. If it is an object, the following
|
|
2849
|
+
* additional properties can be passed:
|
|
2850
|
+
*
|
|
2851
|
+
* If the `callback` function is provided this function uses libuv's threadpool.
|
|
2852
|
+
* @since v12.0.0
|
|
1225
2853
|
*/
|
|
1226
|
-
function sign(
|
|
1227
|
-
algorithm: string | null | undefined,
|
|
1228
|
-
data: NodeJS.ArrayBufferView,
|
|
1229
|
-
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
|
|
1230
|
-
): Buffer;
|
|
2854
|
+
function sign(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput): Buffer;
|
|
1231
2855
|
function sign(
|
|
1232
2856
|
algorithm: string | null | undefined,
|
|
1233
2857
|
data: NodeJS.ArrayBufferView,
|
|
1234
2858
|
key: KeyLike | SignKeyObjectInput | SignPrivateKeyInput,
|
|
1235
2859
|
callback: (error: Error | null, data: Buffer) => void
|
|
1236
2860
|
): void;
|
|
1237
|
-
|
|
1238
2861
|
/**
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1241
|
-
* dependent upon the key type (especially Ed25519 and Ed448).
|
|
2862
|
+
* 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
|
|
2863
|
+
* key type (especially Ed25519 and Ed448).
|
|
1242
2864
|
*
|
|
1243
2865
|
* If `key` is not a `KeyObject`, this function behaves as if `key` had been
|
|
1244
|
-
* passed to
|
|
2866
|
+
* passed to {@link createPublicKey}. If it is an object, the following
|
|
2867
|
+
* additional properties can be passed:
|
|
2868
|
+
*
|
|
2869
|
+
* The `signature` argument is the previously calculated signature for the `data`.
|
|
2870
|
+
*
|
|
2871
|
+
* Because public keys can be derived from private keys, a private key or a public
|
|
2872
|
+
* key may be passed for `key`.
|
|
2873
|
+
*
|
|
2874
|
+
* If the `callback` function is provided this function uses libuv's threadpool.
|
|
2875
|
+
* @since v12.0.0
|
|
1245
2876
|
*/
|
|
1246
|
-
function verify(
|
|
1247
|
-
algorithm: string | null | undefined,
|
|
1248
|
-
data: NodeJS.ArrayBufferView,
|
|
1249
|
-
key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput,
|
|
1250
|
-
signature: NodeJS.ArrayBufferView,
|
|
1251
|
-
): boolean;
|
|
2877
|
+
function verify(algorithm: string | null | undefined, data: NodeJS.ArrayBufferView, key: KeyLike | VerifyKeyObjectInput | VerifyPublicKeyInput, signature: NodeJS.ArrayBufferView): boolean;
|
|
1252
2878
|
function verify(
|
|
1253
2879
|
algorithm: string | null | undefined,
|
|
1254
2880
|
data: NodeJS.ArrayBufferView,
|
|
@@ -1256,16 +2882,13 @@ declare module 'crypto' {
|
|
|
1256
2882
|
signature: NodeJS.ArrayBufferView,
|
|
1257
2883
|
callback: (error: Error | null, result: boolean) => void
|
|
1258
2884
|
): void;
|
|
1259
|
-
|
|
1260
2885
|
/**
|
|
1261
|
-
* Computes the Diffie-Hellman secret based on a privateKey and a publicKey
|
|
1262
|
-
* Both keys must have the same asymmetricKeyType
|
|
1263
|
-
*
|
|
2886
|
+
* Computes the Diffie-Hellman secret based on a `privateKey` and a `publicKey`.
|
|
2887
|
+
* 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).
|
|
2888
|
+
* @since v13.9.0, v12.17.0
|
|
1264
2889
|
*/
|
|
1265
2890
|
function diffieHellman(options: { privateKey: KeyObject; publicKey: KeyObject }): Buffer;
|
|
1266
|
-
|
|
1267
2891
|
type CipherMode = 'cbc' | 'ccm' | 'cfb' | 'ctr' | 'ecb' | 'gcm' | 'ocb' | 'ofb' | 'stream' | 'wrap' | 'xts';
|
|
1268
|
-
|
|
1269
2892
|
interface CipherInfoOptions {
|
|
1270
2893
|
/**
|
|
1271
2894
|
* A test key length.
|
|
@@ -1276,7 +2899,6 @@ declare module 'crypto' {
|
|
|
1276
2899
|
*/
|
|
1277
2900
|
ivLength?: number | undefined;
|
|
1278
2901
|
}
|
|
1279
|
-
|
|
1280
2902
|
interface CipherInfo {
|
|
1281
2903
|
/**
|
|
1282
2904
|
* The name of the cipher.
|
|
@@ -1305,64 +2927,95 @@ declare module 'crypto' {
|
|
|
1305
2927
|
*/
|
|
1306
2928
|
mode: CipherMode;
|
|
1307
2929
|
}
|
|
1308
|
-
|
|
1309
2930
|
/**
|
|
1310
2931
|
* Returns information about a given cipher.
|
|
1311
2932
|
*
|
|
1312
|
-
* Some ciphers accept variable length keys and initialization vectors.
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
2933
|
+
* Some ciphers accept variable length keys and initialization vectors. By default,
|
|
2934
|
+
* the `crypto.getCipherInfo()` method will return the default values for these
|
|
2935
|
+
* ciphers. To test if a given key length or iv length is acceptable for given
|
|
2936
|
+
* cipher, use the `keyLength` and `ivLength` options. If the given values are
|
|
2937
|
+
* unacceptable, `undefined` will be returned.
|
|
2938
|
+
* @since v15.0.0
|
|
1317
2939
|
* @param nameOrNid The name or nid of the cipher to query.
|
|
1318
2940
|
*/
|
|
1319
2941
|
function getCipherInfo(nameOrNid: string | number, options?: CipherInfoOptions): CipherInfo | undefined;
|
|
1320
|
-
|
|
1321
2942
|
/**
|
|
1322
|
-
* HKDF is a simple key derivation function defined in RFC 5869.
|
|
1323
|
-
*
|
|
2943
|
+
* 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.
|
|
2944
|
+
*
|
|
2945
|
+
* The supplied `callback` function is called with two arguments: `err` and`derivedKey`. If an errors occurs while deriving the key, `err` will be set;
|
|
2946
|
+
* otherwise `err` will be `null`. The successfully generated `derivedKey` will
|
|
2947
|
+
* 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
|
|
2948
|
+
* of the input arguments specify invalid values or types.
|
|
1324
2949
|
*
|
|
1325
|
-
*
|
|
1326
|
-
*
|
|
1327
|
-
*
|
|
1328
|
-
*
|
|
2950
|
+
* ```js
|
|
2951
|
+
* import { Buffer } from 'buffer';
|
|
2952
|
+
* const {
|
|
2953
|
+
* hkdf
|
|
2954
|
+
* } = await import('crypto');
|
|
2955
|
+
*
|
|
2956
|
+
* hkdf('sha512', 'key', 'salt', 'info', 64, (err, derivedKey) => {
|
|
2957
|
+
* if (err) throw err;
|
|
2958
|
+
* console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
|
|
2959
|
+
* });
|
|
2960
|
+
* ```
|
|
2961
|
+
* @since v15.0.0
|
|
2962
|
+
* @param digest The digest algorithm to use.
|
|
2963
|
+
* @param ikm The input keying material. It must be at least one byte in length.
|
|
2964
|
+
* @param salt The salt value. Must be provided but can be zero-length.
|
|
2965
|
+
* @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
|
|
2966
|
+
* @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`
|
|
2967
|
+
* generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
|
|
1329
2968
|
*/
|
|
1330
|
-
function hkdf(digest: string,
|
|
1331
|
-
|
|
2969
|
+
function hkdf(digest: string, irm: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number, callback: (err: Error | null, derivedKey: ArrayBuffer) => void): void;
|
|
1332
2970
|
/**
|
|
1333
|
-
* Provides a synchronous HKDF key derivation function as defined in RFC 5869
|
|
1334
|
-
*
|
|
2971
|
+
* Provides a synchronous HKDF key derivation function as defined in RFC 5869\. The
|
|
2972
|
+
* given `ikm`, `salt` and `info` are used with the `digest` to derive a key of`keylen` bytes.
|
|
2973
|
+
*
|
|
2974
|
+
* The successfully generated `derivedKey` will be returned as an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer).
|
|
1335
2975
|
*
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
2976
|
+
* An error will be thrown if any of the input arguments specify invalid values or
|
|
2977
|
+
* types, or if the derived key cannot be generated.
|
|
2978
|
+
*
|
|
2979
|
+
* ```js
|
|
2980
|
+
* import { Buffer } from 'buffer';
|
|
2981
|
+
* const {
|
|
2982
|
+
* hkdfSync
|
|
2983
|
+
* } = await import('crypto');
|
|
2984
|
+
*
|
|
2985
|
+
* const derivedKey = hkdfSync('sha512', 'key', 'salt', 'info', 64);
|
|
2986
|
+
* console.log(Buffer.from(derivedKey).toString('hex')); // '24156e2...5391653'
|
|
2987
|
+
* ```
|
|
2988
|
+
* @since v15.0.0
|
|
2989
|
+
* @param digest The digest algorithm to use.
|
|
2990
|
+
* @param ikm The input keying material. It must be at least one byte in length.
|
|
2991
|
+
* @param salt The salt value. Must be provided but can be zero-length.
|
|
2992
|
+
* @param info Additional info value. Must be provided but can be zero-length, and cannot be more than 1024 bytes.
|
|
2993
|
+
* @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`
|
|
2994
|
+
* generates 64-byte hashes, making the maximum HKDF output 16320 bytes).
|
|
1339
2995
|
*/
|
|
1340
|
-
function hkdfSync(digest: string,
|
|
1341
|
-
|
|
2996
|
+
function hkdfSync(digest: string, ikm: BinaryLike | KeyObject, salt: BinaryLike, info: BinaryLike, keylen: number): ArrayBuffer;
|
|
1342
2997
|
interface SecureHeapUsage {
|
|
1343
2998
|
/**
|
|
1344
2999
|
* The total allocated secure heap size as specified using the `--secure-heap=n` command-line flag.
|
|
1345
3000
|
*/
|
|
1346
3001
|
total: number;
|
|
1347
|
-
|
|
1348
3002
|
/**
|
|
1349
3003
|
* The minimum allocation from the secure heap as specified using the `--secure-heap-min` command-line flag.
|
|
1350
3004
|
*/
|
|
1351
3005
|
min: number;
|
|
1352
|
-
|
|
1353
3006
|
/**
|
|
1354
3007
|
* The total number of bytes currently allocated from the secure heap.
|
|
1355
3008
|
*/
|
|
1356
3009
|
used: number;
|
|
1357
|
-
|
|
1358
3010
|
/**
|
|
1359
3011
|
* The calculated ratio of `used` to `total` allocated bytes.
|
|
1360
3012
|
*/
|
|
1361
3013
|
utilization: number;
|
|
1362
3014
|
}
|
|
1363
|
-
|
|
3015
|
+
/**
|
|
3016
|
+
* @since v15.6.0
|
|
3017
|
+
*/
|
|
1364
3018
|
function secureHeapUsed(): SecureHeapUsage;
|
|
1365
|
-
|
|
1366
3019
|
interface RandomUUIDOptions {
|
|
1367
3020
|
/**
|
|
1368
3021
|
* By default, to improve performance,
|
|
@@ -1374,166 +3027,175 @@ declare module 'crypto' {
|
|
|
1374
3027
|
*/
|
|
1375
3028
|
disableEntropyCache?: boolean | undefined;
|
|
1376
3029
|
}
|
|
1377
|
-
|
|
3030
|
+
/**
|
|
3031
|
+
* Generates a random [RFC 4122](https://www.rfc-editor.org/rfc/rfc4122.txt) version 4 UUID. The UUID is generated using a
|
|
3032
|
+
* cryptographic pseudorandom number generator.
|
|
3033
|
+
* @since v15.6.0
|
|
3034
|
+
*/
|
|
1378
3035
|
function randomUUID(options?: RandomUUIDOptions): string;
|
|
1379
|
-
|
|
1380
3036
|
interface X509CheckOptions {
|
|
1381
3037
|
/**
|
|
1382
3038
|
* @default 'always'
|
|
1383
3039
|
*/
|
|
1384
3040
|
subject: 'always' | 'never';
|
|
1385
|
-
|
|
1386
3041
|
/**
|
|
1387
3042
|
* @default true
|
|
1388
3043
|
*/
|
|
1389
3044
|
wildcards: boolean;
|
|
1390
|
-
|
|
1391
3045
|
/**
|
|
1392
3046
|
* @default true
|
|
1393
3047
|
*/
|
|
1394
3048
|
partialWildcards: boolean;
|
|
1395
|
-
|
|
1396
3049
|
/**
|
|
1397
3050
|
* @default false
|
|
1398
3051
|
*/
|
|
1399
3052
|
multiLabelWildcards: boolean;
|
|
1400
|
-
|
|
1401
3053
|
/**
|
|
1402
3054
|
* @default false
|
|
1403
3055
|
*/
|
|
1404
3056
|
singleLabelSubdomains: boolean;
|
|
1405
3057
|
}
|
|
1406
|
-
|
|
3058
|
+
/**
|
|
3059
|
+
* Encapsulates an X509 certificate and provides read-only access to
|
|
3060
|
+
* its information.
|
|
3061
|
+
*
|
|
3062
|
+
* ```js
|
|
3063
|
+
* const { X509Certificate } = await import('crypto');
|
|
3064
|
+
*
|
|
3065
|
+
* const x509 = new X509Certificate('{... pem encoded cert ...}');
|
|
3066
|
+
*
|
|
3067
|
+
* console.log(x509.subject);
|
|
3068
|
+
* ```
|
|
3069
|
+
* @since v15.6.0
|
|
3070
|
+
*/
|
|
1407
3071
|
class X509Certificate {
|
|
1408
3072
|
/**
|
|
1409
|
-
* Will be
|
|
3073
|
+
* Will be \`true\` if this is a Certificate Authority (ca) certificate.
|
|
3074
|
+
* @since v15.6.0
|
|
1410
3075
|
*/
|
|
1411
3076
|
readonly ca: boolean;
|
|
1412
|
-
|
|
1413
3077
|
/**
|
|
1414
3078
|
* The SHA-1 fingerprint of this certificate.
|
|
3079
|
+
* @since v15.6.0
|
|
1415
3080
|
*/
|
|
1416
3081
|
readonly fingerprint: string;
|
|
1417
|
-
|
|
1418
3082
|
/**
|
|
1419
3083
|
* The SHA-256 fingerprint of this certificate.
|
|
3084
|
+
* @since v15.6.0
|
|
1420
3085
|
*/
|
|
1421
3086
|
readonly fingerprint256: string;
|
|
1422
|
-
|
|
1423
3087
|
/**
|
|
1424
3088
|
* The complete subject of this certificate.
|
|
3089
|
+
* @since v15.6.0
|
|
1425
3090
|
*/
|
|
1426
3091
|
readonly subject: string;
|
|
1427
|
-
|
|
1428
3092
|
/**
|
|
1429
3093
|
* The subject alternative name specified for this certificate.
|
|
3094
|
+
* @since v15.6.0
|
|
1430
3095
|
*/
|
|
1431
3096
|
readonly subjectAltName: string;
|
|
1432
|
-
|
|
1433
3097
|
/**
|
|
1434
3098
|
* The information access content of this certificate.
|
|
3099
|
+
* @since v15.6.0
|
|
1435
3100
|
*/
|
|
1436
3101
|
readonly infoAccess: string;
|
|
1437
|
-
|
|
1438
3102
|
/**
|
|
1439
3103
|
* An array detailing the key usages for this certificate.
|
|
3104
|
+
* @since v15.6.0
|
|
1440
3105
|
*/
|
|
1441
3106
|
readonly keyUsage: string[];
|
|
1442
|
-
|
|
1443
3107
|
/**
|
|
1444
3108
|
* The issuer identification included in this certificate.
|
|
3109
|
+
* @since v15.6.0
|
|
1445
3110
|
*/
|
|
1446
3111
|
readonly issuer: string;
|
|
1447
|
-
|
|
1448
3112
|
/**
|
|
1449
|
-
* The issuer certificate or `undefined` if the issuer certificate is not
|
|
3113
|
+
* The issuer certificate or `undefined` if the issuer certificate is not
|
|
3114
|
+
* available.
|
|
3115
|
+
* @since v15.9.0
|
|
1450
3116
|
*/
|
|
1451
3117
|
readonly issuerCertificate?: X509Certificate | undefined;
|
|
1452
|
-
|
|
1453
3118
|
/**
|
|
1454
|
-
* The public key for this certificate.
|
|
3119
|
+
* The public key `KeyObject` for this certificate.
|
|
3120
|
+
* @since v15.6.0
|
|
1455
3121
|
*/
|
|
1456
3122
|
readonly publicKey: KeyObject;
|
|
1457
|
-
|
|
1458
3123
|
/**
|
|
1459
3124
|
* A `Buffer` containing the DER encoding of this certificate.
|
|
3125
|
+
* @since v15.6.0
|
|
1460
3126
|
*/
|
|
1461
3127
|
readonly raw: Buffer;
|
|
1462
|
-
|
|
1463
3128
|
/**
|
|
1464
3129
|
* The serial number of this certificate.
|
|
3130
|
+
* @since v15.6.0
|
|
1465
3131
|
*/
|
|
1466
3132
|
readonly serialNumber: string;
|
|
1467
|
-
|
|
1468
3133
|
/**
|
|
1469
|
-
*
|
|
3134
|
+
* The date/time from which this certificate is considered valid.
|
|
3135
|
+
* @since v15.6.0
|
|
1470
3136
|
*/
|
|
1471
3137
|
readonly validFrom: string;
|
|
1472
|
-
|
|
1473
3138
|
/**
|
|
1474
|
-
* The date/time
|
|
3139
|
+
* The date/time until which this certificate is considered valid.
|
|
3140
|
+
* @since v15.6.0
|
|
1475
3141
|
*/
|
|
1476
3142
|
readonly validTo: string;
|
|
1477
|
-
|
|
1478
3143
|
constructor(buffer: BinaryLike);
|
|
1479
|
-
|
|
1480
3144
|
/**
|
|
1481
3145
|
* Checks whether the certificate matches the given email address.
|
|
1482
|
-
*
|
|
1483
|
-
* Returns `email` if the certificate matches
|
|
3146
|
+
* @since v15.6.0
|
|
3147
|
+
* @return Returns `email` if the certificate matches, `undefined` if it does not.
|
|
1484
3148
|
*/
|
|
1485
3149
|
checkEmail(email: string, options?: X509CheckOptions): string | undefined;
|
|
1486
|
-
|
|
1487
3150
|
/**
|
|
1488
3151
|
* Checks whether the certificate matches the given host name.
|
|
1489
|
-
*
|
|
1490
|
-
* Returns `name` if the certificate matches, `undefined` if it does not.
|
|
3152
|
+
* @since v15.6.0
|
|
3153
|
+
* @return Returns `name` if the certificate matches, `undefined` if it does not.
|
|
1491
3154
|
*/
|
|
1492
3155
|
checkHost(name: string, options?: X509CheckOptions): string | undefined;
|
|
1493
|
-
|
|
1494
3156
|
/**
|
|
1495
3157
|
* Checks whether the certificate matches the given IP address (IPv4 or IPv6).
|
|
1496
|
-
*
|
|
1497
|
-
* Returns `ip` if the certificate matches, `undefined` if it does not.
|
|
3158
|
+
* @since v15.6.0
|
|
3159
|
+
* @return Returns `ip` if the certificate matches, `undefined` if it does not.
|
|
1498
3160
|
*/
|
|
1499
3161
|
checkIP(ip: string, options?: X509CheckOptions): string | undefined;
|
|
1500
|
-
|
|
1501
3162
|
/**
|
|
1502
3163
|
* Checks whether this certificate was issued by the given `otherCert`.
|
|
3164
|
+
* @since v15.6.0
|
|
1503
3165
|
*/
|
|
1504
3166
|
checkIssued(otherCert: X509Certificate): boolean;
|
|
1505
|
-
|
|
1506
3167
|
/**
|
|
1507
|
-
* Checks whether
|
|
3168
|
+
* Checks whether the public key for this certificate is consistent with
|
|
3169
|
+
* the given private key.
|
|
3170
|
+
* @since v15.6.0
|
|
3171
|
+
* @param privateKey A private key.
|
|
1508
3172
|
*/
|
|
1509
3173
|
checkPrivateKey(privateKey: KeyObject): boolean;
|
|
1510
|
-
|
|
1511
3174
|
/**
|
|
1512
|
-
* There is no standard JSON encoding for X509 certificates. The
|
|
1513
|
-
* `toJSON()` method returns a string containing the PEM encoded
|
|
3175
|
+
* There is no standard JSON encoding for X509 certificates. The`toJSON()` method returns a string containing the PEM encoded
|
|
1514
3176
|
* certificate.
|
|
3177
|
+
* @since v15.6.0
|
|
1515
3178
|
*/
|
|
1516
3179
|
toJSON(): string;
|
|
1517
|
-
|
|
1518
3180
|
/**
|
|
1519
|
-
* Returns information about this certificate using the legacy certificate object encoding.
|
|
3181
|
+
* Returns information about this certificate using the legacy `certificate object` encoding.
|
|
3182
|
+
* @since v15.6.0
|
|
1520
3183
|
*/
|
|
1521
3184
|
toLegacyObject(): PeerCertificate;
|
|
1522
|
-
|
|
1523
3185
|
/**
|
|
1524
3186
|
* Returns the PEM-encoded certificate.
|
|
3187
|
+
* @since v15.6.0
|
|
1525
3188
|
*/
|
|
1526
3189
|
toString(): string;
|
|
1527
|
-
|
|
1528
3190
|
/**
|
|
1529
3191
|
* Verifies that this certificate was signed by the given public key.
|
|
1530
3192
|
* Does not perform any other validation checks on the certificate.
|
|
3193
|
+
* @since v15.6.0
|
|
3194
|
+
* @param publicKey A public key.
|
|
1531
3195
|
*/
|
|
1532
3196
|
verify(publicKey: KeyObject): boolean;
|
|
1533
3197
|
}
|
|
1534
|
-
|
|
1535
3198
|
type LargeNumberLike = NodeJS.ArrayBufferView | SharedArrayBuffer | ArrayBuffer | bigint;
|
|
1536
|
-
|
|
1537
3199
|
interface GeneratePrimeOptions {
|
|
1538
3200
|
add?: LargeNumberLike | undefined;
|
|
1539
3201
|
rem?: LargeNumberLike | undefined;
|
|
@@ -1543,25 +3205,74 @@ declare module 'crypto' {
|
|
|
1543
3205
|
safe?: boolean | undefined;
|
|
1544
3206
|
bigint?: boolean | undefined;
|
|
1545
3207
|
}
|
|
1546
|
-
|
|
1547
3208
|
interface GeneratePrimeOptionsBigInt extends GeneratePrimeOptions {
|
|
1548
3209
|
bigint: true;
|
|
1549
3210
|
}
|
|
1550
|
-
|
|
1551
3211
|
interface GeneratePrimeOptionsArrayBuffer extends GeneratePrimeOptions {
|
|
1552
3212
|
bigint?: false | undefined;
|
|
1553
3213
|
}
|
|
1554
|
-
|
|
3214
|
+
/**
|
|
3215
|
+
* Generates a pseudorandom prime of `size` bits.
|
|
3216
|
+
*
|
|
3217
|
+
* If `options.safe` is `true`, the prime will be a safe prime -- that is,`(prime - 1) / 2` will also be a prime.
|
|
3218
|
+
*
|
|
3219
|
+
* The `options.add` and `options.rem` parameters can be used to enforce additional
|
|
3220
|
+
* requirements, e.g., for Diffie-Hellman:
|
|
3221
|
+
*
|
|
3222
|
+
* * If `options.add` and `options.rem` are both set, the prime will satisfy the
|
|
3223
|
+
* condition that `prime % add = rem`.
|
|
3224
|
+
* * If only `options.add` is set and `options.safe` is not `true`, the prime will
|
|
3225
|
+
* satisfy the condition that `prime % add = 1`.
|
|
3226
|
+
* * If only `options.add` is set and `options.safe` is set to `true`, the prime
|
|
3227
|
+
* will instead satisfy the condition that `prime % add = 3`. This is necessary
|
|
3228
|
+
* because `prime % add = 1` for `options.add > 2` would contradict the condition
|
|
3229
|
+
* enforced by `options.safe`.
|
|
3230
|
+
* * `options.rem` is ignored if `options.add` is not given.
|
|
3231
|
+
*
|
|
3232
|
+
* Both `options.add` and `options.rem` must be encoded as big-endian sequences
|
|
3233
|
+
* if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or`DataView`.
|
|
3234
|
+
*
|
|
3235
|
+
* By default, the prime is encoded as a big-endian sequence of octets
|
|
3236
|
+
* in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
|
|
3237
|
+
* [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
|
|
3238
|
+
* @since v15.8.0
|
|
3239
|
+
* @param size The size (in bits) of the prime to generate.
|
|
3240
|
+
*/
|
|
1555
3241
|
function generatePrime(size: number, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
|
|
1556
3242
|
function generatePrime(size: number, options: GeneratePrimeOptionsBigInt, callback: (err: Error | null, prime: bigint) => void): void;
|
|
1557
3243
|
function generatePrime(size: number, options: GeneratePrimeOptionsArrayBuffer, callback: (err: Error | null, prime: ArrayBuffer) => void): void;
|
|
1558
3244
|
function generatePrime(size: number, options: GeneratePrimeOptions, callback: (err: Error | null, prime: ArrayBuffer | bigint) => void): void;
|
|
1559
|
-
|
|
3245
|
+
/**
|
|
3246
|
+
* Generates a pseudorandom prime of `size` bits.
|
|
3247
|
+
*
|
|
3248
|
+
* If `options.safe` is `true`, the prime will be a safe prime -- that is,`(prime - 1) / 2` will also be a prime.
|
|
3249
|
+
*
|
|
3250
|
+
* The `options.add` and `options.rem` parameters can be used to enforce additional
|
|
3251
|
+
* requirements, e.g., for Diffie-Hellman:
|
|
3252
|
+
*
|
|
3253
|
+
* * If `options.add` and `options.rem` are both set, the prime will satisfy the
|
|
3254
|
+
* condition that `prime % add = rem`.
|
|
3255
|
+
* * If only `options.add` is set and `options.safe` is not `true`, the prime will
|
|
3256
|
+
* satisfy the condition that `prime % add = 1`.
|
|
3257
|
+
* * If only `options.add` is set and `options.safe` is set to `true`, the prime
|
|
3258
|
+
* will instead satisfy the condition that `prime % add = 3`. This is necessary
|
|
3259
|
+
* because `prime % add = 1` for `options.add > 2` would contradict the condition
|
|
3260
|
+
* enforced by `options.safe`.
|
|
3261
|
+
* * `options.rem` is ignored if `options.add` is not given.
|
|
3262
|
+
*
|
|
3263
|
+
* Both `options.add` and `options.rem` must be encoded as big-endian sequences
|
|
3264
|
+
* if given as an `ArrayBuffer`, `SharedArrayBuffer`, `TypedArray`, `Buffer`, or`DataView`.
|
|
3265
|
+
*
|
|
3266
|
+
* By default, the prime is encoded as a big-endian sequence of octets
|
|
3267
|
+
* in an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer). If the `bigint` option is `true`, then a
|
|
3268
|
+
* [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) is provided.
|
|
3269
|
+
* @since v15.8.0
|
|
3270
|
+
* @param size The size (in bits) of the prime to generate.
|
|
3271
|
+
*/
|
|
1560
3272
|
function generatePrimeSync(size: number): ArrayBuffer;
|
|
1561
3273
|
function generatePrimeSync(size: number, options: GeneratePrimeOptionsBigInt): bigint;
|
|
1562
3274
|
function generatePrimeSync(size: number, options: GeneratePrimeOptionsArrayBuffer): ArrayBuffer;
|
|
1563
3275
|
function generatePrimeSync(size: number, options: GeneratePrimeOptions): ArrayBuffer | bigint;
|
|
1564
|
-
|
|
1565
3276
|
interface CheckPrimeOptions {
|
|
1566
3277
|
/**
|
|
1567
3278
|
* The number of Miller-Rabin probabilistic primality iterations to perform.
|
|
@@ -1573,23 +3284,24 @@ declare module 'crypto' {
|
|
|
1573
3284
|
*/
|
|
1574
3285
|
checks?: number | undefined;
|
|
1575
3286
|
}
|
|
1576
|
-
|
|
1577
3287
|
/**
|
|
1578
|
-
* Checks the primality of the candidate
|
|
3288
|
+
* Checks the primality of the `candidate`.
|
|
3289
|
+
* @since v15.8.0
|
|
3290
|
+
* @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
|
|
1579
3291
|
*/
|
|
1580
3292
|
function checkPrime(value: LargeNumberLike, callback: (err: Error | null, result: boolean) => void): void;
|
|
1581
3293
|
function checkPrime(value: LargeNumberLike, options: CheckPrimeOptions, callback: (err: Error | null, result: boolean) => void): void;
|
|
1582
|
-
|
|
1583
3294
|
/**
|
|
1584
|
-
* Checks the primality of the candidate
|
|
3295
|
+
* Checks the primality of the `candidate`.
|
|
3296
|
+
* @since v15.8.0
|
|
3297
|
+
* @param candidate A possible prime encoded as a sequence of big endian octets of arbitrary length.
|
|
3298
|
+
* @return `true` if the candidate is a prime with an error probability less than `0.25 ** options.checks`.
|
|
1585
3299
|
*/
|
|
1586
|
-
function checkPrimeSync(
|
|
1587
|
-
|
|
3300
|
+
function checkPrimeSync(candidate: LargeNumberLike, options?: CheckPrimeOptions): boolean;
|
|
1588
3301
|
namespace webcrypto {
|
|
1589
3302
|
class CryptoKey {} // placeholder
|
|
1590
3303
|
}
|
|
1591
3304
|
}
|
|
1592
|
-
|
|
1593
3305
|
declare module 'node:crypto' {
|
|
1594
3306
|
export * from 'crypto';
|
|
1595
3307
|
}
|