docs/key/generate_key_pair/functions/generateKeyPair.md
Support from the community to continue maintaining and improving this module is welcome. If you find the module useful, please consider supporting the project by becoming a sponsor.
āø generateKeyPair(alg, options?): Promise<GenerateKeyPairResult>
Generates an asymmetric key pair for a JWA algorithm identifier.
For symmetric secrets use the generateSecret function.
[!NOTE]
Private keys are not extractable by default. Set GenerateKeyPairOptions.extractable to export them; public keys are always extractable.
This function is exported (as a named export) from the main 'jose' module entry point as well
as from its subpath export 'jose/key/generate/keypair'.
| Parameter | Type | Description |
|---|---|---|
alg | string | JWA Algorithm Identifier to be used with the generated key pair. See Algorithm Key Requirements. |
options? | GenerateKeyPairOptions | Additional options passed down to the key pair generation. |
Promise<GenerateKeyPairResult>
const { publicKey, privateKey } = await jose.generateKeyPair('PS256')
console.log(publicKey)
console.log(privateKey)