Skip to content

DiffieHellmanGroup

[<Interface>]
type DiffieHellmanGroup =
    abstract member verifyError: float with get, set
    abstract member computeSecret (otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding: BinaryToTextEncoding) : string
    abstract member computeSecret (otherPublicKey: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, inputEncoding: obj, outputEncoding: BinaryToTextEncoding) : string
    abstract member computeSecret (otherPublicKey: string, inputEncoding: BinaryToTextEncoding, ?outputEncoding: unit) : NonSharedBuffer
    abstract member computeSecret (otherPublicKey: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, ?inputEncoding: unit, ?outputEncoding: unit) : NonSharedBuffer
    abstract member generateKeys (encoding: BinaryToTextEncoding) : string
    abstract member generateKeys () : NonSharedBuffer
    abstract member getGenerator (encoding: BinaryToTextEncoding) : string
    abstract member getGenerator () : NonSharedBuffer
    abstract member getPrime (encoding: BinaryToTextEncoding) : string
    abstract member getPrime () : NonSharedBuffer
    abstract member getPrivateKey (encoding: BinaryToTextEncoding) : string
    abstract member getPrivateKey () : NonSharedBuffer
    abstract member getPublicKey (encoding: BinaryToTextEncoding) : string
    abstract member getPublicKey () : NonSharedBuffer
AssemblyXantham.Fable.Node

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.h
modp1  #  768 bits
modp2  # 1024 bits
modp5  # 1536 bits
modp14 # 2048 bits
modp15 # etc.
modp16
modp17
modp18

@since v0.7.5

Properties

abstract member verifyError: float with get, set

A bit field containing any warnings and/or errors resulting from a check performed during initialization of the DiffieHellman object.

The following values are valid for this property (as defined in node:constants module):

  • DH_CHECK_P_NOT_SAFE_PRIME
  • DH_CHECK_P_NOT_PRIME
  • DH_UNABLE_TO_CHECK_GENERATOR
  • DH_NOT_SUITABLE_GENERATOR

@since v0.11.12

Methods

abstract member computeSecret (otherPublicKey: string, inputEncoding: BinaryToTextEncoding, outputEncoding: BinaryToTextEncoding) : string

Computes the shared secret using otherPublicKey as the other party's public key and returns the computed shared secret. The supplied key is interpreted using the specified inputEncoding, and secret is encoded using specified outputEncoding. If the inputEncoding is not provided, otherPublicKey is expected to be a Buffer, TypedArray, or DataView.

If outputEncoding is given a string is returned; otherwise, a Buffer is returned.

@since v0.5.0

Parameter
inputEncodingThe encoding of an otherPublicKey string.
outputEncodingThe encoding of the return value.
abstract member computeSecret (otherPublicKey: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, inputEncoding: obj, outputEncoding: BinaryToTextEncoding) : string

Computes the shared secret using otherPublicKey as the other party's public key and returns the computed shared secret. The supplied key is interpreted using the specified inputEncoding, and secret is encoded using specified outputEncoding. If the inputEncoding is not provided, otherPublicKey is expected to be a Buffer, TypedArray, or DataView.

If outputEncoding is given a string is returned; otherwise, a Buffer is returned.

@since v0.5.0

Parameter
inputEncodingThe encoding of an otherPublicKey string.
outputEncodingThe encoding of the return value.
abstract member computeSecret (otherPublicKey: string, inputEncoding: BinaryToTextEncoding, ?outputEncoding: unit) : NonSharedBuffer

Computes the shared secret using otherPublicKey as the other party's public key and returns the computed shared secret. The supplied key is interpreted using the specified inputEncoding, and secret is encoded using specified outputEncoding. If the inputEncoding is not provided, otherPublicKey is expected to be a Buffer, TypedArray, or DataView.

If outputEncoding is given a string is returned; otherwise, a Buffer is returned.

@since v0.5.0

Parameter
inputEncodingThe encoding of an otherPublicKey string.
outputEncodingThe encoding of the return value.
abstract member computeSecret (otherPublicKey: U12<BigInt64Array<U2<ArrayBuffer,SharedArrayBuffer>>,BigUint64Array<U2<ArrayBuffer,SharedArrayBuffer>>,DataView<U2<ArrayBuffer,SharedArrayBuffer>>,Float32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Float64Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Int8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint16Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint32Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>,Uint8ClampedArray<U2<ArrayBuffer,SharedArrayBuffer>>>, ?inputEncoding: unit, ?outputEncoding: unit) : NonSharedBuffer

Computes the shared secret using otherPublicKey as the other party's public key and returns the computed shared secret. The supplied key is interpreted using the specified inputEncoding, and secret is encoded using specified outputEncoding. If the inputEncoding is not provided, otherPublicKey is expected to be a Buffer, TypedArray, or DataView.

If outputEncoding is given a string is returned; otherwise, a Buffer is returned.

@since v0.5.0

Parameter
inputEncodingThe encoding of an otherPublicKey string.
outputEncodingThe encoding of the return value.
abstract member generateKeys (encoding: BinaryToTextEncoding) : 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. If encoding is provided a string is returned; otherwise a Buffer is 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.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member generateKeys () : NonSharedBuffer

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. If encoding is provided a string is returned; otherwise a Buffer is 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.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getGenerator (encoding: BinaryToTextEncoding) : string

Returns the Diffie-Hellman generator in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getGenerator () : NonSharedBuffer

Returns the Diffie-Hellman generator in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getPrime (encoding: BinaryToTextEncoding) : string

Returns the Diffie-Hellman prime in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getPrime () : NonSharedBuffer

Returns the Diffie-Hellman prime in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getPrivateKey (encoding: BinaryToTextEncoding) : string

Returns the Diffie-Hellman private key in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getPrivateKey () : NonSharedBuffer

Returns the Diffie-Hellman private key in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getPublicKey (encoding: BinaryToTextEncoding) : string

Returns the Diffie-Hellman public key in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.
abstract member getPublicKey () : NonSharedBuffer

Returns the Diffie-Hellman public key in the specified encoding. If encoding is provided a string is returned; otherwise a Buffer is returned.

@since v0.5.0

Parameter
encodingThe encoding of the return value.