My nodejs 3DES encryption didn't get expected result. Is there anything wrong with my code?
let cryptojs = require('crypto-js')
var key = '412B121B61C9782FCA6B983AF29862AA';
var message = '46574669849832145886804657466984';
key = cryptojs.enc.Hex.parse(key);
message = cryptojs.enc.Hex.parse(message);
var result = cryptojs.TripleDES.encrypt(message, key, {mode: cryptojs.mode.ECB, padding: cryptojs.pad.NoPadding});
console.log (result.key.toString());
console.log (result.ciphertext.toString());
console.log (result.toString());
the output is
412b121b61c9782fca6b983af29862aa
511e4f67d9dd0f840c4689348e2e7ce3
UR5PZ9ndD4QMRok0ji584w==
however expected should be
2B4D7E0FE9672FEA5CDF60735B58D356
TripleDES keys are, as you might imagine, three times the length of DES keys. The key you are using is 128-bits whereas the key size expected is 192-bits.
What this means is that you have 2 of the 3 required keys, e.g. 2 lots of 64-bits, and a third lot of 64-bits is missing.
Some implementations of TripleDES will simply use the first lot of 64-bits as the third lot of 64-bits if you omit them. CryptoJS doesn't do this for you, it just sets the third lot of 64-bits to be 0. The result you have comes from an implementation that uses the first key as the third key, so we have to simulate this behavior in CryptoJS.
To solve this problem, change the value of your key to the following: 412B121B61C9782FCA6B983AF29862AA412B121B61C9782F
.