in reply to crypt::openpgp encrypt error

As far as I understand it (which isn't very far), the recipients are expected to be specified by "id", and I believe that by default when you generate a key it picks the email address you specify to be the id.

Note also that recipients is plural, and normally expects an arrayref of recipients; I'm pretty sure though that this isn't your problem, that the code copes with a single recipient supplied in non-arrayref form.

Here is (roughly) the code I use for encryption, which fetches the key from elsewhere:

sub encrypt { my($proto, $target, $data) = @_; my $id = $target->email_address; my $key = $target->pgp_key; my $ring = Crypt::OpenPGP::KeyRing->new(Data => $key) or die "new KeyRing failed: $Crypt::OpenPGP::ErrorHandler: +:ERROR"; my $pgp = Crypt::OpenPGP->new(PubRing => $ring) or die "new Context failed: $Crypt::OpenPGP::ErrorHandler: +:ERROR"; $pgp->encrypt( Data => $data, Recipients => [ $id ], Armour => 1, ); }

However it took me a while to get there, and the maze of interconnected modules can be daunting to read through. Certainly I found it very helpful to install the modules to a personal installation of perl so I could safely stuff extra diagnostics directly into the modules to help explain what was going on.

One thing in particular you can do to check whether the recipient id can be found in the keyring looks something like this:

$ring->find_keyblock_by_uid($id) or die "Find keyblock failed: @{[ $ring->errstr ]}";

Hope this helps,

Hugo

Replies are listed 'Best First'.
Re: Re: crypt::openpgp encrypt error
by boat73 (Scribe) on Mar 16, 2004 at 23:59 UTC
    Thanks for the reply. Gets me that much closer