: This article describes how to debug Crypt_GPG. For more information about PHP tutorials, see. Error output on the browser:
( ! ) Fatal error: Uncaught
Crypt_GPG_FileException: The 'homedir' "/Library/WebServer/.gnupg" is not readable or does not exist and cannot be created. This can happen if 'homedir' is not specified in the Crypt_GPG options, Crypt_GPG is run as the web user, and the web user has no home directory. in
/usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php on line
278
Exception trace
#
Function
Location
0Crypt_GPG_Engine->__construct(Array)/usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php in /usr/local/webdata/andy/fanli/citic/Crypt/GPG/Engine.php on line 541
Error message output by the command line:
PHP Fatal error: Uncaught PEAR_Exception: gpg-agent binary not found.If you are sure the gpg-agent is installed, please specify the location of the gpg-agent binary using the 'agent' driver option.in /usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php on line 278#0 /usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php(278): Crypt_GPG_Engine->__construct(Array)#1 /usr/local/webdata/andy/fanli/citic/gpg2.php(9): Crypt_GPGAbstract->__construct()#2 {main} thrown in /usr/local/webdata/andy/fanli/citic/Crypt/GPG/Engine.php on line 601Fatal error: Uncaught PEAR_Exception: gpg-agent binary not found.If you are sure the gpg-agent is installed, please specify the location of the gpg-agent binary using the 'agent' driver option.in /usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php on line 278#0 /usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php(278): Crypt_GPG_Engine->__construct(Array)#1 /usr/local/webdata/andy/fanli/citic/gpg2.php(9): Crypt_GPGAbstract->__construct()#2 {main} thrown in /usr/local/webdata/andy/fanli/citic/Crypt/GPG/Engine.php on line 601
The first error reported in browser is my analysis of permission issues, and the second is the true problem when running in shell. use brew to install gpg-agent as prompted.
Then I write the code as follows:
require_once'./Crypt/GPG.php';$gpg = new Crypt_GPG();$key = getKey();$gpg->addDecryptKey('zhangsanfeng','123456');$encrypted = file_get_contents('wait_for_decrpyt.txt.gpg');$data = $gpg->decrypt($encrypted);echo'
';var_dump($data);exit;
The decryption is successful !!!
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes the process of debugging Crypt_GPG, including the content, and hope to be helpful to friends who are interested in PHP tutorials.