info > Crypt::OpenSSL::RSA

📖 NAME

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

🚀 Quick Reference

Use CaseCommandDescription
🔑 Generate key pair$rsa = Crypt::OpenSSL::RSA->generate_key(1024);Generate a new RSA key pair with 1024-bit key size
🔒 Encrypt with public key$ciphertext = $rsa_pub->encrypt($plaintext);Encrypt using public key (PKCS1_OAEP padding by default)
🔓 Decrypt with private key$plaintext = $rsa_priv->decrypt($ciphertext);Decrypt using private key
✍️ Sign data$signature = $rsa_priv->sign($data);Sign with private key (SHA-256 by default)
✔️ Verify signature$rsa_pub->verify($data, $signature);Verify signature with public key
📤 Get public key string$rsa->get_public_key_string();Get PKCS1 Base64/DER public key
📤 Get private key string$rsa->get_private_key_string();Get PKCS1 Base64/DER private key

📝 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);
$rsa_pub->use_sslv23_padding(); # use_pkcs1_oaep_padding is the default
$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 AT cpan.org". For support, please email "perl-openssl-users AT lists.net".

🙏 ACKNOWLEDGEMENTS

(empty)

⚖️ 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)

Crypt::OpenSSL::RSA
📖 NAME 🚀 Quick Reference 📝 SYNOPSIS 📄 DESCRIPTION
🔧 Class Methods ⚙️ Instance Methods
🐛 BUGS 👤 AUTHOR 🙏 ACKNOWLEDGEMENTS ⚖️ LICENSE 📚 SEE ALSO

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-16 09:33 @2600:1f28:365:80b0:7cb9:fb:26c1:e368
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!