Warning: gnupg::adddecryptkey(): get_key failed

怎甘沉沦 提交于 2020-06-16 04:13:25

问题


I am using gnupg php functions to decrypt a file.

With the help of another post on here I managed to get it to list the keys (gnupg_keyinfo) by using gnupg_import and changing the owner of the gnupg directory and chmod permissions.

I can also successfully encrypt a file using gnupg_encrypt.

But when it comes to decrypting a file using gnupg_decrypt it doesn't work with an error message that reads:

Warning: gnupg::adddecryptkey(): get_key failed

This is the code I am using to encrypt and then decrypt the file:

$CONFIG['gnupg_home'] = '{{PATH}}';
$CONFIG['gnupg_fingerprint'] = '{{FINGERPRINT}}';

$data = 'Info to encrypt/decrypt';

$gpg = new gnupg();
putenv("GNUPGHOME={$CONFIG['gnupg_home']}");
$gpg->seterrormode(GNUPG_ERROR_WARNING);
$gpg->addencryptkey($CONFIG['gnupg_fingerprint']);

$encrypted = $gpg->encrypt($data);
echo "Encrypted text: \n<pre>$encrypted</pre>\n";


$plain_text = '';
$passphrase = '';
$gpg->adddecryptkey($CONFIG['gnupg_fingerprint'], $passphrase);
$decrypted = $gpg->decrypt($encrypted);

echo "Decrypted text: $decrypted";

I have tried it with a passphrase and it didn't work and then read that it doesn't use a passphrase anymore so I have tried it without one.

I have chmod 700 to ~/.gnupg and chmod 600 to ~/.gnupg/*

The path to the gnupghome is correct as it's the same as the path I use for the gnupg_keyinfo and there are 2 fingerprints that get returned from it and I have tried it with both.

I have googled it and I have seen people with the same problem but can't find an answer to the problem.

Thank you

来源:https://stackoverflow.com/questions/40932964/warning-gnupgadddecryptkey-get-key-failed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!