Linux – Why can one box decrypt a file with openssl, but another one can’t

encryptionkali-linuxopenssl

I've got a simple encrypted file with a bit of text inside. It's encrypted with des3 and I know the key. However, I can't for the life of me get it to decrypt in my kali VM. It works fine in a LInux Mint VM however. I'm at my wits end here…. What am I doing wrong?

Here's the working decryption:

user@user-virtual-machine ~/Desktop $ openssl des3 -d -in TheKeyIsInHere.des3 -pass pass:aramisthethird
GJC13 says the key is nuorjbwyldurrurykpym
user@user-virtual-machine ~/Desktop $

And here's the broken one:

root@chkali:~/Desktop/new# openssl des3 -d -in TheKeyIsInHere.des3 -pass pass:aramisthethird
bad decrypt
139786246681728:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:crypto/evp/evp_enc.c:529:
�c]z��6z��oք��n&ΰ�Xqroot@chkali:~/Desktop/new# 

The file is the same in both cases (verified by md5sum).

Best Answer

The default hash used by openssl enc for password-based key derivation changed in 1.1.0 to SHA256 versus MD5 in lower versions. This produces a different key from the same password (and salt if used as it usually is), and trying to encrypt and decrypt with different keys produces garbage, an error, or both.

To fix this for existing data specify -md md5 in 1.1.0 to decrypt data from lower versions, and -md sha256 in lower versions to decrypt data from 1.1.0. Going forward, consider specifying -md explicitly. For details see https://crypto.stackexchange.com/questions/3298/is-there-a-standard-for-openssl-interoperable-aes-encryption/35614#35614 (disclosure: mine)

Related Question