脚本宝典收集整理的这篇文章主要介绍了php – 如何强制GPG接受STDIN的输入而不是尝试打开文件?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$encrypted = shell_exec("echo '$text' | gpg -e -a -r foo@bar.COM --trust-model always");
这是完美的,加密文本发送到$encrypted变量.这证明GNUPGHOME和GNUPG设置正确.
$text = "googar"; $signature = exec("echo $passphrase | gpg -v --clearsign --no-tty --passphrase-fd 0 '$text' 2>&1 1> /dev/null",$output);
我收到此错误:
... string(51) "gpg: can't oPEn `googar': No such file or directory" [3]=> string(46) "gpg: googar: clearsign Failed: file open error" }
返回此错误,包含或不包含$text变量周围的单引号.
如何强制GPG或shell_exec将$text视为管道而不是查找文件?
我需要以这种方式回应密码(我知道,它’非常不安全’,因为GPG无法在密码中传递密码作为命令行上的变量.
$descriptorspec = array( 0 => array("pipe","r"),1 => array("pipe","w"),2 => array("pipe",3 => array("pipe",); $pipes = false; $PRocess = proc_open("gpg -v --clearsign --no-tty --passphrase-fd 3",$descriptorspec,$pipes); if(is_resource($process)) { fwrITe($pipes[3],$passphrase); fclose($pipes[3]); fwrite($pipes[0],$text); fclose($pipes[0]); $output = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $retval = proc_close($process); echo "retval = $retval\n"; echo "output= $output\n"; echo "err= $stderr\n"; }
以上是脚本宝典为你收集整理的php – 如何强制GPG接受STDIN的输入而不是尝试打开文件?全部内容,希望文章能够帮你解决php – 如何强制GPG接受STDIN的输入而不是尝试打开文件?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。