Method: OpenSSL::PKey::RSA#private_encrypt

Defined in:
lib/openssl/pkey.rb

#private_encrypt(string, padding = PKCS1_PADDING) ⇒ Object

:call-seq:

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

Encrypt string with the private 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 #public_decrypt.

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



373
374
375
376
377
378
379
380
381
382
383
# File 'lib/openssl/pkey.rb', line 373

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