Method: OpenSSL::PKey::RSA#public_encrypt
- Defined in:
- lib/openssl/pkey.rb
#public_encrypt(data, padding = PKCS1_PADDING) ⇒ Object
:call-seq:
rsa.public_encrypt(string) -> String
rsa.public_encrypt(string, padding) -> String
Encrypt string
with the public key. padding
defaults to PKCS1_PADDING, which is known to be insecure but is kept for backwards compatibility. The encrypted string output can be decrypted using #private_decrypt.
Deprecated in version 3.0. Consider using PKey::PKey#encrypt and PKey::PKey#decrypt instead.
418 419 420 421 422 423 424 425 426 427 |
# File 'lib/openssl/pkey.rb', line 418 def public_encrypt(data, padding = PKCS1_PADDING) n or raise OpenSSL::PKey::RSAError, "incomplete RSA" begin encrypt(data, { "rsa_padding_mode" => translate_padding_mode(padding), }) rescue OpenSSL::PKey::PKeyError raise OpenSSL::PKey::RSAError, $!. end end |