MgenerateKeys
Bun

method

crypto.DiffieHellman.generateKeys

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 recomputes the public key from the existing private key. Since the public key is determined by the private key, the result will be the same unless the private key has been changed via diffieHellman.setPrivateKey().

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. 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 recomputes the public key from the existing private key. Since the public key is determined by the private key, the result will be the same unless the private key has been changed via diffieHellman.setPrivateKey().

@param encoding

The encoding of the return value.