Skip to content

Instantly share code, notes, and snippets.

@mrbitsdcf
Created October 22, 2013 12:28
Show Gist options
  • Save mrbitsdcf/7099745 to your computer and use it in GitHub Desktop.
Save mrbitsdcf/7099745 to your computer and use it in GitHub Desktop.
Using PGP assyncronous keys to encrypt data in Ruby
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
public_key_file = '/path/to/key.pem';
string = 'Hello World!';
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
encrypted_string = Base64.encode64(public_key.public_encrypt(string))
print encrypted_string, "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment