in reply to Crypt::OpenPGP, encrypting messages using a public key file
The user id is typically the email address for which the PGP key was generated. Here's the code I use, which targets someone for whom I have a PGP public key block and an email address:
sub encrypt { my($proto, $target, $data) = @_; my $id = $target->email; my $key = $target->pgp_key; my $ring = Crypt::OpenPGP::KeyRing->new(Data => $key) or $proto->error("new user KeyRing failed"); my $pgp = Crypt::OpenPGP->new(PubRing => $ring) or $proto->error("new Context failed"); my $kb = $ring->find_keyblock_by_uid($id) or $proto->error("find user keyblock failed", $ring); my $alg = $kb->preferred_sk_alg; $pgp->encrypt( Data => $data, Recipients => [ $id ], Armour => 1, ($alg ? (Cipher => $alg) : ()), # use default if no preference + located ); }
Note that this is also using Crypt::OpenPGP - finding and using preferred SK algorithm to get an appropriate encryption mechanism.
Hugo
|
|---|