auser has asked for the wisdom of the Perl Monks concerning the following question:

Those wiser than I,
I am attempting to encrypt using GPG.pm. I have searched and have been unable to find any posts with any more ideas. I wrote the following test script as my full CGI was complex and harder to isolate the problem:
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); #show us the errors in the browser use GPG; #the GPG perl module my $gpg = new GPG( #create a new GPG object homedir => '/home/xxxxxx/.gnupg', #specify the directory gnupg_path => '/usr/bin', #non-standard path to gpg binary armor => '1', #make sure the output is ascii armored debug => '1' #debug mode to trouble shoot ); my $encrypted = $gpg->encrypt("Testing GPG", 'xxxx@xxxxx.com'); # This is where things break down. # GPG's debug looks fine but # I am unable to use the resulting scalar. print <<"_END_"; Content-type: text/plain Encrypted: -> $encrypted <- _END_
This is the output in both the browser and the command line. Notice that the scalar $encrypted is empty, however the gpg command seemed to work fine:
******************************************************************** COMMAND : /usr/bin/gpg -a --homedir /home/xxxxx/.gnupg --batch --no-co +mment --no-version $self->{'homedir'} : /home/xxxxx/.gnupg $self->{'config'} : $self->{'armor'} : 1 $self->{'debug'} : 1 ******************************************************************** ******************************************************************** COMMAND : /usr/bin/gpg -a --homedir /home/xxxxx/.gnupg --batch --no-comment --no +-version -r xxxxx@xxxxxxx.com --encrypt [PID 20804] STDIN : Testing GPG STDOUT : -----BEGIN PGP MESSAGE----- hQEOA48qWedehilLEAP+OY9G7xnv8QR5iXdg8zt6eccudlO+Qz8liAm7Zxd2JHZW oo6VKCa913HQuVJvV38c9F4HTIKorL7DaNyqQXI6poFUx4NqAk5slScug8hzbIn3 PucLXP9YBtGiRea5IpWCe1F3f7Rondaq3dnxkx210mtwT4W/i0h2b9BRNv+kwDwD /RHwL+kVtSAo98C/4TKAihPleiYdtwJ/xcJuV38j2t/V+SgCWE5R7QvwWF/oT395 w5ICu83ox1r6frOH/dnao9mkLrdpLONJfh/gRDRtx1ehLBPgyAxhJTwQDeFoxhTL OlDftD8p6fTn1ftJjKE9wcoOt02Del+YXRBpOXVHCZUJ0kYBb31wayNPdxGTx6No l4pjHB67pO2DTqQGg5vkauLqEwWUpFN+ILwLK7zjlmTY/onjkIBB5An4RG0eAnF/ 85/ImeXRtCWJ =dMrS -----END PGP MESSAGE----- WARNING : STDERR : gpg: WARNING: "--no-comment" is a deprecated option gpg: please use "--no-sk-comments" instead ******************************************************************** Content-type: text/plain Encrypted: -> <-
Thank you so much for your help :-)

Replies are listed 'Best First'.
Re: Problems with GPG.pm
by helphand (Pilgrim) on Feb 26, 2006 at 17:41 UTC

    You might consider switching to Crypt::OpenPGP instead of GPG.pm. It seems to work fine.

    #!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); #show us the errors in the browser use Crypt::OpenPGP; my $gpg = Crypt::OpenPGP->new; my $encrypted = $gpg->encrypt( Data => "Testing GPG", KeyID => $ARGV[0], Armour => 1, ) || die $gpg->errstr; print <<"_END_"; Content-type: text/plain Encrypted: -> $encrypted <- _END_
    helphand@helphand:~> perl gpg.pl helphand@pacbell.net Content-type: text/plain Encrypted: -> -----BEGIN PGP MESSAGE----- Version: Crypt::OpenPGP 1.03 hQEOA3chMi/0iuq/EAP/ayJ2CjLe0svhfwI3w39/1ZjzoqX9hmWT8anhaMRgXrPo kcw6o0W2MsuxELezZkHNIN7zJwq/JDA7fp58xy6bAaYpNxEhH8W4tmzHZJq777kt kVQXVIi5c7g8SFc9T9u6CZHAh494Z2DZMILyCIh2h098SeXefrBjRXyd2nQu6MAE AOYfzSetZM8OROHatTGdXCS7mqId5OdleMCrPRbjRhICiN3A2hyNVOwJFDnSvPbv tc1HzLXkpC5oiAYhTqejXF2S6zG0BEj8RDyodhwP9lIr6O6UGLLDkDiU7gjY+cLt 9hsdLgGsiQz8gZg8Y6tYR20c+pMSP/0fbYlXh7qcJgxOpB3lonRzbWjJ0VC+MYG5 1WIARDzLZo83ncscqnSoLA== =9lvU -----END PGP MESSAGE----- <-

    Scott

Re: Problems with GPG.pm
by zentara (Cardinal) on Feb 26, 2006 at 18:05 UTC
    Yeah, some of the encryption modules work better than others. I've had better luck with GnuPG.
    #!/usr/bin/perl use warnings; use strict; use GnuPG; my $gpg = new GnuPG(homedir => '/home/zentara/.gnupg'); $gpg->encrypt(plaintext =>"Gnufile.txt", output => "Gnufile.gpg", recipient =>"zentara\@zentara.net",armor=>"1"); exit;
    I did have to fix line 267 of GnuPG.pm, and single quote a string, but after that it worked fine.

    I'm not really a human, but I play one on earth. flash japh