Skip to content

Instantly share code, notes, and snippets.

@mdp
Created December 10, 2008 18:05
Show Gist options
  • Save mdp/34425 to your computer and use it in GitHub Desktop.
Save mdp/34425 to your computer and use it in GitHub Desktop.
# OpenSSL RSA Cipher
# I always forget this, time to write it down
require "openssl"
require "base64"
private_key = OpenSSL::PKey::RSA.new(1024)
key = OpenSSL::PKey::RSA.new(private_key.public_key)
p enc = Base64.encode64(key.public_encrypt('mums the word'))
key = OpenSSL::PKey::RSA.new(private_key)
p key.private_decrypt(Base64.decode64(enc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment