Skip to content

Instantly share code, notes, and snippets.

@pottedmeat7
Created October 28, 2019 22:24
Show Gist options
  • Save pottedmeat7/a99d9f1170868070963971d44eee713c to your computer and use it in GitHub Desktop.
Save pottedmeat7/a99d9f1170868070963971d44eee713c to your computer and use it in GitHub Desktop.
encrypts any string using openssl key and ruby
require 'openssl'
require 'base64'
public_key_file = 'pubkey.pem';
string = ""
File.open(ARGV[0]).each_line do |line|
string += line
end
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
encrypted_string = Base64.encode64(public_key.public_encrypt(string))
puts encrypted_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment