Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.3 KB

key_generate_key_pair.generateKeyPair.md

File metadata and controls

43 lines (32 loc) · 1.3 KB

Function: generateKeyPair

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: Under Web Cryptography API runtime the privateKey is generated with extractable set to false by default.

example Usage

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

example ESM import

import { generateKeyPair } from 'jose'

example CJS import

const { generateKeyPair } = require('jose')

example Deno import

import { generateKeyPair } from 'https://deno.land/x/jose@v4.1.1/index.ts'

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<GenerateKeyPairResult>