Skip to content

Instantly share code, notes, and snippets.

@darkredz
Forked from Holger-Will/jwtRS256.sh
Created August 25, 2023 11:08
Show Gist options
  • Save darkredz/210b5e4d95d61e33aaba680c3f30d7da to your computer and use it in GitHub Desktop.
Save darkredz/210b5e4d95d61e33aaba680c3f30d7da to your computer and use it in GitHub Desktop.
generate public private key pair (RSA RS256) for use with koa-jwt jasonwebtoken etc.
# generate private key
openssl genrsa -out private.pem 2048
# extatract public key from it
openssl rsa -in private.pem -pubout > public.pem
const jwt2 = require('jsonwebtoken');
const fs = require("fs")
const public_key = fs.readFileSync('public.pem');
const private_key = fs.readFileSync('private.pem');
var token=jwt2.sign({"user":"me"},private_key, { algorithm: 'RS256'})
var res = jwt2.verify(token, public_key, { algorithm: 'RS256'})
console.log(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment