I am trying to decrypt a simple message with PGP(gnupg) in PHP.
But I always get this error: get_key failed
.
On stack-overflow I see many people with this problem but I can't fix it.
I followed this tutorial that includes how to set the permissions for the files: http://46dogs.blogspot.nl/2007/11/setting-up-gnupg-gpg-for-use-with-php.html
This is the script that I am using. My PGP key does not contain a phase phrase:
<?php
putenv("GNUPGHOME=/home/user/.gnupg/");
$gpg = new gnupg();
$gpg -> addencryptkey("2ADA21BDC9C96556EA0758F04A935AE0010AE203");
$encrypted_text = $gpg -> encrypt("just a test");
//echo $encrypted_text;
$gpg = new gnupg();
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
try{
$gpg -> adddecryptkey("2ADA21BDC9C96556EA0758F04A935AE0010AE203","");
$decrypted_text = $gpg -> decrypt($encrypted_text);
} catch (Exception $e) {
echo $e;
}
echo $decrypted_text;
?>
The permissions of the files(pubring.gpg, trustdb.gpg and secring.gpg) are exactly the same as the tutorial(Only user changed to nginx).
The encrypting part works. But decrypting doesn't work.
Does anyone know what is wrong?
I am running Centos and php5.