Posted on 2005-02-21 20:03:39-08 by ata in response to 139
Re: Help with Crypt::OpenPGP
OK, as usual when all else fails ignore the documentation and look at an example. This works. BTW, the process must of course have read access to the keyrings.
use strict; use CGI; use CGI::Carp 'fatalsToBrowser'; $CGI::POST_MAX= 10*1048; # max 10K byte posts $CGI::DISABLE_UPLOADS = 1; # no upload use Crypt::OpenPGP; use Crypt::OpenPGP::KeyRing; my $mailprog = "/usr/sbin/sendmail"; my $recipient = "test\@mydomain.com"; my $key_id = "05C1F245"; my $ring_file = '/home/mpo/.gnupg/pubring.gpg'; my $ring = Crypt::OpenPGP::KeyRing->new( Filename => $ring_file ) or die "Error: Crypt::OpenPGP::KeyRing->errstr"; my $pgp = Crypt::OpenPGP->new(PubRing => $ring); my $ciphertext = $pgp->encrypt( Data => "test 1234", Recipients => $key_id, Armour => 1, ); print $pgp->errstr; open (MAIL,"|$mailprog $recipient") || die "Unable to send email to $recipient."; print MAIL "$ciphertext\n"; close (MAIL); exit;
Direct Responses: 2614 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.