Gnupg 不会在 php 中解密文件

Gnupg doesn't decrypt the file in php

我尝试用 php 中的 Gnupg 解密我的加密文件(包含多个文件的 zip 存档),但它总是 return 是错误的。没有异常或错误信息。 这是加密:

 $gpg = gnupg_init();
 gnupg_seterrormode($gpg, GNUPG_ERROR_EXCEPTION);
 // public key
 $publicKey = file_get_contents('pubkey.pub');
 $key = gnupg_import($gpg, $publicKey);
 gnupg_addencryptkey($gpg, $key['fingerprint']);
 // zip file
 $zip = file_get_contents('myzip.zip');
 $encryptedFile = gnupg_encrypt($gpg, $zip);
 //save encrypted file
 file_put_contents('myzip.zip.gpg', $encryptedFile);

解密如下:

$gpg = gnupg_init();

$privateKey = file_get_contents('private.asc');
$key = gnupg_import($gpg, $privateKey);

gnupg_adddecryptkey($gpg, $key['fingerprint'], '12345');
$file = file_get_contents('myzip.zip.gpg');
$content = gnupg_decrypt($gpg, $file); // <- always returns false

我尝试用在线工具解密文件。起初我试图只解密 1 个文本文件并且它成功了(它显示了文件的内容)。我也尝试解密 zip 存档

但每次我尝试用 php 中的 gnupg_decrypt 解密它时,它 return 都是错误的。我究竟做错了什么?

问题出在 gnupg 版本中。我灌输 gpg2 并且有效。