function generateKeyPairSync
Usage in Deno
import { generateKeyPairSync } from "node:crypto";
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.
options: RSAKeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: RSAKeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: RSAKeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "rsa",options: RSAKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: RSAKeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "rsa",options: RSAKeyPairKeyObjectOptions,): KeyPairKeyObjectResult
options: RSAKeyPairKeyObjectOptions
generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: RSAPSSKeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: RSAPSSKeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: RSAPSSKeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: RSAPSSKeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "rsa-pss",options: RSAPSSKeyPairKeyObjectOptions,): KeyPairKeyObjectResult
options: RSAPSSKeyPairKeyObjectOptions
generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: DSAKeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: DSAKeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: DSAKeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "dsa",options: DSAKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: DSAKeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "dsa",options: DSAKeyPairKeyObjectOptions,): KeyPairKeyObjectResult
options: DSAKeyPairKeyObjectOptions
generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: ECKeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: ECKeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: ECKeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "ec",options: ECKeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: ECKeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "ec",options: ECKeyPairKeyObjectOptions,): KeyPairKeyObjectResult
options: ECKeyPairKeyObjectOptions
generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: ED25519KeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: ED25519KeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: ED25519KeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "ed25519",options: ED25519KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: ED25519KeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "ed25519",options?: ED25519KeyPairKeyObjectOptions,): KeyPairKeyObjectResult
optional
options: ED25519KeyPairKeyObjectOptions
generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: ED448KeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: ED448KeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: ED448KeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "ed448",options: ED448KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: ED448KeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "ed448",options?: ED448KeyPairKeyObjectOptions,): KeyPairKeyObjectResult
optional
options: ED448KeyPairKeyObjectOptions
generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: X25519KeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: X25519KeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: X25519KeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "x25519",options: X25519KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: X25519KeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "x25519",options?: X25519KeyPairKeyObjectOptions,): KeyPairKeyObjectResult
optional
options: X25519KeyPairKeyObjectOptions
generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"pem", "pem">,): KeyPairSyncResult<string, string>
options: X448KeyPairOptions<"pem", "pem">
KeyPairSyncResult<string, string>
generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"pem", "der">,): KeyPairSyncResult<string, Buffer>
options: X448KeyPairOptions<"pem", "der">
KeyPairSyncResult<string, Buffer>
generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"der", "pem">,): KeyPairSyncResult<Buffer, string>
options: X448KeyPairOptions<"der", "pem">
KeyPairSyncResult<Buffer, string>
generateKeyPairSync(type: "x448",options: X448KeyPairOptions<"der", "der">,): KeyPairSyncResult<Buffer, Buffer>
options: X448KeyPairOptions<"der", "der">
KeyPairSyncResult<Buffer, Buffer>
generateKeyPairSync(type: "x448",options?: X448KeyPairKeyObjectOptions,): KeyPairKeyObjectResult
optional
options: X448KeyPairKeyObjectOptions