I am using Crypt_GPG for PHP and I am unable to sign a GPG document even though I am importing a sign key which I just created, which does have a passphrase.
The code is pretty simple:
$gpg = new \Crypt_GPG();
// Import my private key and client public key
$gpg->importKey($myPrivateKey);
$gpg->importKey($clientPublicKey);
$myPrivateFingerprint = $gpg->getKeys('my_email@example.org')[0]->getPrimaryKey()->getFingerprint();
$clientPublicFingerprint = $gpg->getKeys('client@example.org')[0]->getPrimaryKey()->getFingerprint();
$gpg->addSignKey($myPrivateFingerprint, 'myunittest');
$gpg->addEncryptKey($clientPublicFingerprint);
return $gpg->encryptAndSign('hello');
When I dump the Crypt_GPG class before the return statement I can see that the sign key is there as well as the passphrase. Here is the relevant portion:
#signKeys: array:1 [
"XXXXXXXXXXXXX" => array:2 [
"fingerprint" => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"passphrase" => "myunittest"
]
]
Everything matches up as it should. When I get to the final function, encryptAndSign(), it fails with this error:
[Crypt_GPG_BadPassphraseException] Cannot sign data. No passphrase provided.
What am I missing here?
Thank you bishop. The problem seems to be a bug in gpg 2.0.22, which is the version I have in Docker. I did some testing and I noticed I had no issues on our qa and production servers. I checked the version on those boxes and it was 2.0.28. My code has been vindicated.