-
-
Save austonpramodh/0aced7a045f65b52ab72d84f57f0ab74 to your computer and use it in GitHub Desktop.
generate public private key pair (RSA RS256) for use with koa-jwt jasonwebtoken etc.
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
| # generate private key | |
| openssl genrsa -out jwtRS256.key 2048 | |
| # extatract public key from it | |
| openssl rsa -in jwtRS256.key -pubout > jwtRS256.key.pub |
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 jwt2 = require('jsonwebtoken'); | |
| const fs = require("fs") | |
| const public_key = fs.readFileSync('jwtRS256.key.pub'); | |
| const private_key = fs.readFileSync('jwtRS256.key'); | |
| 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