Reputation: 91
I'm trying to encrypt a string using the PHP GnuPG library on my Linux server hosted on Rackspace, however I keep getting an error message no matter what I try. Please see below:
Fatal error: Uncaught exception 'Exception' with message 'no key for encryption set' in /var/www/vhosts/royal/facebook/email-sign-up/encrypt.php:10 Stack trace: #0 /var/www/vhosts/royal/facebook/email-sign-up/encrypt.php(10): gnupg->encrypt('this is some co...') #1 {main} thrown in /var/www/vhosts/royal/facebook/email-sign-up/encrypt.php on line 10
I have checked that the GnuPG library is installed properly on the server, that I'm using the correct key fingerprint and that the server has permission to read/write to the GNUPGHOME directory.
Please see below for the PHP code I'm using:
$gpg = new gnupg();
putenv("GNUPGHOME=/root/.gnupg");
$gpg->seterrormode(GNUPG_ERROR_SILENT);
$gpg->addencryptkey('********************************');
$gpg->seterrormode(gnupg::ERROR_EXCEPTION); // throw an exception in case of an error
$encrypted = $gpg->encrypt('this is some confidential information');
echo "Encrypted text: \n<pre>$encrypted</pre>\n";
Thanks for any help, it would be greatly appreciated!
Upvotes: 0
Views: 1079
Reputation: 91
It turned out to be an incorrectly set permission on the server. The directory "/root/.gnupg" had full read access but no write access.
Upvotes: 1