testsuite

NAME

Crypt::OpenSSL::RSA - RSA encoding and decoding, using the openSSL libraries

SYNOPSIS

use Crypt::OpenSSL::Random;
use Crypt::OpenSSL::RSA;

# not necessary if we have /dev/random:
Crypt::OpenSSL::Random::random_seed($good_entropy);
Crypt::OpenSSL::RSA->import_random_seed();
$rsa_pub = Crypt::OpenSSL::RSA->new_public_key($key_string);
$ciphertext = $rsa->encrypt($plaintext);

$rsa_priv = Crypt::OpenSSL::RSA->new_private_key($key_string);
$plaintext = $rsa->decrypt($ciphertext);

$rsa = Crypt::OpenSSL::RSA->generate_key(1024); # or
$rsa = Crypt::OpenSSL::RSA->generate_key(1024, $prime);

print "private key is:\n", $rsa->get_private_key_string();
print "public key (in PKCS1 format) is:\n",
      $rsa->get_public_key_string();
print "public key (in X509 format) is:\n",
      $rsa->get_public_key_x509_string();

$rsa_priv->use_md5_hash(); # insecure. use_sha256_hash or use_sha1_hash are the default
$signature = $rsa_priv->sign($plaintext);
print "Signed correctly\n" if ($rsa->verify($plaintext, $signature));

SECURITY

Version 0.35 disabled PKCS#1 v1.5 padding entirely to mitigate the Marvin attack. However, the Marvin attack only affects PKCS#1 v1.5 decryption (padding oracle), not signatures. Version 0.38 re-enables use_pkcs1_padding() for use with sign() and verify(), while keeping it disabled for encrypt() and decrypt(). PKCS1_OAEP should be used for encryption and either PKCS1_PSS or PKCS1 can be used for signing.

DESCRIPTION

Crypt::OpenSSL::RSA provides the ability to RSA encrypt strings which are somewhat shorter than the block size of a key. It also allows for decryption, signatures and signature verification.

NOTE: Many of the methods in this package can croak, so use eval, or Error.pm's try/catch mechanism to capture errors. Also, while some methods from earlier versions of this package return true on success, this (never documented) behavior is no longer the case.

Class Methods

Instance Methods

Padding Methods

use_pkcs1_padding can be used for signature operations (sign() and verify()). PKCS#1 v1.5 encryption is disabled due to the Marvin attack. use_pkcs1_pss_padding is the recommended replacement for signatures. use_pkcs1_oaep_padding is used for encryption operations.

On OpenSSL 3.x, the appropriate padding is set for each operation unless use_no_padding or use_pkcs1_padding is called before the operation.

Hash/Digest Methods

AUTHOR

Ian Robertson, iroberts@cpan.org. For support, please email perl-openssl-users@lists.sourceforge.net.

ACKNOWLEDGEMENTS

LICENSE

Copyright (c) 2001-2011 Ian Robertson. Crypt::OpenSSL::RSA is free software; you may redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl(1), Crypt::OpenSSL::Random, Crypt::OpenSSL::Bignum, rsa(3), RSA_new(3), RSA_public_encrypt(3), RSA_size(3), RSA_generate_key(3), RSA_check_key(3)