Skip to content

Instantly share code, notes, and snippets.

@mudge
Created February 9, 2010 10:13
Show Gist options
  • Select an option

  • Save mudge/299067 to your computer and use it in GitHub Desktop.

Select an option

Save mudge/299067 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'base64'
def encrypt_rsa_and_base64_encode(message, public_key_filename)
# Use open mode 'rb' for Windows compatibility.
public_key = OpenSSL::PKey::RSA.new(File.open(public_key_filename, 'rb') { |f| f.read })
Base64.encode64(public_key.public_encrypt(message))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment