Last active
February 5, 2019 22:26
-
-
Save havenwood/e51db7a7fdb05b57100de17e5cf5ee84 to your computer and use it in GitHub Desktop.
Example twisted Edwards curves digital signatures with JWTs.
This file contains 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
# 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