Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Crypt::OpenPGP, encrypting messages using a public key file

by edoc (Chaplain)
on Jan 12, 2006 at 02:44 UTC ( #522604=note: print w/replies, xml ) Need Help??


in reply to Crypt::OpenPGP, encrypting messages using a public key file

When your public key was generated it would have had an 'Identity'. You want to use this (or part of it) as the 'Recipients'.
#!/usr/bin/perl use strict; use warnings; # generate public/private Crypt::OpenPGP keys. # encrypt some data # decrypt some data use Crypt::OpenPGP; my $size = 1024; my $ident = 'Me <me@example.com>'; my $pass = 'my passphrase'; my $public_file = 'public.pgp'; my $private_file = 'private.pgp'; my $keychain = Crypt::OpenPGP->new; my ($public, $private) = $keychain->keygen ( Type => 'RSA', Size => $size, Identity => $ident, Passphrase => $pass, Verbosity => 1, ) or die $keychain->errstr( +); my $public_str = $public->save; my $private_str = $private->save; print "Public encrypting_key: ".$public->encrypting_key ."\n"; print "Private encrypting_key: ".$private->encrypting_key ."\n"; open( PUB, '>', $public_file ) or die $!; print PUB $public_str; close(PUB); open( PRIV, '>', $private_file ) or die $!; print PRIV $private_str; close(PRIV); my $pgp = Crypt::OpenPGP->new( PubRing => $public_file ); my $cyphertext = $pgp->encrypt ( Data => 'Encrypt This', Recipients => $ident, Armour => 1, ) || die $pgp->errstr(); print $cyphertext; $pgp = new Crypt::OpenPGP( SecRing => $private_file ); my $plaintext = $pgp->decrypt ( Data => $cyphertext, Passphrase => $pass, ) || die $pgp->errstr(); print "plaintext: $plaintext\n";

cheers,

J

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://522604]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-01-28 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?