I am using AES 256 CBC with PBKDF2 to decrypt file. Salt is generated randomly.
I want to decrypt file using CryptoJS.
CryptoJS gives correct key, IV and salt. It is matching with openSSL generated key, IV and salt.
It gives first 32 characters output correct and rest of thing are garbage, when we call decrypt function of aes.
Content of test.txt
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
This is test file. It is containing secret in this file.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccccccccc
dddddddddddddddddddddddddddddddddddddddd
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Decrypted text:
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Decrypted Text UTF8 :: This is test file. It is containjf"HT'Ý8evE>µª?É° ¬m¼ö#ÉF2c8£¥¡2Aa/ ëêCó[|·´]
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Code snapshot:
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
var decrypted = CryptoJS.AES.decrypt(
{
ciphertext: cipherParams.ciphertext,
salt: cipherParams.salt
},
key,
{
iv: ivText,
mode: CryptoJS.mode.CBC,
algorithm: CryptoJS.algo.AES,
blockSize: 256/32
});
console.log( "Decrypted Text :: " + decrypted );
alert( "Decrypted Text :: " + decrypted );
console.log( "Decrypted Text UTF8 :: " + hex_to_ascii(decrypted) );
alert( "Decrypted Text UTF8 :: " + hex_to_ascii(decrypted) );
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
CryptoJS AES 256 CBC decrypt only first 32 character
I am encrypting file using openssl command. Command with details mentioned below.
OpenSSL encrypt Command: openssl enc -aes-256-cbc -in test.txt -out test_long_AES256CBC_a_PBKDF2.bizrtc -k abcdefghijklmnopqrstuvwxyz012345 -e -a -pbkdf2 -p
I am using AES 256 CBC with PBKDF2 to decrypt file. Salt is generated randomly.
I want to decrypt file using CryptoJS. CryptoJS gives correct key, IV and salt. It is matching with openSSL generated key, IV and salt. It gives first 32 characters output correct and rest of thing are garbage, when we call decrypt function of aes.
Content of test.txt $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ This is test file. It is containing secret in this file. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccccccccccccccccccccccccccccccccc dddddddddddddddddddddddddddddddddddddddd $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Decrypted text: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Decrypted Text UTF8 :: This is test file. It is containjf"HT'Ý8evE>µª?É° ¬m¼ö#ÉF2c8£¥¡2Aa/ ëêCó[|·´] $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ Code snapshot: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ var decrypted = CryptoJS.AES.decrypt( { ciphertext: cipherParams.ciphertext, salt: cipherParams.salt }, key, { iv: ivText, mode: CryptoJS.mode.CBC, algorithm: CryptoJS.algo.AES, blockSize: 256/32 });
console.log( "Decrypted Text :: " + decrypted ); alert( "Decrypted Text :: " + decrypted );
console.log( "Decrypted Text UTF8 :: " + hex_to_ascii(decrypted) ); alert( "Decrypted Text UTF8 :: " + hex_to_ascii(decrypted) ); $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$