I try to decrypt my enrypted file(zip archive which contains multiple files) with Gnupg
in php, but it constantly returns false. no exception or error message.
here's encryption:
$gpg = gnupg_init();
gnupg_seterrormode($gpg, GNUPG_ERROR_EXCEPTION);
// public key
$publicKey = file_get_contents('pubkey.pub');
$key = gnupg_import($gpg, $publicKey);
gnupg_addencryptkey($gpg, $key['fingerprint']);
// zip file
$zip = file_get_contents('myzip.zip');
$encryptedFile = gnupg_encrypt($gpg, $zip);
//save encrypted file
file_put_contents('myzip.zip.gpg', $encryptedFile);
here's decryption:
$gpg = gnupg_init();
$privateKey = file_get_contents('private.asc');
$key = gnupg_import($gpg, $privateKey);
gnupg_adddecryptkey($gpg, $key['fingerprint'], '12345');
$file = file_get_contents('myzip.zip.gpg');
$content = gnupg_decrypt($gpg, $file); // <- always returns false
I tried to decrypt the file with online tool. at first I tried to decrypt only 1 text file and it worked(it displayed the content of file). I tried to decrypt the zip archive as well
but everytime I try to decrypt it with gnupg_decrypt
in php it return false. what am I doing wrong?
The problem was in gnupg
version. I instilled gpg2
and it worked.