2017-02-01 33 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)

相關問題