简体   繁体   English

使用gpg4win加密后,使用PHP gnupg解密文件

[英]decrypt file with PHP gnupg after encrypting using gpg4win

i am completely stuck with a pgp problem, but I guess it's more a logical than a technical problem - anyway, i don't get it. 我完全陷入了pgp问题,但我想这比技术问题更合乎逻辑-无论如何,我不明白。

The goal is to encrypt a file with gpg4win (www.gpg4win.de/index.html) and decrypt it with PHP (gnupg). 目标是使用gpg4win(www.gpg4win.de/index.html)加密文件,然后使用PHP(gnupg)解密文件。

First thing I did, I've created a certificate with gpg4win, set a passphrase and encrypted a simple text file (ASCII). 我做的第一件事是,我用gpg4win创建了一个证书,设置了密码,并对一个简单的文本文件(ASCII)进行了加密。 Then I upload the file and tried to decrypt it with the following code: 然后,我上传文件并尝试使用以下代码对其解密:

$content = file_get_contents("some-test-data.asc");
$gpg = new gnupg();
$gpg -> adddecryptkey("MYFINGERPRINT","my.pass.phrase");
$plain = $gpg -> decrypt($content);
var_dump($plain);

The result was: bool(false) 结果是:bool(false)

What I am doing wrong? 我做错了什么? I've tried different code and suggestions, but always ended up with bool(false). 我尝试了不同的代码和建议,但始终以bool(false)结尾。

Are these methods not compatible, do I have to a different application? 这些方法不兼容吗,我必须使用其他应用程序吗?

I appreciate every little help I could get. 我感谢我能得到的每一个小帮助。 Thanks alot! 非常感谢!

PS PHP is compiled with gnupg GPGme Version 1.4.2 Extension Version 1.3.3-dev PS PHP使用gnupg GPGme版本1.4.2扩展版本1.3.3-dev进行编译

Problem solved. 问题解决了。 If anybody run into the same trouble, it's due to lag in the PHP Documentation: 如果有人遇到同样的麻烦,那是由于PHP文档中的滞后:

string gnupg_decrypt ( resource $identifier , string $text ) 字符串gnupg_decrypt(资源$ identifier,字符串$ text)

If found the following comment in the comment section: As of gnupg version 2, it is not possible to pass a plain password any more. 如果在注释部分中找到以下注释:从gnupg版本2开始,将无法再传递普通密码。 The parameter is simply ignored. 该参数将被忽略。 Instead, a pinentry application will be launched in case of php running in cli mode. 相反,如果php以cli模式运行,则会启动pinentry应用程序。 In cgi or apache mode, opening the key will fail. 在cgi或apache模式下,打开密钥将失败。 The simplest solution is to use keys without passwords. 最简单的解决方案是使用不带密码的密钥。

So i've created a new key without password and everything works fine. 因此,我创建了一个没有密码的新密钥,并且一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM