|
13 | 13 |
|
14 | 14 | </Stability> |
15 | 15 |
|
16 | | -<Metadata version="v16.19.1" data={{"source_link":"lib/crypto.js"}} /> |
| 16 | +<Metadata version="v16.20.1" data={{"source_link":"lib/crypto.js"}} /> |
17 | 17 |
|
18 | 18 | The `node:crypto` module provides cryptographic functionality that includes a |
19 | 19 | set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify |
@@ -954,12 +954,17 @@ If `outputEncoding` is given a string is returned; otherwise, a |
954 | 954 | * `encoding` [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) The [encoding][] of the return value. |
955 | 955 | * Returns: [`Buffer`](/api/v16/buffer#buffer) | [`string`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) |
956 | 956 |
|
957 | | -Generates private and public Diffie-Hellman key values, and returns |
| 957 | +Generates private and public Diffie-Hellman key values unless they have been |
| 958 | +generated or computed already, and returns |
958 | 959 | the public key in the specified `encoding`. This key should be |
959 | 960 | transferred to the other party. |
960 | 961 | If `encoding` is provided a string is returned; otherwise a |
961 | 962 | [`Buffer`][] is returned. |
962 | 963 |
|
| 964 | +This function is a thin wrapper around [`DH_generate_key()`][]. In particular, |
| 965 | +once a private key has been generated or set, calling this function only updates |
| 966 | +the public key but does not generate a new private key. |
| 967 | + |
963 | 968 | #### <DataTag tag="M" /> `diffieHellman.getGenerator([encoding])` |
964 | 969 |
|
965 | 970 | <Metadata data={{"update":{"type":"added","version":["v0.5.0"]}}} /> |
@@ -1016,6 +1021,10 @@ Sets the Diffie-Hellman private key. If the `encoding` argument is provided, |
1016 | 1021 | to be a string. If no `encoding` is provided, `privateKey` is expected |
1017 | 1022 | to be a [`Buffer`][], `TypedArray`, or `DataView`. |
1018 | 1023 |
|
| 1024 | +This function does not automatically compute the associated public key. Either |
| 1025 | +[`diffieHellman.setPublicKey()`][] or [`diffieHellman.generateKeys()`][] can be |
| 1026 | +used to manually provide the public key or to automatically derive it. |
| 1027 | + |
1019 | 1028 | #### <DataTag tag="M" /> `diffieHellman.setPublicKey(publicKey[, encoding])` |
1020 | 1029 |
|
1021 | 1030 | <Metadata data={{"update":{"type":"added","version":["v0.5.0"]}}} /> |
@@ -5094,6 +5103,7 @@ See the [list of SSL OP Flags][] for details. |
5094 | 5103 | [Web Crypto API documentation]: /api/v16/webcrypto |
5095 | 5104 | [`BN_is_prime_ex`]: https://www.openssl.org/docs/man1.1.1/man3/BN_is_prime_ex.html |
5096 | 5105 | [`Buffer`]: /api/v16/buffer |
| 5106 | +[`DH_generate_key()`]: https://www.openssl.org/docs/man3.0/man3/DH_generate_key.html |
5097 | 5107 | [`DiffieHellmanGroup`]: #class-diffiehellmangroup |
5098 | 5108 | [`EVP_BytesToKey`]: https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html |
5099 | 5109 | [`KeyObject`]: #class-keyobject |
@@ -5128,6 +5138,7 @@ See the [list of SSL OP Flags][] for details. |
5128 | 5138 | [`crypto.scrypt()`]: #cryptoscryptpassword-salt-keylen-options-callback |
5129 | 5139 | [`decipher.final()`]: #decipherfinaloutputencoding |
5130 | 5140 | [`decipher.update()`]: #decipherupdatedata-inputencoding-outputencoding |
| 5141 | +[`diffieHellman.generateKeys()`]: #diffiehellmangeneratekeysencoding |
5131 | 5142 | [`diffieHellman.setPublicKey()`]: #diffiehellmansetpublickeypublickey-encoding |
5132 | 5143 | [`ecdh.generateKeys()`]: #ecdhgeneratekeysencoding-format |
5133 | 5144 | [`ecdh.setPrivateKey()`]: #ecdhsetprivatekeyprivatekey-encoding |
|
0 commit comments