在 PHP 中使用 PGP 加密

发布于 2025-01-07 06:27:10 字数 1169 浏览 3 评论 0原文

我第一次尝试在 PHP 中实现 pgp 加密,但我很难让它工作。我希望有人能够指出我正确的方向。基本上,如果我这样做:

  $gpg = '/usr/bin/gpg';

  $recipient = '[email protected]';

  $encrypted_message =  shell_exec("echo 'a_string_here' | $gpg -e -r $recipient");

  echo $encrypted_message;

它工作得很好。服务器上安装了[电子邮件受保护]的公钥和私钥。但是,如果我这样做,我会得到一个空变量,

  $gpg = '/usr/bin/gpg';

  $recipient = '[email protected]';

  $encrypted_message =  shell_exec("echo 'a_string_here' | $gpg -e -r $recipient");

  echo $encrypted_message;

仅为 [ 安装一个公钥电子邮件受保护]。当然,我需要这个来工作 [email protected] 这是加密字符串的接收者...

提前致谢

I'm trying to implement pgp encryption from within PHP for the very first time but I'm having a hard time making it work. I hope someone will be able to point me in the right direction. basically, if I do this:

  $gpg = '/usr/bin/gpg';

  $recipient = '[email protected]';

  $encrypted_message =  shell_exec("echo 'a_string_here' | $gpg -e -r $recipient");

  echo $encrypted_message;

it works fine. a public and a private key is installed on the server for [email protected]. however, if I do this, I get a null variable

  $gpg = '/usr/bin/gpg';

  $recipient = '[email protected]';

  $encrypted_message =  shell_exec("echo 'a_string_here' | $gpg -e -r $recipient");

  echo $encrypted_message;

there is only one public key installed for [email protected]. of course, I need this to work for [email protected] which is the recipient of the encrypted string...

thanks in advance

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

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

发布评论

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

评论(1

绝情姑娘 2025-01-14 06:27:10

你可以看看这篇文章:
http://devzone.zend.com/30/ Encryption-and-Decryption-using-php-and-gnupg/

请注意,它们对 shell_exec 结果进行 Base 64 编码,因为默认情况下加密消息采用二进制格式(可以使用 -a 开关更改为 ASCII: $gpg -a -e -r $收件人)

You can take a look at this article:
http://devzone.zend.com/30/encryption-and-decryption-using-php-and-gnupg/

Note that they base 64 encode the shell_exec result because by default the encrypted message is in binary format (can be changed to ASCII with the -a switch: $gpg -a -e -r $recipient)

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