Hello all. I have been working on this much longer than I care to admit so I am sure I am missing something simple. I have created a public and private key file with Crypt::OpenPGP using the following code.
use Crypt::OpenPGP; $pgp = Crypt::OpenPGP->new (); %attrib = ( 'Type' => 'DSA', 'Size' => '1024', 'Identity' => 'Garett L Holmes <email address here>', '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);
That seems to create the files no problem but when I try to encrypt using the following code...
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, );<br> die "Encryption failed: ", $pgp->errstr unless $ciphertext; print $ciphertext;
I get this error
<code>"Encryption failed: No known recipients for encryption"<code>
I know the encrypt code works as I used it with another valid key file. Any help with this is appreciated.

Edited by BazB: fixed/added code tags. Removed email address.


In reply to crypt::openpgp encrypt error by boat73

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.