Search code examples
phpgnupgpgp

GNUPG decryption failed in php


I am using GnuPG library to encrypt decrypt messages. I have successfully confirgured the GPG extension on my server and generated a key pair. Also I am successfull in importing another public key and enrypting data using that public key.

I also encrypted data using my public key and decrypted it using my private key.

But when somebody else encrypts data using my public key I am unable to decrypt it. the error is

Warning: gnupg_decrypt(): decrypt failed in pgpdecrypt.php on line 22 

my code is

$Message = $_REQUEST["Message"];

// Specify custom location of GnuPG binary.
$res = gnupg_init();

gnupg_seterrormode($res, GNUPG_ERROR_WARNING); 

$rtv = gnupg_adddecryptkey($res, "rizwan@google.com", "0000");
echo gnupg_geterror($res) . "<br>"; // Print if any errors

$enc = gnupg_decrypt($res, $Message); // ERROR IS AT THIS LINE
echo gnupg_geterror($res) . "<br>"; // Print if any errors
echo $enc;

this same code is decrypting data encrypted by me at my machine.

I am unable to extract error details.


Solution

  • Cipher Algorithm 6 reffers to DES. DES is not supported in GnuPG, it uses 3DES/Triple-DES instead. I encrypted the data using 3DES and it successfuly decrypted at my site.

    Hope this helps to other people encountering same problem. :)