jose/docs/functions/_util_generate_key_pair_.generatekeypair.md
2020-12-14 16:43:16 +01:00

1.3 KiB

Function: generateKeyPair

generateKeyPair(alg: string, options?: GenerateKeyPairOptions): Promise<{ privateKey: CryptoKey | KeyObject ; publicKey: CryptoKey | KeyObject }>

Defined in src/util/generate_key_pair.ts:47

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.

example

// ESM import
import generateKeyPair from 'jose/util/generate_key_pair'

example

// CJS import
const { default: generateKeyPair } = require('jose/util/generate_key_pair')

example

// usage
const { publicKey, privateKey } = await generateKeyPair('PS256')
console.log(publicKey)
console.log(privateKey)

Parameters:

Name Type Description
alg string JWA Algorithm Identifier to be used with the generated key pair.
options? GenerateKeyPairOptions Additional options passed down to the key pair generation.

Returns: Promise<{ privateKey: CryptoKey | KeyObject ; publicKey: CryptoKey | KeyObject }>