在 PHP 中使用 PGP 加密
我第一次尝试在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以看看这篇文章:
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)