Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Crypt::OpenPGP, encrypting messages using a public key file

by hv (Prior)
on Jan 12, 2006 at 09:58 UTC ( [id://522656]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://522656]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-25 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found