首頁 > 後端開發 > php教程 > 調試Crypt_GPG的過程

調試Crypt_GPG的過程

WBOY
發布: 2016-07-29 09:15:51
原創
1146 人瀏覽過

在瀏覽器端的錯誤輸出訊息:

<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>
登入後複製

命令列輸出的錯誤訊息:

<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教程有興趣的朋友有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板