Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created January 30, 2019 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/90067d0e37353f0e8dc5a0dfc7868952 to your computer and use it in GitHub Desktop.
Save havenwood/90067d0e37353f0e8dc5a0dfc7868952 to your computer and use it in GitHub Desktop.
rsa_private = OpenSSL::PKey::RSA.generate 2048
rsa_public = rsa_private.public_key
File.write 'jwt-key.pub', rsa_public
secret = {'sekret' => 'Cicadoidea'}
payload = JWT.encode secret, rsa_private, 'RS256'
pub = File.read 'jwt-key.pub'
rsa_public_key = OpenSSL::PKey::RSA.new pub
decrypted_payload, _ = JWT.decode payload, rsa_public_key, true, {algorithm: 'RS256'}
decrypted_payload
#=> {"sekret"=>"Cicadoidea"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment