Correct subpath names that otherwise lead users to unexported entries, and fix examples, links, and missing descriptions in published JSDoc. Use instanceof in JWKS recovery examples so strict TypeScript can narrow caught errors. Signed-off-by: Filip Skokan <[email protected]>
1.7 KiB
Function: generateKeyPair()
💗 Help the project
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 a private and a public key for a given JWA algorithm identifier. This can only generate
asymmetric key pairs. For symmetric secrets use the generateSecret function.
Note
The
privateKeyis generated withextractableset tofalseby default. See GenerateKeyPairOptions.extractable to generate an extractableprivateKey.
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'.
Parameters
| 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. |
Returns
Promise<GenerateKeyPairResult>
Example
const { publicKey, privateKey } = await jose.generateKeyPair('PS256')
console.log(publicKey)
console.log(privateKey)