温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/crypto/generateKeyPair
点击访问原文链接

Node crypto.generateKeyPair function | API Reference | Bun

Node crypto.generateKeyPair function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:crypto/generateKeyPairNgenerateKeyPair

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:crypto/generateKeyPairNgenerateKeyPair

namespace

crypto.generateKeyPair { // Handle errors and use the generated key pair. }); ``` On completion, `callback` will be called with `err` set to `undefined` and `publicKey` / `privateKey` representing the generated key pair. If this method is invoked as its `util.promisify()` ed version, it returns a `Promise` for an `Object` with `publicKey` and `privateKey` properties." data-algolia-static="false" data-algolia-merged="true" data-type="Namespace">function generateKeyPairT extends DHKeyPairOptions>(type: 'dh',options: T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends DSAKeyPairOptions>(type: 'dsa',options: T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends ECKeyPairOptions>(type: 'ec',options: T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends ED25519KeyPairOptions = {}>(type: 'ed25519',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends ED448KeyPairOptions = {}>(type: 'ed448',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends MLDSAKeyPairOptions = {}>(type: 'ml-dsa-44' | 'ml-dsa-65' | 'ml-dsa-87',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends MLKEMKeyPairOptions = {}>(type: 'ml-kem-1024' | 'ml-kem-512' | 'ml-kem-768',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends RSAPSSKeyPairOptions>(type: 'rsa-pss',options: T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends RSAKeyPairOptions>(type: 'rsa',options: T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends SLHDSAKeyPairOptions = {}>(type: 'slh-dsa-sha2-128f' | 'slh-dsa-sha2-128s' | 'slh-dsa-sha2-192f' | 'slh-dsa-sha2-192s' | 'slh-dsa-sha2-256f' | 'slh-dsa-sha2-256s' | 'slh-dsa-shake-128f' | 'slh-dsa-shake-128s' | 'slh-dsa-shake-192f' | 'slh-dsa-shake-192s' | 'slh-dsa-shake-256f' | 'slh-dsa-shake-256s',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends X25519KeyPairOptions = {}>(type: 'x25519',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typefunction generateKeyPairT extends X448KeyPairOptions = {}>(type: 'x448',options: undefined | T,callback: KeyPairExportCallbackT>): void;

Generates a new asymmetric key pair of the given type. See the supported asymmetric key types.

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.

It is recommended to encode public keys as 'spki' and private keys as 'pkcs8' with encryption for long-term storage:

const {
generateKeyPair,
} = await import('node:crypto');

generateKeyPair('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: 'top secret',
},
}, (err, publicKey, privateKey) => {
// Handle errors and use the generated key pair.
});

On completion, callback will be called with err set to undefined and publicKey / privateKey representing the generated key pair.

If this method is invoked as its util.promisify() ed version, it returns a Promise for an Object with publicKey and privateKey properties.

@param typenamespace generateKeyPair

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node crypto.generateKeyPair function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for namespace node:crypto.generateKeyPair | Bun