Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Forked from Holger-Will/jwtRS256.sh
Created March 4, 2023 19:06
Show Gist options
  • Select an option

  • Save andersonbosa/16ece55e7f496b2b569b263807afb3e5 to your computer and use it in GitHub Desktop.

Select an option

Save andersonbosa/16ece55e7f496b2b569b263807afb3e5 to your computer and use it in GitHub Desktop.

Revisions

  1. @Holger-Will Holger-Will revised this gist Jul 9, 2017. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions jwtRS256.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    # generate private key
    openssl genrsa -out private.pem 2048
    # extatract public key from it
    openssl rsa -in private.pem -pubout > public.pem
    # use private.pem in jwt.sign
    # and public.pem in jwt.verify
    openssl rsa -in private.pem -pubout > public.pem
  2. @Holger-Will Holger-Will revised this gist Jul 9, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion testkeys.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    const jwt2 = require('jsonwebtoken');
    const fs = require("fs")
    const public_key = fs.readFileSync('public.pub');
    const public_key = fs.readFileSync('public.pem');
    const private_key = fs.readFileSync('private.pem');

    var token=jwt2.sign({"user":"me"},private_key, { algorithm: 'RS256'})
  3. @Holger-Will Holger-Will created this gist Jul 9, 2017.
    6 changes: 6 additions & 0 deletions jwtRS256.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    # generate private key
    openssl genrsa -out private.pem 2048
    # extatract public key from it
    openssl rsa -in private.pem -pubout > public.pem
    # use private.pem in jwt.sign
    # and public.pem in jwt.verify
    8 changes: 8 additions & 0 deletions testkeys.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    const jwt2 = require('jsonwebtoken');
    const fs = require("fs")
    const public_key = fs.readFileSync('public.pub');
    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)