const crypto = require('crypto');
const key = 'mysecretkey';
const data = 'Hello, World!';
// 加密
const cipher = crypto.createCipher('aes-256-cbc', key);
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log('加密后的数据:', encrypted);
// 解密
const decipher = crypto.createDecipher('aes-256-cbc', key);
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log('解密后的数据:', decrypted);const crypto = require('crypto');
const key = 'mysecretkey';
const data = 'Hello, World!';
// 加密
const cipher = crypto.createCipher('des-ecb', key);
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log('加密后的数据:', encrypted);
// 解密
const decipher = crypto.createDecipher('des-ecb', key);
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log('解密后的数据:', decrypted);本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com
