码迷,mamicode.com
首页 > Web开发 > 详细

nodejs 核心模块crypto

时间:2016-05-01 14:56:35      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:

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

 

nodejs 核心模块crypto

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!