'GnuPG PHP Module: Check key passphrase

When I run gnupg_adddecryptkey with a correct key identifier, but wrong passphrase, it does not fail, but returns true:

$res = gnupg_init();
gnupg_adddecryptkey($res,"8660281B6051D071D94B5B230549F9DC851566DC","correctpassphrase"); // true
gnupg_adddecryptkey($res,"WRONGKEYIDENTIFIER","correctpassphrase"); // false
gnupg_adddecryptkey($res,"8660281B6051D071D94B5B230549F9DC851566DC","wrongpassphrase"); // true

So how to check a key passphrase of gnupg key in PHP?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source