var crypto = require (' crypto ');
Const IV = Buffer.from ([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
/**
* AES-CBC encrypted pkcs5padding padding
* @param data raw
* @param key key device Accesscode first 16 characters
* @returns Ciphertext buffer
*/
function Aes_128_cbc_encrypt (data, key) {
var encipher = Crypto.createcipheriv (' AES-128-CBC ', Buffer.from (key, ' ASCII '), IV);
var crypted = encipher.update (data, ' UTF8 ', ' binary ');
crypted + = encipher.final (' binary ');
Return Buffer.from (crypted, ' binary ');
}
/**
* AES-CBC decryption, returns the decrypted string
* @param crypted cipher
* @param key key device Accesscode first 16 characters
* @returns Clear Text
*/
function Aes_128_cbc_decrypt (crypted, key) {
var buf = new Buffer (crypted, ' hex ');
var decipher = crypto.createdecipheriv (' AES-128-CBC ', Buffer.from (key, ' ASCII '), IV);
var decoded = decipher.update (buf, ' binary ', ' UTF8 ');
decoded + = decipher.final (' UTF8 ');
return decoded;
}
Module.exports = {
Encrypt:aes_128_cbc_encrypt,
Decrypt:aes_128_cbc_decrypt
}
Nodejs and Java interactive AES-128-CBC encryption and decryption