如何使用 GNUPG 和 Crypt_GPG

发布于 2024-08-04 16:33:56 字数 4393 浏览 4 评论 0原文

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

  1. 我已经在服务器上安装了 GNUPG,它工作得很好,位于 /home/myserver/.gnupg
  2. 我已经将 Crypt_GPG 安装到 /home/myserver/php/Crypt code> 并编辑各个文件以具有彼此的绝对链接引用。他们工作得很好。
  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('[email protected]'), "<br>";
echo "My key fingerprint is: ", $gpg->getFingerprint('[email protected]', Crypt_GPG::FORMAT_CANONICAL), "<br>";

$data = 'Hello, World!';
$gpg->addSignKey('[email protected]');
$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 是不同的用户或其他原因?

需要一些指导,谢谢;)

I'm trying to use GNUPG and Crypt_GPG to encrypt data ready to be sent across email to a client server but i'm having problems setting it up.

  1. I've installed GNUPG on the server, and it works just fine, located in /home/myserver/.gnupg
  2. I've installed Crypt_GPG into /home/myserver/php/Crypt and edited the various files to have absolute link references to each other. They work fine.
  3. I've used my server CPanel to create a test public/secret key. The key generated fine.

Here is my test code (with debug mode left on)

<?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('[email protected]'), "<br>";
echo "My key fingerprint is: ", $gpg->getFingerprint('[email protected]', Crypt_GPG::FORMAT_CANONICAL), "<br>";

$data = 'Hello, World!';
$gpg->addSignKey('[email protected]');
$signedData = $gpg->sign($data, Crypt_GPG::SIGN_MODE_CLEAR);
echo "<br><br>Clearsigned message is: ", $signedData, "\n";

?>

The first section of code works well - the public key is retrieved, displayed and the fingerprint shows too.

The problem is with the second block of code - actually trying to encrypt something. I get these errors in the debug output. I won't post the full output (its large) but I hope these are the salient points:

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

and then later:

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> </td></tr> </table> thrown in /home/myserver/php/Crypt/GPG.php on line 1837

To me it looks like the Crypt_GPG is having issues selecting what it needs from the GNUPG key? It appears to find the key correctly, but it falls over with the passphrase. Is this an error with my understanding and code, or is this because CPanel and Apache are different users or something?

Need a bit of guidance, thanks ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2024-08-11 16:33:56

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

$gpg->addSignKey('[email protected]', 'test');

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

The examples show you how to specify the passphrase:

$gpg->addSignKey('[email protected]', 'test');

Check the documentation for more examples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文