Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Re: Getting Started with GnuPG and GPG by jaf0faj
in thread Getting Started with GnuPG and GPG by derby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (7)
    As of 2014-08-30 03:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (291 votes), past polls