Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
Create JWK representation of RSA key pair
node v18.11.0
version:
master
endpoint
share
tweet
Create RSA Key pair with DER format
const crypto = require('crypto'); // Generate a new RSA key pair const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', { modulusLength: 2048, publicKeyEncoding: { type: 'spki', format: 'der', }, privateKeyEncoding: { type: 'pkcs8', format: 'der', }, });
Creating JSON Web Keys using generated RSA key pairs. You need to provide unique Key Ids (kid) for your JWKs
// Create JWKs from generated keys const jwkPublicKey = { kty: 'RSA', alg: 'RS256', use: 'sig', kid: 'my-key-id', n: publicKey.toString('base64'), e: 'AQAB', }; const jwkPrivateKey = { kty: 'RSA', alg: 'RS256', use: 'sig', kid: 'my-key-id', n: publicKey.toString('base64'), e: 'AQAB', d: privateKey.toString('base64'), p: '', q: '', dp: '', dq: '', qi: '', };
Geneated JWK representations
console.log('Public JWK:', jwkPublicKey); console.log('Private JWK:', jwkPrivateKey);
Loading…
no comments
sign in
to comment