An alias for getDiffieHellman
function
crypto.createDiffieHellmanGroup
Referenced types
class DiffieHellmanGroup
The DiffieHellmanGroup class takes a well-known modp group as its argument. It works the same as DiffieHellman, except that it does not allow changing its keys after creation. In other words, it does not implement setPublicKey() or setPrivateKey() methods.
const { createDiffieHellmanGroup } = await import('node:crypto');
const dh = createDiffieHellmanGroup('modp1');
The name (e.g. 'modp1') is taken from RFC 2412 (modp1 and 2) and RFC 3526:
perl -ne 'print "$1\n" if /"(modp\d+)"/' src/node_crypto_groups.hmodp1 # 768 bits
modp2 # 1024 bits
modp5 # 1536 bits
modp14 # 2048 bits
modp15 # etc.
modp16
modp17
modp18- verifyError: number
A bit field containing any warnings and/or errors resulting from a check performed during initialization of the
DiffieHellmanobject.The following values are valid for this property (as defined in
node:constantsmodule):DH_CHECK_P_NOT_SAFE_PRIMEDH_CHECK_P_NOT_PRIMEDH_UNABLE_TO_CHECK_GENERATORDH_NOT_SUITABLE_GENERATOR
- inputEncoding?: BufferEncoding): NonSharedBuffer;
Computes the shared secret using
otherPublicKeyas the other party's public key and returns the computed shared secret. The supplied key is interpreted using the specifiedinputEncoding, and secret is encoded using specifiedoutputEncoding. If theinputEncodingis not provided,otherPublicKeyis expected to be aBuffer,TypedArray, orDataView.If
outputEncodingis given a string is returned; otherwise, aBufferis returned.@param inputEncodingThe
encodingof anotherPublicKeystring.inputEncoding: undefined | null | BufferEncoding,outputEncoding: BufferEncoding): string;Computes the shared secret using
otherPublicKeyas the other party's public key and returns the computed shared secret. The supplied key is interpreted using the specifiedinputEncoding, and secret is encoded using specifiedoutputEncoding. If theinputEncodingis not provided,otherPublicKeyis expected to be aBuffer,TypedArray, orDataView.If
outputEncodingis given a string is returned; otherwise, aBufferis returned.@param inputEncodingThe
encodingof anotherPublicKeystring.@param outputEncodingThe
encodingof the return value. Generates private and public Diffie-Hellman key values unless they have been generated or computed already, and returns the public key in the specified
encoding. This key should be transferred to the other party. Ifencodingis provided a string is returned; otherwise aBufferis returned.This function is a thin wrapper around
DH_generate_key(). In particular, once a private key has been generated or set, calling this function only updates the public key but does not generate a new private key.encoding: BufferEncoding): string;Generates private and public Diffie-Hellman key values unless they have been generated or computed already, and returns the public key in the specified
encoding. This key should be transferred to the other party. Ifencodingis provided a string is returned; otherwise aBufferis returned.This function is a thin wrapper around
DH_generate_key(). In particular, once a private key has been generated or set, calling this function only updates the public key but does not generate a new private key.@param encodingThe
encodingof the return value.Returns the Diffie-Hellman generator in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.encoding: BufferEncoding): string;Returns the Diffie-Hellman generator in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.@param encodingThe
encodingof the return value.Returns the Diffie-Hellman prime in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.encoding: BufferEncoding): string;Returns the Diffie-Hellman prime in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.@param encodingThe
encodingof the return value.Returns the Diffie-Hellman private key in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.encoding: BufferEncoding): string;Returns the Diffie-Hellman private key in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.@param encodingThe
encodingof the return value.Returns the Diffie-Hellman public key in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.encoding: BufferEncoding): string;Returns the Diffie-Hellman public key in the specified
encoding. Ifencodingis provided a string is returned; otherwise aBufferis returned.@param encodingThe
encodingof the return value.