2017-02-01 28 views
0

我在做一个小程序,其中的一部分必须解密在两个pcs之间传输的gpg消息。不幸的是,Perl的GnuPG的库回报:即使使用指定的密码,Perl GnuPG也会返回NO_SECKEY

GnuPG::abort_gnupg(GnuPG=HASH(0x1ddba80), "Protocol error: expected NEED_PASSPHRASE.* got NO_SECKEY\x{a}")

当我运行这段代码:

#!/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; 

我是即使使用正确的库要做到这一点,或者我不得不转向加密:: GnuPG的(当测试时,它给了我“解密失败:无法找到一个密钥解密信息”,即使与指定的密码...)我真的丢了

回答

1

出现,为了让它运行,您必须完整指定GnuPG homedir的位置,选项文件& gpg_path wh enever你打电话GnuPG的构造函数:

$gpg = new GnuPG (gnupg_path => "/usr/bin/gpg", homedir => "/home/your_username/.gnupg/", options => "/home/your_username/.gnupg/gpg.conf");

(测试在Debian 8)

相关问题