Skip to content

Instantly share code, notes, and snippets.

@markbrown4
Created October 25, 2019 01:16
Show Gist options
  • Save markbrown4/649308219e06ded1d4e6fed73d627031 to your computer and use it in GitHub Desktop.
Save markbrown4/649308219e06ded1d4e6fed73d627031 to your computer and use it in GitHub Desktop.
RSA Key Pair signing in Ruby
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