use Crypt::OpenPGP; $pgp = Crypt::OpenPGP->new (); %attrib = ( 'Type' => 'DSA', 'Size' => '1024', 'Identity' => 'Garett L Holmes ', 'Passphrase' => 'password', 'Cipher' => 'DES3', 'Verbosity' => '1' ); ($id, $email) = split("<", $attrib{Identity}); $id =~ s/\s+/_/g; chop $id; ($pubkey, $privkey) = $pgp->keygen( %attrib ) or die $pgp->errstr; $public = $pubkey->save; open(PUBLIC,">${id}.public") or die "COULD NOT OPEN ${id}_pub.pgp\n"; print PUBLIC $public; close(PUBLIC); $private = $privkey->save; open(PRIVATE,">${id}.private") or die "COULD NOT OPEN ${id}_priv.pgp\n"; print PRIVATE $private; close(PRIVATE); #### use Crypt::OpenPGP; my $pgp = Crypt::OpenPGP->new ( "PubRing" => 'pubring.pkr' )or die Crypt::OpenPGP->errstr; my $ciphertext = $pgp->encrypt ( "Compat" => 'PGP5', "Data" => 'this is a test', "Recipients" => 'Garett L Holmes', "Armour" => 1, );
die "Encryption failed: ", $pgp->errstr unless $ciphertext; print $ciphertext;