Last active
March 16, 2016 16:18
-
-
Save rwjblue/5922584 to your computer and use it in GitHub Desktop.
Public-key encryption with Ruby.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'base64' | |
ciphertext = Base64.decode64("CIPHERTEXT GOES HERE") | |
passphrase = ENV['PRIVATE_KEY_PASSPHRASE'] # read in from environment | |
private_key = OpenSSL::PKey::RSA.new(File.read('path/to/private_key.pem'), passphrase) | |
plaintext = private_key.private_decrypt(ciphertext, OpenSSL::PKey::RSA::PKCS1_PADDING) | |
puts "Plain text is: " + plaintext |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'base64' | |
public_key = OpenSSL::PKey::RSA.new(File.read('path/to/public_key.pem'), '') | |
ciphertext = public_key.public_encrypt(plaintext, OpenSSL::PKey::RSA::PKCS1_PADDING) | |
ciphertext = Base64.encode64(ciphertext) | |
puts "Encrypted text is: " + ciphertext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment