PHP/GnuPG 解密——语法错误?
我正在使用 php 调用 gpg,但出现管道错误。我想如果我从文件中读取密码,我可以将其通过管道传递给命令本身?但是,我不断收到:语法错误:“|”意外
这是代码:(
注意:文件正在 foreach 循环中迭代......)
foreach($files as $k => $v) {
$encrypted = $v;
$filename = explode('.',$v);
$decrypted = $filename[0].'.txt';
shell_exec("echo $passphrase | gpg --no-tty --passphrase-fd 0 -o $decrypted -d $encrypted");
}
I'm using php to invoke gpg, but I'm getting a pipe error. I thought that if I read in the password from a file, I could then pipe it to the command itself? But, I keep getting: Syntax error: "|" unexpected
Here's the code:
(Note: The files are being iterated over in a foreach loop...)
foreach($files as $k => $v) {
$encrypted = $v;
$filename = explode('.',$v);
$decrypted = $filename[0].'.txt';
shell_exec("echo $passphrase | gpg --no-tty --passphrase-fd 0 -o $decrypted -d $encrypted");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以打印这些行,然后在终端中运行它们,看看它们是否真的按预期工作。
也许您的输入中有一些奇怪的字符需要转义,请将您的 PHP 变量放在引号中,带空格的文件名可能很危险。请参阅 escapeshellarg 和 escapeshellcmd。
maybe you can print the lines instead and then run them in a terminal to see if they really work as expected.
Maybe there is some weird character in your input that needs to be escaped, and please put your PHP variables in quotes, filenames with spaces could be dangerous. See escapeshellarg and escapeshellcmd.