My problem is that the newer versions of OpenSSL aren't compatible with default settings of CryptoJS.
The default hash used by openssl enc for password-based key derivation changed in 1.1.0 to SHA256 versus MD5 in lower versions. https://unix.stackexchange.com/questions/344150/why-can-one-box-decrypt-a-file-with-openssl-but-another-one-cant/344586#344586
By default, CryptoJS uses MD5 for its key derivation. OpenSSL used MD5, but now in OpenSSL versions >=1.1.0 it's using SHA256.
So if I pass -md md5
to OpenSSL, CryptoJS is compatible:
echo "Hello World" | openssl enc -aes-256-cbc -md md5 -pass pass:"Secret Passphrase" -e -base64
output: U2FsdGVkX19aufvaqQQ89scaApBos6oFCyqPj7IKUFk=
CryptoJS:
CryptoJS.AES.decrypt('U2FsdGVkX19aufvaqQQ89scaApBos6oFCyqPj7IKUFk=', 'Secret Passphrase').toString(CryptoJS.enc.Utf8);
output: "Hello World"
But now if I want to use SHA256 instead of MD5 (removing the -md md5
):
echo "Hello World" | openssl enc -aes-256-cbc -pass pass:"Secret Passphrase" -e -base64
output: U2FsdGVkX1/5LLkFkTpawh1im4a/fCco5hS42cjn/fg=
CryptoJS:
CryptoJS.AES.decrypt('U2FsdGVkX1/5LLkFkTpawh1im4a/fCco5hS42cjn/fg=', 'Secret Passphrase').toString(CryptoJS.enc.Utf8);
output: null
How do I tell CryptoJS to use SHA256 instead of MD5 for its key derivation?