Created
October 25, 2019 01:16
-
-
Save markbrown4/649308219e06ded1d4e6fed73d627031 to your computer and use it in GitHub Desktop.
RSA Key Pair signing in Ruby
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
data = 'hello' | |
# generate signature and public key | |
private_key = OpenSSL::PKey::RSA.new(2048) | |
signature = private_key.sign(OpenSSL::Digest::SHA256.new, data) | |
public_key = private_key.public_key | |
# verify signature with public key | |
rsa_key = OpenSSL::PKey::RSA.new(public_key.to_pem) | |
rsa_key.verify(OpenSSL::Digest::SHA256.new, signature, data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment