Method: OpenSSL::PKey::RSA#public_decrypt

Defined in:
lib/openssl/pkey.rb

#public_decrypt(string, padding = PKCS1_PADDING) ⇒ Object

:call-seq:

rsa.public_decrypt(string)          -> String
rsa.public_decrypt(string, padding) -> String

Decrypt string, which has been encrypted with the private key, with the public key. padding defaults to PKCS1_PADDING which is known to be insecure but is kept for backwards compatibility.

Deprecated in version 3.0. Consider using PKey::PKey#sign_raw and PKey::PKey#verify_raw, and PKey::PKey#verify_recover instead.


396
397
398
399
400
401
402
403
404
405
# File 'lib/openssl/pkey.rb', line 396

def public_decrypt(string, padding = PKCS1_PADDING)
  n or raise OpenSSL::PKey::RSAError, "incomplete RSA"
  begin
    verify_recover(nil, string, {
      "rsa_padding_mode" => translate_padding_mode(padding),
    })
  rescue OpenSSL::PKey::PKeyError
    raise OpenSSL::PKey::RSAError, $!.message
  end
end