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);

 

posted @ 2016-05-01 14:04  致敬科神  阅读(853)  评论(0编辑  收藏  举报