public
Created

RSA with no padding

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.