Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
OpenSSL::PKey::RSA#public_encrypt
(::String data, ?::Integer padding) -> ::String
rsa.public_encrypt(string) → String
rsa.public_encrypt(string, padding) → String
ext/openssl/lib/openssl/pkey.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ext/openssl/lib/openssl/pkey.rb, line 448
def public_encrypt(data, padding = PKCS1_PADDING)
n or raise PKeyError, "incomplete RSA"
encrypt(data, {
"rsa_padding_mode" => translate_padding_mode(padding),
})
end
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.
See also
#public_decrypt
#public_key
#public?
#set_crt_params
also in
4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0