Question

I am encrypting a string using:

$gpg = new gnupg();
putenv("GNUPGHOME=/var/www/.gnupg");
$gpg->seterrormode(gnupg::ERROR_EXCEPTION);
$gpg->addencryptkey($fingerprint);
$encrypted =  $gpg->encrypt($data);
echo "Encrypted text: \n<pre>$encrypted</pre>\n";

The output of which works correctly, but I am having problems decrypting this output back to a string.

In order to decrypt this in CLI I have to use

gpg-agent --daemon --verbose gpg --homedir /var/www/.gnupg

(I get a socket connection error if I don't include the gpg-agent stuff before gpg)

I then enter my passphrase and and CTRL+D for end of file, and the text string is correctly decrypted.

When I try the same decryption in php using gnupg_decrypt I just get decrypt failed. Is there something I can do to disable the gpg-agent as I've tried adding no-agent etc to the conf file but it appears to have no effect but I think this may be the problem.

All files are set to match the owner of the process that is run from the php file, and permissions seem correct as everything else is working okay except for interaction with gpg-agent.

This decryption needs to happen silently as a php function as it forms part of an overnight automatic update system.

Any help much appreciated.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top