Closed Alanscut closed 3 years ago
It took me a long time to understand that crypto-js uses MD5 to generate keys, whereas OpenSSL uses SHA256 to generate keys by default. Therefore, the OpenSSL encryption command should be as follows:
printf "hahahahahahahahahahahahahahahaha" | /usr/bin/openssl enc -aes-256-cbc -pass pass:"pass" -S "cc00000000000000" -e -base64 -p -nopad -md md5
result:
salt=CC00000000000000
key=A6E7A6052892AC89CF80A4AE58A74C7F7C65D54CB03812DC21AFF64F6BF23D19
iv =372D34788469EA8B2F7F9A3400AA65AA
U2FsdGVkX1/MAAAAAAAAAPqHYc4dS/BfUX3vlVvkdNhbVuW915Oz8W9dqjXv0ldA
Using crypto-js decrypt the ciphertext 'U2FsdGVkX1/MAAAAAAAAAPqHYc4dS/BfUX3vlVvkdNhbVuW915Oz8W9dqjXv0ldA' var CryptoJS = require('crypto-js');
const decrypted = CryptoJS.AES.decrypt(
'U2FsdGVkX1/MAAAAAAAAAPqHYc4dS/BfUX3vlVvkdNhbVuW915Oz8W9dqjXv0ldA',
'pass',
{
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.NoPadding,
blockSize: 256/32
}
)
console.log(decrypted.toString(CryptoJS.enc.Utf8));
It works fine, get the string hahahahahahahahahahahahahahahaha
Using openssl cli encrypted the string 'hahahahahahahahahahahahahahahaha'
result:
Using crypto-js decrypt the ciphertext 'U2FsdGVkX1/MAAAAAAAAANcQ3NNYy8zIC9jzcAHAwxNYIM6/88Xdy/eMhRD4kCxh'
expected:
hahahahahahahahahahahahahahahaha
but an error was reported:Error: Malformed UTF-8 data
crypto-js decrypts the cipertext in different ways from openssl. Does the crypto-js intend to provide support for decrypting the cipertext encrypted in openssl? @evanvosberg