需求
使用 node.js 进行AES 加密解密,代码如下
代码
// Nodejs encryption with CTR
const crypto = require('crypto');
const algorithm = 'aes-256-cbc';
const keyStr = '2ba27190770c3203a3094b1d212f5e2f'
const ivStr = keyStr.substr(0, 16)
const keyByte = Buffer.from(keyStr)
const ivByte = Buffer.from(ivStr)
function encrypt(text) {
let cipher = crypto.createCipheriv(algorithm, Buffer.from(keyStr), ivByte);
let encrypted = cipher.update(text);
encrypted = Buffer.concat