jeanluca has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks

Using the doc from cpan I was able to construct the following script:
#! /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)) +;
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 ?

Cheers
LuCa

UPDATE: I solved it with RSA:
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
    ... google for "gpg tutorial"..... then once you figure out how keys work, you can use something like this GnuPG example with with your keys.... search CPAN for other modules for GpG too.... some work better than others for different platforms
    #!/usr/bin/perl use warnings; use strict; use GnuPG; # where you find your default keys, or you can specify an exact key # get a tutorial, it's alot to explain my $gpg = new GnuPG(homedir => '/home/z/.gnupg'); $gpg->encrypt(plaintext =>"Gnufile.txt", output => "Gnufile.gpg", recipient =>"z\@z.net", armor=> 1, ); exit;
    .... then you can mail off your secret file to anyone you want, and there are more details like clearsigning it, ...... it goes on and on ad infinitum in the spy vs. spy game :-)

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku