问题描述
我正在将gnupg
用于php
中的数字签名文件.以前工作正常.突然我收到此错误:
I am using gnupg
for digital sign file in php
. It was working fine before. Suddenly I am getting this error:
putenv("GNUPGHOME=/tmp");
$publicKey = file_get_contents("./media/public.key");
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
$info = $gpg->import($publicKey);
$gpg->addsignkey($info['fingerprint'], DIGITAL_FILE_PASS);
$signed = $gpg->sign($data_to_sign);
可能是什么原因?
信息:
$info
变量如下所示:
Array
(
[imported] => 0
[unchanged] => 2
[newuserids] => 0
[newsubkeys] => 0
[secretimported] => 0
[secretunchanged] => 0
[newsignatures] => 0
[skippedkeys] => 0
[fingerprint] => 622FC43AB6E1FC175C08E9C0048EAEBF6E607FA3
)
公钥:
-----开始PGP公钥块-----版本:GnuPG v1
-----BEGIN PGP PUBLIC KEY BLOCK-----Version: GnuPG v1
mQENBFXvNq0BCADAgEoJ9yHbgJp2h86eUqwqP8s4bKa4nFodx4dmUL3dJfrOhibPjiaG9eDyzyT3 + avQVc4 + Z3knYBxanFx1lchDS3EnjLwvfShbtU2X0oiuqoYIM76B03pCNpAiNsICVtZCYUBPe8Xjl8BNquK1RRdzrQRm29t9qa6TvCMIdc3rl0hOVHeXIgVzyYjE2Je9ICI2MRE7XK76GrdQ9N1nvoTOf6K3QA + wSQjOY4FUk95/tLUXiGssSQKqkczro4l7PEBCcX99QvY + BBTV4ykJ4lg6cdQabFXSeNfPYb56v62J0S8VswS9AofwkQGt1TplcFvpoziQ1ecCj2DGYBD6rvzRABEBAAG0KEJoYXNrZXIgUmVkZHkgPGJiaGFza2VyLnJlZGR5QHBuYi5jby5pbj6JAT4EEwECACgFAlXvNq0CGwMFCQlmAYAGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEASOrr9uYH + jgmMIAI9Sg8KlxbschHKIvndQzfQ/TZyc4LpKRMgJsxw8utluq1ksbnHsmvF4rdgZ2hfnrAxN3lduvt6lddqi9 + LLQD8pWMqH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FDLOORQAmxOKK7dztUxCDWLIuwUrmjrr/u5uO38f5jAygEcAEQEAAYkBJQQYAQIADwUCVlNssAIbDAUJCWYBgAAKCRD9whVF2jH48eETCAChvI2tDT3E/wUCxHNSLYSHo4xFi9GKOy6MfhkyhDQtdkapwsrv+4kun/U87qzQ3X/36K4rIpsoxGRSr6Q9gzE5+8HBQGIlz5Waverlamsh9iMxYfYzROyJURrJOpG9bXl3pqB20ZW5Ry1H4sa5uIlz5/LWnjIJqLo3E81+HDO6Gwml3KujiY5NlrFEltX9bU9UoM/u6Os3dlglBQH/DZpqOPxL3CgKRb7cWCT3xeXIsFFWbreDFDvRndaOSFE3Z8bAYx17deJFf9EEBTRSTRPGS6WZ9Oc2IvsWqs8w/+mq7EVxKZ3T8CWy8d8wxzDzxg9ZNwVCDzbqDCw5a1xG5T03=Zji/-----END PGP PUBLIC KEY BLOCK-----
推荐答案
尽管您的代码正确,但是我不知道为什么file_get_contents在您的代码中无法正常工作,请尝试使用cURL:
Although your code is correct but I don't know why file_get_contents is not working correctly in your code, Kindly give it a try using cURL:
此函数是file_get_contents的替代方法.
This function is an alternative to file_get_contents.
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
这篇关于gnupg get_key在php中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!