ブラウザ側のエラー出力情報:
<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>
ブラウザで報告される最初のエラーは権限の問題で、実際の問題はシェルでの 2 番目のエラーの実行です。プロンプトに従い、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 チュートリアルに興味のある友人にとって役立つことを願っています。