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


In reply to Re: Crypt::OpenPGP, encrypting messages using a public key file by edoc
in thread Crypt::OpenPGP, encrypting messages using a public key file by BUU

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.