Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active February 5, 2019 22:26
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/e51db7a7fdb05b57100de17e5cf5ee84 to your computer and use it in GitHub Desktop.
Save havenwood/e51db7a7fdb05b57100de17e5cf5ee84 to your computer and use it in GitHub Desktop.
Example twisted Edwards curves digital signatures with JWTs.
# gem install jwt rbnacl
require 'jwt'
require 'securerandom'
payload = {
'signed' => 'Cicadoidea'
}
##
# Sign your payload.
signing_key = RbNaCl::Signatures::Ed25519::SigningKey.new SecureRandom.bytes 32
signature = signing_key.to_bytes # Save your signature to sign other things.
password = signing_key.verify_key.to_bytes # Use your password to authenticate.
signed_payload = JWT.encode payload, signing_key, 'ED25519' # Share the signed payload.
##
# Authenticate your signed payload.
verify_key = RbNaCl::Signatures::Ed25519::VerifyKey.new password
authenticated_payload, _ = JWT.decode signed_payload, verify_key, true, {algorithm: 'ED25519'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment