Skip to content
Create a gist now

Instantly share code, notes, and snippets.

RSA with no padding
# 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
def get_rsa_key(key, password = '')
return key if key.is_a?(OpenSSL::PKey::RSA)
key = if key !~ /^-+BEGIN .* KEY-+$/
return, password)
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
Something went wrong with that request. Please try again.