linux - 加密/解密在两个不同的 openssl 版本之间不能很好地工作

我已经下载并编译了openssl-1.1.0

我可以使用 openssl 的相同 exe 加密和解密(和 here 一样)

me@ubuntu:~/openssl-1.1.0$ LD_LIBRARY_PATH=. ./apps/openssl aes-256-cbc -a -salt -in file.txt -out file.txt.enc
enter aes-256-cbc encryption password: 123
Verifying - enter aes-256-cbc encryption password:
me@ubuntu:~/openssl-1.1.0$ LD_LIBRARY_PATH=. apps/openssl aes-256-cbc -a -d -in file.txt.enc -out file.txt.dec
enter aes-256-cbc decryption password: 123

这个openssl使用:libcrypto.so.1.1, libssl.so.1.1

当我尝试使用安装在我的 ubuntu 上的 openssl 进行解密时,它使用: /lib/x86_64-linux-gnu/libssl.so.1.0.0,/lib/x86_64-linux-gnu/libcrypto.so.1.0.0

我收到一个错误:

me@ubuntu:~/openssl-1.1.0$ openssl aes-256-cbc -a -d -in file.txt.enc -out file.txt.dec2
enter aes-256-cbc decryption password: 123
bad decrypt
140456117421728:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:539:

什么可能导致这种情况? 谢谢

最佳答案

Openssl 1.1 中的默认摘要从 MD5 更改为 SHA256

尝试使用 -md md5

cgs@ubuntu:~$ echo "it-works!" > file.txt
cgs@ubuntu:~$ LD_LIBRARY_PATH=~/openssl-1.1.0/ openssl-1.1.0/apps/openssl aes-256-cbc -a -salt -in ~/file.txt -out ~/file.txt.enc -md md5
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
cgs@ubuntu:~$ LD_LIBRARY_PATH=~/openssl-1.0.1f/ openssl-1.0.1f/apps/openssl aes-256-cbc -a -in ~/file.txt.enc -d
enter aes-256-cbc decryption password:
it-works!

丑陋的细节:

aes(或其他加密)并未按原样使用输入的密码,但该命令隐式从中派生 key 。 key 派生使用在 openssl 1.1 Use SHA256 not MD5 as default digest. 中更改的消息摘要

如果你想保持简单的密码,而不是开始弄乱键控(-K,-iv),只需使用 -md 强制使用相同的摘要

https://stackoverflow.com/questions/39637388/

相关文章:

linux - 打印当前一周的星期一的日期(在 bash 中)

ruby - 在本地文件夹中安装 gem

linux - 获取变量中的当前路径并使用它

linux - 顶部的进程命令

linux - i386 输入文件架构与 i386 不兼容 :x86-64

linux - 如何递归列出所有文件和目录

python - 如何从命令行下载python?

python - 我如何从 Ubuntu 上的源代码自己构建 python?

python - 缺少 python bz2 模块

python - 错误 : command 'gcc' failed with exit statu