javax.crypto.Cipher equivalent code in Nodejs Crypto Javascript

别来无恙 提交于 2019-12-04 19:10:09
Vinay Bhargav

Just need to change -

crypto.createCipher('aes-128-ecb', fcKey, "");

to

crypto.createCipheriv('aes-128-ecb', fcKey, "");

Reason is simple - createCipher method treats second parameter as Encryption Password while it is an Encryption Key.

My bad, even after reading this answer, I've used wrong method (crypto.createCipher instead of crypto.createCipheriv). Below is proper working code in nodejs. That was all needed.

function freeChargeEncryptAES(token){
    var fcKey = "11111111111111111111".substring(0, 16);
    var cipher = crypto.createCipheriv('aes-128-ecb', fcKey, "");
    var encrypted = cipher.update(token,'ascii','hex');
    encrypted += cipher.final('hex');
    return encrypted;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!