Last active
January 23, 2025 15:58
-
-
Save joshcanhelp/a51d30256b988c9b1363f6ed19c1241b to your computer and use it in GitHub Desktop.
Generate a JWK-formatted private key in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { generateKeyPair } = require('jose/util/generate_key_pair'); | |
const { fromKeyLike } = require('jose/jwk/from_key_like'); | |
(async () => { | |
const { privateKey } = await generateKeyPair('RS256'); | |
const jwk = await fromKeyLike(privateKey); | |
console.log(JSON.stringify(jwk)); | |
})(); | |
// $ npm install jose | |
// $ node keygen.js | openssl base64 | tr -d '\n' | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/panva/jose/blob/main/docs/functions/util_generate_key_pair.generatekeypair.md
https://github.com/panva/jose/blob/main/docs/functions/jwk_from_key_like.fromkeylike.md