nodejs 核心模块crypto

crypto用于加密解密

'use strict'
var crypto=require('crypto');

var data={age:18}
var key='dt';//定义一个钥匙
var plaintext = JSON.stringify(data);
var cryped = '';
// aes192是一种加密算法,此处也可换成blowfish
var cipher = crypto.createCipher('aes192', key);//加密
cryped += cipher.update(plaintext, 'utf8', 'hex');
cryped += cipher.final('hex');
console.log(cryped);

var decryped='';
var decipher = crypto.createDecipher('aes192', key);//解密
decryped += decipher.update(cryped, 'hex', 'utf8');
decryped += decipher.final('utf8');
console.log(decryped);

原文地址:https://www.cnblogs.com/ytu2010dt/p/5450450.html