【问题标题】:How to use GNUPG and Crypt_GPG如何使用 GNUPG 和 Crypt_GPG
【发布时间】:2009-09-09 10:05:25
【问题描述】:

我正在尝试使用 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 是不同的用户或什么?

需要一些指导,谢谢;)

【问题讨论】:

  • 尝试声明另一个 Crypt_GPG 而不是使用 $gpg 来清除消息。

标签: php encryption pear gnupg pgp


【解决方案1】:

examples 向您展示如何指定密码:

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

查看the documentation 了解更多示例。

【讨论】:

  • 是的,就是这样 - 我的密码配置错误!现在一切正常。谢谢大家!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多