toddr / Crypt-OpenSSL-RSA

Release history of Crypt-OpenSSL-RSA
https://metacpan.org/pod/Crypt::OpenSSL::RSA
Other
8 stars 25 forks source link

Build Status

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->encrypt($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));

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

BUGS

There is a small memory leak when generating new keys of more than 512 bits.

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)