Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/jose/util/generate_key_pair.ts>generateKeyPair

"JSON Web Almost Everything" - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto in Node.js, Browser, Cloudflare Workers, Electron, and Deno.
Extremely Popular
Go to Latest
function generateKeyPair
import { generateKeyPair } from "https://deno.land/x/jose@v3.20.4/util/generate_key_pair.ts";

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.

Examples

ESM import

import { generateKeyPair } from 'jose/util/generate_key_pair'

CJS import

const { generateKeyPair } = require('jose/util/generate_key_pair')

Deno import

import { generateKeyPair } from 'https://deno.land/x/jose@VERSION/util/generate_key_pair.ts'

Usage

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

Parameters

alg: string

JWA Algorithm Identifier to be used with the generated key pair.

optional
options: GenerateKeyPairOptions

Additional options passed down to the key pair generation.