Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Last active November 2, 2023 10:13
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save max-mapper/62b7119909a93204c747633308a4d769 to your computer and use it in GitHub Desktop.
Save max-mapper/62b7119909a93204c747633308a4d769 to your computer and use it in GitHub Desktop.
generate ES512 and RS256 elliptic curve keypairs for JWT JWK (JSON Web Token JSON Web Key) using openssl
# RS256
# private key
openssl genrsa -out rs256-4096-private.rsa 4096
# public key
openssl rsa -in rs256-4096-private.rsa -pubout > rs256-4096-public.pem
# ES512
# private key
openssl ecparam -genkey -name secp521r1 -noout -out ecdsa-p521-private.pem
# public key
openssl ec -in ecdsa-p521-private.pem -pubout -out ecdsa-p521-public.pem
// from npmjs.org/jwa. shout out to brianloveswords
const fs = require('fs');
const jwa = require('jwa');
const privateKey = fs.readFileSync(__dirname + '/ecdsa-p521-private.pem');
const publicKey = fs.readFileSync(__dirname + '/ecdsa-p521-public.pem');
const ecdsa = jwa('ES512');
const input = 'very important stuff';
const signature = ecdsa.sign(input, privateKey);
console.log('signature', signature)
console.log('verify', ecdsa.verify(input, signature, publicKey))
@max-mapper
Copy link
Author

max-mapper commented Nov 23, 2016

hmm, ES512 does not work with browserify :(

Error: wrong private key type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment