Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Getting Started with GnuPG and GPG

by jaf0faj (Novice)
on Mar 13, 2012 at 13:10 UTC ( #959324=note: print w/ replies, xml ) Need Help??


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!!


Comment on Re: Getting Started with GnuPG and GPG
Select or Download Code
Re^2: Getting Started with GnuPG and GPG
by Anonymous Monk on Mar 14, 2012 at 06:24 UTC

      I have no problem with this posting being here ... it's a question about the tutorial.

      -derby
Re^2: Getting Started with GnuPG and GPG
by derby (Abbot) on Mar 14, 2012 at 13:09 UTC

    Wow! I don't know what's more amazing ... a question about a decade old post, the fact that the monastery is still here after ten years, or that I'm still here to answer it.

    The problem is GPG has not been updated in a dozen years but gpg has. Looks like the underlying options to the gpg command

    --batch --no-comment --no-version
    are no longer sufficient to keep non-error messages off of STDERR. GPG interpets anything on STDERR as an error and will not return the output
    $this->error($error) and return if $error; return $output;

    So ... the real solution is to use a newer module (maybe GnuPG -- but I haven't really looked into it). But ... if you're feeling hacky, you can always modify GPG to use the --quiet option and that should prevent information on STDERR from blocking the decrypt.

    -derby

      Excellent! I did hack the GPG.pm by inserting the --quiet option and gave it a go...works brilliantly. Thanks again for this. Now, if only I could get Crypt::OpenPGP to work....

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-11-24 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (144 votes), past polls