【问题标题】:openssl aes-256 encrypted file on windows cant be decrypted on linuxwindows上的openssl aes-256加密文件无法在linux上解密
【发布时间】:2011-06-12 07:34:16
【问题描述】:

我有一个在 windows apache 上运行的 php 文档存储库应用程序,该应用程序将使用以下命令对任何上传的文档进行 aes 加密:

echo MyPass34 | openssl.exe aes-256-cbc -pass stdin -salt -in somefile.pdf -out somefile.pdf

并在下载时解密它们,使用以下命令:

echo MyPass34 | openssl.exe aes-256-cbc -pass stdin -d -in somefile.pdf -out decriptedfile.pdf

到目前为止,该应用程序运行良好,人们正在上传和下载他们的文件,而他们在服务器上保持加密,现在的问题是这个应用程序已被移动到 apache linux 服务器,现在加密的文件在 windows 上没有在 linux 上正确解密。

这是为什么?是否有可能对解密命令进行调整,以便再次正确解密该文件?

PS:在linux上加密的新文件被正确解密,与windows中一样,是encode-on-windows decoded-on-linux情况失败。

【问题讨论】:

    标签: linux encryption openssl aes echo


    【解决方案1】:

    我找到了解决方案 :-),问题是 windows echo 命令在密码末尾添加了三个字符,即空格、CR 和 LF 字符,而 linux echo 命令似乎没有输入这些字符,所以openssl 命令未收到用于加密的相同密码。

    解决方案是在 Linux 中将这三个字符添加到密码中,这是可能的,因为 echo 命令具有用于插入十六进制值的转义序列。因此,按照我的示例,现在在 linux 中为我工作的正确解密命令是:

    echo $'MyPass34\x20\x0d\x0a' | /usr/bin/openssl aes-256-cbc -pass stdin -d -in somefile.pdf -out decriptedfile.pdf
    

    希望这可以帮助别人!

    【讨论】:

    • 您可以使用-k 'MyPass34'直接指定openssl的密码,而不是使用管道。
    • 别忘了,在 Linux 上,可以使用“ps”命令查看任何进程的参数。最好将密码放在不需要它在命令行上或任何可见位置的地方。
    猜你喜欢
    • 2020-01-20
    • 1970-01-01
    • 2014-01-30
    • 2017-08-28
    • 1970-01-01
    • 2011-03-09
    • 2013-08-12
    • 2013-08-11
    • 1970-01-01
    相关资源
    最近更新 更多