2

我正在尝试使用 GNUPG 和Crypt_GPG来加密准备通过电子邮件发送到客户端服务器的数据,但我在设置它时遇到了问题。

  1. 我已经在服务器上安装了 GNUPG,它工作得很好,位于/home/myserver/.gnupg
  2. 我已经将 Crypt_GPG 安装到/home/myserver/php/Crypt并编辑了各种文件以具有彼此的绝对链接引用。他们工作正常。
  3. 我已经使用我的服务器 CPanel 创建了一个测试公钥/密钥。密钥生成良好。

这是我的测试代码(保持调试模式)

<?php
require_once '/home/myserver/php/Crypt/GPG.php';

$gpg = new Crypt_GPG(array('homedir' => '/home/myserver/.gnupg', 'debug' => true));
echo "My public key is: ", $gpg->exportPublicKey('info@test.co.uk'), "<br>";
echo "My key fingerprint is: ", $gpg->getFingerprint('info@test.co.uk', Crypt_GPG::FORMAT_CANONICAL), "<br>";

$data = 'Hello, World!';
$gpg->addSignKey('info@test.co.uk');
$signedData = $gpg->sign($data, Crypt_GPG::SIGN_MODE_CLEAR);
echo "<br><br>Clearsigned message is: ", $signedData, "\n";

?>

第一部分代码运行良好 - 检索、显示公钥并显示指纹。

问题出在第二个代码块上——实际上是在尝试加密某些东西。我在调试输出中得到这些错误。我不会发布完整的输出(很大),但我希望这些是重点:

Crypt_GPG DEBUG: STATUS: GET_HIDDEN passphrase.enter
Crypt_GPG DEBUG: STATUS: GOT_IT
Crypt_GPG DEBUG: STATUS: MISSING_PASSPHRASE
Crypt_GPG DEBUG: STATUS: BAD_PASSPHRASE EEE2DCBB741D9730
Crypt_GPG DEBUG: STATUS: USERID_HINT EEE2DCBB741D9730 Test Key (Test Key)
Crypt_GPG DEBUG: STATUS: NEED_PASSPHRASE EEE2DCBB741D9730 EEE2DCBB741D9730 17 0
Crypt_GPG DEBUG: STATUS: GET_HIDDEN passphrase.enter
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG is ready for command data
Crypt_GPG DEBUG: => about to write 1 bytes to GPG command
Crypt_GPG DEBUG: => wrote 1
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG status stream ready for reading
Crypt_GPG DEBUG: => about to read 8192 bytes from GPG status
Crypt_GPG DEBUG: => read 44 bytes
Crypt_GPG DEBUG: STATUS: GOT_IT
Crypt_GPG DEBUG: STATUS: MISSING_PASSPHRASE
Crypt_GPG DEBUG: => closing GPG input pipe
Crypt_GPG DEBUG: selecting streams
Crypt_GPG DEBUG: => got 1
Crypt_GPG DEBUG: GPG status stream ready for reading
Crypt_GPG DEBUG: => about to read 8192 bytes from GPG status
Crypt_GPG DEBUG: => read 122 bytes
Crypt_GPG DEBUG: STATUS: BAD_PASSPHRASE EEE2DCBB741D9730

然后:

Crypt_GPG DEBUG: END PROCESSING
Crypt_GPG DEBUG: CLOSING SUBPROCESS
Crypt_GPG DEBUG: => subprocess returned an unexpected exit code: 2

Fatal error: Uncaught <table border="1" cellspacing="0"> <tr><td colspan="3" bgcolor="#ff9999"> <b>Crypt_GPG_BadPassphraseException</b>: Cannot sign data. Incorrect passphrase provided. in <b>/home/myserver/php/Crypt/GPG.php</b> on line <b>1054</b></td></tr> <tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr> <tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td><td align="center" bgcolor="#cccccc"><b>Function</b></td><td align="center" bgcolor="#cccccc"><b>Location</b></td></tr> <tr><td align="center">0</td><td>Crypt_GPG->_sign('Hello, World!', false, null, 2, true)</td><td>/home/myserver/php/Crypt/GPG.php:1054</td></tr> <tr><td align="center">1</td><td>Crypt_GPG->sign('Hello, World!', 2)</td><td>/home/myserver/public_html/email.php:7</td></tr> <tr><td align="center">2</td><td>{main}</td><td>&nbsp;</td></tr> </table> thrown in /home/myserver/php/Crypt/GPG.php on line 1837

对我来说,Crypt_GPG 似乎在从 GNUPG 密钥中选择所需内容时遇到问题?它似乎正确地找到了密钥,但它与密码短语有关。这是我的理解和代码的错误,还是因为 CPanel 和 Apache 是不同的用户或什么?

需要一些指导,谢谢;)

4

1 回答 1

2

这些示例向您展示了如何指定密码:

$gpg->addSignKey('test@example.com', 'test');

查看文档以获取更多示例。

于 2009-09-09T10:32:59.113 回答