小编Axi*_*nar的帖子

如何强制GPG接受来自STDIN的输入而不是尝试打开文件?

我试图在PHP脚本中的字符串中加入GPG clear-signed of text.我可以使GPG加密字符串中的文本,如下所示:

$encrypted = shell_exec("echo '$text' | gpg -e -a -r foo@bar.com --trust-model always");
Run Code Online (Sandbox Code Playgroud)

这是完美的,加密文本被发送到$ encrypted变量.这证明GNUPGHOME和GNUPG设置正确.

但是,当我尝试以相同的方式生成一个明确签名的消息:

$text = "googar";

$signature = exec("echo $passphrase | gpg -v --clearsign --no-tty --passphrase-fd 0 '$text' 2>&1 1> /dev/null", $output);
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

... string(51) "gpg: can't open `googar': No such file or directory"
[3]=>
string(46) "gpg: googar: clearsign failed: file open error"
}
Run Code Online (Sandbox Code Playgroud)

返回此错误,包含或不包含$ text变量周围的单引号.

如何强制GPG或shell_exec将$ text视为管道而不是查找文件?

我需要以这种方式回应密码(我知道,它'非常不安全',因为GPG无法在密码中传递密码作为命令行上的变量.

php bash lamp passphrase gnupg

3
推荐指数
1
解决办法
7366
查看次数

标签 统计

bash ×1

gnupg ×1

lamp ×1

passphrase ×1

php ×1