function generateKeyPairSync
Overload 1
#generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Generates a new asymmetric key pair of the given type. RSA, RSA-PSS, DSA, EC,
Ed25519, Ed448, X25519, X448, and DH are currently supported.
If a publicKeyEncoding or privateKeyEncoding was specified, this function
behaves as if keyObject.export() had been called on its result. Otherwise,
the respective part of the key is returned as a KeyObject.
When encoding public keys, it is recommended to use 'spki'. When encoding
private keys, it is recommended to use 'pkcs8' with a strong passphrase,
and to keep the passphrase confidential.
const {
generateKeyPairSync,
} = await import('node:crypto');
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
});
The return value { publicKey, privateKey } represents the generated key pair.
When PEM encoding was selected, the respective key will be a string, otherwise
it will be a buffer containing the data encoded as DER.
Parameters #
#type: "rsa" Must be 'rsa', 'rsa-pss', 'dsa', 'ec', 'ed25519', 'ed448', 'x25519', 'x448', or 'dh'.
#options: RSAKeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 2
#generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "rsa" #options: RSAKeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 3
#generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "rsa" #options: RSAKeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 4
#generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "rsa" #options: RSAKeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 5
#generateKeyPairSync(type: "rsa",options: RSAKeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "rsa" #options: RSAKeyPairKeyObjectOptions Return Type #
Overload 6
#generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "rsa-pss" #options: RSAPSSKeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 7
#generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "rsa-pss" #options: RSAPSSKeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 8
#generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "rsa-pss" #options: RSAPSSKeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 9
#generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "rsa-pss" #options: RSAPSSKeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 10
#generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "rsa-pss" #options: RSAPSSKeyPairKeyObjectOptions Return Type #
Overload 11
#generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "dsa" #options: DSAKeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 12
#generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "dsa" #options: DSAKeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 13
#generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "dsa" #options: DSAKeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 14
#generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "dsa" #options: DSAKeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 15
#generateKeyPairSync(type: "dsa",options: DSAKeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "dsa" #options: DSAKeyPairKeyObjectOptions Return Type #
Overload 16
#generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "ec" #options: ECKeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 17
#generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "ec" #options: ECKeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 18
#generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "ec" #options: ECKeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 19
#generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "ec" #options: ECKeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 20
#generateKeyPairSync(type: "ec",options: ECKeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "ec" #options: ECKeyPairKeyObjectOptions Return Type #
Overload 21
#generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "ed25519" #options: ED25519KeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 22
#generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "ed25519" #options: ED25519KeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 23
#generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "ed25519" #options: ED25519KeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 24
#generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "ed25519" #options: ED25519KeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 25
#generateKeyPairSync(type: "ed25519",options?: ED25519KeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "ed25519" #options: ED25519KeyPairKeyObjectOptions Return Type #
Overload 26
#generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "ed448" #options: ED448KeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 27
#generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "ed448" #options: ED448KeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 28
#generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "ed448" #options: ED448KeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 29
#generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "ed448" #options: ED448KeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 30
#generateKeyPairSync(type: "ed448",options?: ED448KeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "ed448" #options: ED448KeyPairKeyObjectOptions Return Type #
Overload 31
#generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "x25519" #options: X25519KeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 32
#generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "x25519" #options: X25519KeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 33
#generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "x25519" #options: X25519KeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 34
#generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "x25519" #options: X25519KeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 35
#generateKeyPairSync(type: "x25519",options?: X25519KeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "x25519" #options: X25519KeyPairKeyObjectOptions Return Type #
Overload 36
#generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>Parameters #
#type: "x448" #options: X448KeyPairOptions<"pem", "pem"> Return Type #
KeyPairSyncResult<string, string> Overload 37
#generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>Parameters #
#type: "x448" #options: X448KeyPairOptions<"pem", "der"> Return Type #
KeyPairSyncResult<string, Buffer> Overload 38
#generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>Parameters #
#type: "x448" #options: X448KeyPairOptions<"der", "pem"> Return Type #
KeyPairSyncResult<Buffer, string> Overload 39
#generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>Parameters #
#type: "x448" #options: X448KeyPairOptions<"der", "der"> Return Type #
KeyPairSyncResult<Buffer, Buffer> Overload 40
#generateKeyPairSync(type: "x448",options?: X448KeyPairKeyObjectOptions,): KeyPairKeyObjectResultParameters #
#type: "x448" #options: X448KeyPairKeyObjectOptions