Created
October 28, 2019 22:24
-
-
Save pottedmeat7/a99d9f1170868070963971d44eee713c to your computer and use it in GitHub Desktop.
encrypts any string using openssl key and 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' | |
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