问题描述
我已经下载并编译了openssl-1.1.0
.
我可以使用 openssl
的同一个 exe 加密和解密(就像 此处)
I can encrypt and decrypt using the same exe of openssl
(as is 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
When I try to decrypt with the openssl
installed on my ubuntu, which uses:/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:
什么可能导致这种情况?谢谢
What may cause this?Thanks
推荐答案
Openssl 1.1 中默认摘要从 MD5 更改为 SHA256
The default digest was changed from MD5 to SHA256 in Openssl 1.1
尝试使用 -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.
The entered password is not used as is by aes (or other encryption) but the command implicitly derives a key from it. The key derivation uses message digest that was changed in openssl 1.1 Use SHA256 not MD5 as default digest.
如果您想保持简单的密码,而不是开始弄乱键控(-K,-iv),只需使用 -md 强制使用相同的摘要
In case you want to keep it simple password, and not start messing with the keying martial (-K,-iv) just force the same digest with -md
这篇关于加密/解密在两个不同的 openssl 版本之间不能很好地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!