I have these two code snippets. The first one uses createCipher
from node:crypto
and the second one is supposed to generate the same result using CryptoJS
:
const dataText = 'Hello';
const crypto = require('node:crypto');
const c = crypto.createCipher( 'aes-128-ecb', '2C8E29E736CB9514DD93C4D111244990' );
const r = c.update( dataText, 'utf-8', 'hex' ) + c.final( 'hex' );
console.log(r);
const CryptoJS = require('crypto-js');
const encrypted = CryptoJS.AES.encrypt(dataText, '2C8E29E736CB9514DD93C4D111244990', {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
}).ciphertext.toString(CryptoJS.enc.Hex);
console.log(encrypted);
The output should be the same but I get different results:
8a78f5302082a5e59aa5d28a1453cba1
f1b3424bb507a6e6185c1cf91527634d
How should I modify the second snippet to get a match with the first one?