Home >Backend Development >PHP Tutorial >The process of debugging Crypt_GPG

The process of debugging Crypt_GPG

WBOY
WBOYOriginal
2016-07-29 09:15:511143browse

Error output information on the browser side:

<code>( ! ) Fatal error: Uncaught <span><<span>table</span><span>style</span>=<span>"border: 1px"</span><span>cellspacing</span>=<span>"0"</span>></span><span><<span>tr</span>></span><span><<span>td</span><span>colspan</span>=<span>"3"</span><span>style</span>=<span>"background: #ff9999"</span>></span><span><<span>b</span>></span>Crypt_GPG_FileException<span></<span>b</span>></span>: The 'homedir' &quot;/Library/WebServer/.gnupg&quot; 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 <span><<span>b</span>></span>/usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php<span></<span>b</span>></span> on line <span><<span>b</span>></span>278<span></<span>b</span>></span><span></<span>td</span>></span><span></<span>tr</span>></span><span><<span>tr</span>></span><span><<span>td</span><span>colspan</span>=<span>"3"</span><span>style</span>=<span>"background-color: #aaaaaa; text-align: center; font-weight: bold;"</span>></span>Exception trace<span></<span>td</span>></span><span></<span>tr</span>></span><span><<span>tr</span>></span><span><<span>td</span><span>style</span>=<span>"text-align: center; background: #cccccc; width:20px; font-weight: bold;"</span>></span>#<span></<span>td</span>></span><span><<span>td</span><span>style</span>=<span>"text-align: center; background: #cccccc; font-weight: bold;"</span>></span>Function<span></<span>td</span>></span><span><<span>td</span><span>style</span>=<span>"text-align: center; background: #cccccc; font-weight: bold;"</span>></span>Location<span></<span>td</span>></span><span></<span>tr</span>></span><span><<span>tr</span>></span><span><<span>td</span><span>style</span>=<span>"text-align: center;"</span>></span>0<span></<span>td</span>></span><span><<span>td</span>></span>Crypt_GPG_Engine->__construct(Array)<span></<span>td</span>></span><span><<span>td</span>></span>/usr/local/webdata/andy/fanli/citic/Crypt/GPGAbstract.php in /usr/local/webdata/andy/fanli/citic/Crypt/GPG/Engine.php on line 541</code>

Error information output on the command line:

<code>PHP Fatal error:  Uncaught PEAR_Exception: gpg<span>-agent</span> binary <span>not</span> found<span>.</span><span>If</span> you are sure the gpg<span>-agent</span> is installed, please specify the location of the gpg<span>-agent</span> binary using the <span>'agent'</span> driver option<span>.</span><span>in</span> /usr/<span>local</span>/webdata/andy/fanli/citic/Crypt/GPGAbstract<span>.</span>php <span>on</span> line <span>278</span><span>#0</span> /usr/<span>local</span>/webdata/andy/fanli/citic/Crypt/GPGAbstract<span>.</span>php(<span>278</span>): Crypt_GPG_Engine<span>-></span>__construct(<span>Array</span>)
<span>#1</span> /usr/<span>local</span>/webdata/andy/fanli/citic/gpg2<span>.</span>php(<span>9</span>): Crypt_GPGAbstract<span>-></span>__construct()
<span>#2</span> {main}
  thrown <span>in</span> /usr/<span>local</span>/webdata/andy/fanli/citic/Crypt/GPG/Engine<span>.</span>php <span>on</span> line <span>601</span>Fatal error: Uncaught PEAR_Exception: gpg<span>-agent</span> binary <span>not</span> found<span>.</span><span>If</span> you are sure the gpg<span>-agent</span> is installed, please specify the location of the gpg<span>-agent</span> binary using the <span>'agent'</span> driver option<span>.</span><span>in</span> /usr/<span>local</span>/webdata/andy/fanli/citic/Crypt/GPGAbstract<span>.</span>php <span>on</span> line <span>278</span><span>#0</span> /usr/<span>local</span>/webdata/andy/fanli/citic/Crypt/GPGAbstract<span>.</span>php(<span>278</span>): Crypt_GPG_Engine<span>-></span>__construct(<span>Array</span>)
<span>#1</span> /usr/<span>local</span>/webdata/andy/fanli/citic/gpg2<span>.</span>php(<span>9</span>): Crypt_GPGAbstract<span>-></span>__construct()
<span>#2</span> {main}
  thrown <span>in</span> /usr/<span>local</span>/webdata/andy/fanli/citic/Crypt/GPG/Engine<span>.</span>php <span>on</span> line <span>601</span></code>

The first error reported in the browser I analyzed is a permissions issue, the second one is running in the shell is the real problem Where, follow the prompts and use brew to install gpg-agent.

After that I wrote the code as follows:

<code><span>require_once</span><span>'./Crypt/GPG.php'</span>;

<span>$gpg</span> = <span>new</span> Crypt_GPG();
<span>$key</span> = getKey();
<span>$gpg</span>->addDecryptKey(<span>'zhangsanfeng'</span>,<span>'123456'</span>);
<span>$encrypted</span> = file_get_contents(<span>'wait_for_decrpyt.txt.gpg'</span>);
<span>$data</span> = <span>$gpg</span>->decrypt(<span>$encrypted</span>);
<span>echo</span><span>'<pre class="brush:php;toolbar:false">'</span>;var_dump(<span>$data</span>);<span>exit</span>;</code>

Finally the decryption was successful! ! !

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the process of debugging Crypt_GPG, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn