http://www.perlmonks.org?node_id=229117

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

I am attempting to decrypt a file using a specific key and that key's password. I've tried several different modules but all of them fail. This is what I've got.
#!/usr/bin/perl -w use strict; use warnings; use GPG; my($passphrase,$key_id) = ("passphrase","KeyName"); my $gpg= new GPG(homedir=>"/home/chinesebob/.gnupg"); die $gpg->error() if $gpg->error(); my $file=$gpg->decrypt_verify($passphrase,"try.pgp");

Replies are listed 'Best First'.
Re: GPG decryption
by Paladin (Vicar) on Jan 22, 2003 at 21:34 UTC
    According to the docs for GPG, decrypt_verify() and friends take the actual text as the second argument, not a file name. Try:
    ... open GPGFILE, "try.gpg" or die "Couldn't open try.gpg: $!"; my $text = do {local $/; <GPGFILE>}; close GPGFILE; my $file=$gpg->decrypt_verify($passphrase,$text); print $file->{text}; ...
      Instead of using the module I tried the
      system(gpg ......);
      and it worked. Go figure. thank you anyways.
      I was racking my brain trying to work out why:

      $gpg->decrypt(pass,$text)

      wasn't working for $text

      The GPG pod wasn't clear to me on this issue, thanks for clearing it up for us Paladin :)