A simple encryption/decryption using CryptoJS gives me a weird output. Can anyone point me to where the code is wrong? (I'm looking for the output in the console)
var code = "Testcode";
var diterations = 1000;
var defaultkeyBytes = new CryptoJS.PBKDF2(code, code, { hasher: CryptoJS.algo.SHA512, keySize: 48 / 4, iterations: diterations });
var key = new CryptoJS.lib.WordArray.init(defaultkeyBytes.words, 32);
var iv = new CryptoJS.lib.WordArray.init(defaultkeyBytes.words.splice(32 / 4), 16);
var data = "test message new test message";
var h = CryptoJS.AES.encrypt(data, key, { iv: iv, mode: CryptoJS.mode.CBC });
console.log(h.toString());
var z = CryptoJS.AES.decrypt(h, key, { iv: iv, mode: CryptoJS.mode.CBC });
console.log(z.toString());
Output :
"Running fiddle"
"qx84iCiNL1YYWJhE6nG8KZxOCh4VGOBTaeCEAjy1P+s=" "74657374206d657373616765206e65772074657374206d657373616765"