Reputation: 47
I'm doing a small program, a part of which has to decipher gpg messages that are transmitted between two pcs. Unfortunately the perl GnuPG library returns:
GnuPG::abort_gnupg(GnuPG=HASH(0x1ddba80), "Protocol error: expected NEED_PASSPHRASE.* got NO_SECKEY\x{a}")
when I run this code:
#!/usr/bin/perl
use strict;
use warnings;
use GnuPG;
my ($gpg, $msg, $dec, $pwd, $tfile);
$gpg = new GnuPG ( gnupg_path => "/usr/bin/gpg",);
$pwd = "pwd"; #
$msg = "message"; #
$tfile = "/tmp/local_scripts/temp.txt";
chomp $msg;
open (my $fh, ">", $tfile) or die "Cannot open temporary file: $!";
print $fh $msg;
close ($fh);
$gpg->decrypt
(
symmetric => 1,
ciphertext => $tfile,
passphrase => $pwd,
output => $dec,
);
print $dec;
Am I even using the right library to do this, or do I have to turn to Crypto::GnuPG (which, when tested, gave me "Decryption failed: Can't find a secret key to decrypt message", even with a specified password...) I'm lost really
Upvotes: 0
Views: 538
Reputation: 47
Appears that in order to get it running, you must fully specify the locations of the GnuPG homedir, options file & gpg_path whenever you're calling the GnuPG constructor:
$gpg = new GnuPG ( gnupg_path => "/usr/bin/gpg", homedir => "/home/your_username/.gnupg/", options => "/home/your_username/.gnupg/gpg.conf");
(Tested on Debian 8)
Upvotes: 1