bash 脚本中的 OpenSSL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1250319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenSSL in bash script
提问by alvatar
I'm trying to make a bash script in linux where some encrypted data is embedded and then retrieved and decrypted with openssl, like this:
我正在尝试在 linux 中制作一个 bash 脚本,其中嵌入了一些加密数据,然后使用 openssl 检索和解密,如下所示:
cat | openssl des3 -d -a -salt -pass pass:asdf > output.txt <<EOF
U2FsdGVkX1/zN55FdyL5j1nbDVt5vK4V3WLQrnHPoycCJPwWO0ei3PCrrMqPaxUH.....blablablah data
EOF
The only problem with this, that would otherwise work, is that I have to hit enter when the script reaches this position. I have tried changing the way \n are placed, but no luck.
唯一的问题是,当脚本到达这个位置时,我必须按回车键,否则会起作用。我试过改变 \n 的放置方式,但没有运气。
I can't afford to press manually enter for all the files that are going to be embedded like this one!!
对于将要嵌入的所有文件,我无法手动按 Enter 键!!
Thanks for your help!
谢谢你的帮助!
回答by Norman Ramsey
A couple of things wrong here:
这里有一些错误:
You shouldn't use both
cat | ...and also a here document (<<EOF). Use one or the other.Your example isn't testable because the example text is not the DES3 encryption of any input.
您不应该同时使用两者
cat | ...和 here 文档 (<<EOF)。使用其中之一。您的示例不可测试,因为示例文本不是任何输入的 DES3 加密。
This example works as expected:
此示例按预期工作:
cat ~/.profile | openssl des3 -e -a -salt -pass pass:asdf -out /tmp/output.txt
That is, it writes an encrypted version of ~/.profile, base64 encoded, to file /tmp/output.txt.
也就是说,它将~/.profilebase64 编码的加密版本写入文件 /tmp/output.txt。
Here's a working decryption example with a here document:
这是一个带有 here 文档的有效解密示例:
openssl des3 -d -a -salt -pass pass:asdf <<EOF
U2FsdGVkX1/03DBd+MpEKId2hUY82cLWpYltYy2zSsg=
EOF
Try this in the safety and comfort of your own home...
在您自己的家中安全舒适地尝试这个......

