Created
December 17, 2010 23:02
-
-
Save DBA/745868 to your computer and use it in GitHub Desktop.
RSA with no padding
This file contains 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
# encoding: UTF-8 | |
require 'ruby-debug' | |
require 'openssl' | |
def crypt(value, padding = OpenSSL::PKey::RSA::NO_PADDING) | |
public_key = get_rsa_key 'public.pem' | |
public_key.public_encrypt value, padding | |
end | |
def get_rsa_key(key, password = '') | |
return key if key.is_a?(OpenSSL::PKey::RSA) | |
key = File.read(key) if key !~ /^-+BEGIN .* KEY-+$/ | |
return OpenSSL::PKey::RSA.new(key, password) | |
end | |
crypt 'xpto' #=> OpenSSL::PKey::RSAError Exception: data too small for key size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment