Skip to content

Instantly share code, notes, and snippets.

@silasb
Last active November 17, 2015 01:06
Show Gist options
  • Save silasb/5badd65981a00de7125c to your computer and use it in GitHub Desktop.
Save silasb/5badd65981a00de7125c to your computer and use it in GitHub Desktop.

Encrypt Data

echo "data-to-encrypt" | ./encrypt.rb | pbcopy -
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
public_key_file = 'public.pem'
string = ARGF.read
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
encrypted_string = Base64.encode64(public_key.public_encrypt(string))
print encrypted_string.split("\n").join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment