在瀏覽器端的錯誤輸出訊息:
<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' "/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 <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>
命令列輸出的錯誤訊息:
<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>
第一個browser中報的錯我分析是權限問題,第二個在shell中運作才是其真正的問題所在,根據提示,使用brew安裝gpg-agent。
之後我寫程式碼如下:
<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>
終於解密成功! ! !
版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。
以上就介紹了調試Crypt_GPG的過程,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。