小编典典

加密/解密在两个不同的openssl版本之间无法正常工作

linux

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

我可以加密和解密使用的相同的exe文件openssl

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

当我尝试openssl使用ubuntu上安装的文件进行解密时,它使用: /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:

是什么原因造成的?谢谢


阅读 1417

收藏
2020-06-02

共1个答案

小编典典

在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(或其他加密)按原样使用,但该命令会从中隐式派生密钥。密钥派生使用在openssl
1.1中更改的消息摘要。使用SHA256而不是MD5作为默认摘要。

如果您想使用简单的密码,而又不想与键盘格斗(-K,-iv)混淆,只需使用 -md 强制相同的摘要 即可

2020-06-02