jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
So, I've generated $rsa, which can give me a private/public key as a string. The question is, how do I encrypt and decrypt using ?#! /usr/bin/perl use Crypt::OpenSSL::Random; use Crypt::OpenSSL::RSA; use Data::Dumper ; my $rsa = Crypt::OpenSSL::RSA->generate_key(1024); # or 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(); # use_sha1_hash is the default #$signature = $rsa_priv->sign($plaintext); #print "Signed correctly\n" if ($rsa->verify($plaintext, #$signature)) +;
my $rsa = Crypt::OpenSSL::RSA->generate_key(2048); # or my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($rsa->get_private_ +key_string() ); my $rsa_pub = Crypt::OpenSSL::RSA->new_public_key( $rsa->get_public_ke +y_string() ); my $ciphertext = $rsa_pub->encrypt($plaintext) ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: encrypt and decrypt with crypt::OpenSSL::RSA
by zentara (Cardinal) on Dec 02, 2009 at 12:25 UTC |