nodejs aes加解密128算法,base64编码

来源:互联网 发布:redis怎么存储数据 编辑:程序博客网 时间:2024/06/07 17:13
function encryption(data) {    var iv = "";    var clearEncoding = 'utf8';    var cipherEncoding = 'base64';    var cipherChunks = [];    var cipher = CRYPTO.createCipheriv('aes-128-ecb', key, iv);    cipher.setAutoPadding(true);    cipherChunks.push(cipher.update(data, clearEncoding, cipherEncoding));    cipherChunks.push(cipher.final(cipherEncoding));    return cipherChunks.join('');}function decryption(data,key){    var iv = "";    var clearEncoding = 'utf8';    var cipherEncoding = 'base64';    var cipherChunks = [];    var decipher = crypto.createDecipheriv('aes-128-ecb', key, iv);    decipher.setAutoPadding(true);    cipherChunks.push(decipher.update(data, cipherEncoding, clearEncoding));    cipherChunks.push(decipher.final(clearEncoding));    console.log( cipherChunks.join(''))}
0 0