bkort1
asked on
Trouble with decrypting PGP encrypted file using PHP & GnuPG
We have the keys setup and GnuPG setup on the server, we are able to decrypt the file using the command line without any errors. However, when we use the GnuPG class for PHP we run into trouble. Here is the code we currently have, although we have gone through many variations and tried many different things, any advice is welcome as this is the first time we have worked with PGP let alone GnuPG.
$encryptedContent = file_get_contents($encryptedFileName);
$passphrase = '************';
$gpg = new gnuPG('gpg', '/var/www/html/.gnupg');
$secretKeys = $gpg->ListKeys('secret');
if (is_array($secretKeys))
{
try
{
$decryptedContent = $gpg->decrypt($secretKeys[0]['KeyID'], $passphrase, $encryptedContent);
}
catch (Exception $e)
{
echo "PGP Error: " . $gpg->error . "<br/>";
echo "Exception: " . $e;
}
echo "PGP Error: " . $gpg->error . "<br/>";
echo "Decrypted Content: " . $decryptedContent;
}
Update: The extension is not installed on my server. Sorry, but it looks like this is (at least) a research project.
http://php.net/manual/en/gnupg.installation.php
From https://www.gnupg.org/related_software/gpgme/ this is unfortunate:
See download section to download the latest tarball.
Best of luck. Sorry I couldn't help any further.
http://php.net/manual/en/gnupg.installation.php
From https://www.gnupg.org/related_software/gpgme/ this is unfortunate:
See download section to download the latest tarball.
Best of luck. Sorry I couldn't help any further.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Given the rather thin collection of user contributed notes, I would surmise that this is not one of the mainstream parts of PHP. If you need a simple encryption that works, this little script will demonstrate how I've done it successfully.
Open in new window
If I have some time today (and my PHP installation has all the bells and whistles) I will try to show something using GnuPG.