Skip to content

Instantly share code, notes, and snippets.

@AdamMagaluk
Last active November 17, 2022 14:04
Show Gist options
  • Save AdamMagaluk/6629279 to your computer and use it in GitHub Desktop.
Save AdamMagaluk/6629279 to your computer and use it in GitHub Desktop.
Node.js aes 128 ecb encryption issue
var key = new Buffer('E8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA','hex');
var text = '6743C3D1519AB4F2CD9A78AB09A511BD';
var decipher = crypto.createDecipheriv('AES-128-ECB',key,'');
//decipher.setAutoPadding(false); this makes it work?
var k1 = decipher.update(text,'hex','hex'); // Why is this ''???
var k2 = decipher.update(text,'hex','hex');
console.log("de k1:" + k1) // is equal to '' but should be 014baf2278a69d331d5180103643e99a
console.log("de k2:" + k2) // is equal to 014baf2278a69d331d5180103643e99a
var cipher = crypto.createCipheriv('AES-128-ECB',key,'');
var k1 = cipher.update(text,'hex','hex');
var k2 = cipher.update(text,'hex','hex');
console.log("en k1:" + k1) // is equal to 064304184e1176a5e556cbb5e1b86a53
console.log("en k2:" + k2) // is equal to 064304184e1176a5e556cbb5e1b86a53
@FlatMapIO
Copy link

decipher.update(text,'hex','hex'); // Why is this ''???
var k1 = decipher.final()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment