http://qs321.pair.com?node_id=959324


in reply to Getting Started with GnuPG and GPG

OK, I have been banging my head over the last little while trying to get GPG working through PERL and finally came across this gem of a tutorial. Thank you!

My only issue is that I still cannot get it to work. In an attempt to emulate the tutorial on my machine, I created two scripts trialencode and trialdecode, listed here

################# ## trialencode ## ################# use strict; use GPG; my $gpg = new GPG(homedir => '/home/jaf/.gnupg'); my $plain="ARGHH!!"; my $phrase=$gpg->encrypt($plain,"jaf0faj\@xxxxxxx"); die $gpg->error() if $gpg->error(); print "Plain: $plain\n\nEncoded:\n$phrase\n"; open (OUT, ">trialencoded"); print OUT $phrase; close (OUT);
################# ## trialdecode ## ################# use strict; use GPG; my $gpg = new GPG(homedir => '/home/jaf/.gnupg'); open (IN, "trialencoded"); my $phrase=join("",<IN>); close(IN); my $message=$gpg->decrypt('HtfdIggtw?',$phrase); print "\n==========================\n\nEncoded:\n$phrase\n\nDecoded: [ +$message]\n"; print "\n\n\$gpg->error message: ".$gpg->error() if $gpg->error();

When I run them consecutively via "perl trialencode && perl trialdecode" encoding works fine, but decoding fails. Here is the output from this:

Plain: ARGHH!!

Encoded:
-----BEGIN PGP MESSAGE-----

hIwDZMVp08Pd6AkBA/9RMIUI66urMEDQXgwgaQC6K4u2v5RCt8N7iMW/a+W5xnWI
ZTInl912BtPs/KZTJvfDEjkjqSc0vrzPZzoT2EMDgjwwPh+uNe2z8PHFALTDUGpb
x+EfIi0etb+4QlWL+MkHFoIeB1ZgTb2zEz7sIndrUEBf2MqF3mpZyrFISdAJPNJC
AaS/x6aTC1hRIs0kYjf9m/laq29bebfsZUPEUR9fDuQeR8bD6KVEn3TT+7Chlv7E
a7Uh1x041RlG/BTareLke0qq
=0kR7
-----END PGP MESSAGE-----

==========================

Encoded:
-----BEGIN PGP MESSAGE-----

hIwDZMVp08Pd6AkBA/9RMIUI66urMEDQXgwgaQC6K4u2v5RCt8N7iMW/a+W5xnWI
ZTInl912BtPs/KZTJvfDEjkjqSc0vrzPZzoT2EMDgjwwPh+uNe2z8PHFALTDUGpb
x+EfIi0etb+4QlWL+MkHFoIeB1ZgTb2zEz7sIndrUEBf2MqF3mpZyrFISdAJPNJC
AaS/x6aTC1hRIs0kYjf9m/laq29bebfsZUPEUR9fDuQeR8bD6KVEn3TT+7Chlv7E
a7Uh1x041RlG/BTareLke0qq
=0kR7
-----END PGP MESSAGE-----

Decoded: []

$gpg->error message: gpg: encrypted with 1024-bit RSA key, ID C3DDE809, created 2012-03-13
"Jaf O Faj (Testing sundry perl GPG packages) <jaf0faj@xxxxxxx>"


What am I doing wrong? BTW, if I perform a "gpg --decrypt trialencoded on the command line, where trialencoded is the dump of the encoded phase generated in trialencode, gpg successfully decodes the text, as shown below (using HtfdIggtw? as the passphrase for the secret key)!

gpg --decrypt trialencoded

You need a passphrase to unlock the secret key for
user: "Jaf O Faj (Testing sundry perl GPG packages) <jaf0faj@xxxxxxx>"
1024-bit RSA key, ID C3DDE809, created 2012-03-13 (main key ID B5A7838C)

gpg: encrypted with 1024-bit RSA key, ID C3DDE809, created 2012-03-13
"Jaf O Faj (Testing sundry perl GPG packages) <jaf0faj@xxxxxxx>"
ARGHH!!