码迷,mamicode.com
首页 > 其他好文 > 详细

node加密

时间:2018-09-05 17:46:40      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:create   +=   encrypt   final   secret   upd   crypto   exp   nod   

var crypto = require(‘crypto‘);

exports.md5 = function (str) {
var md5sum = crypto.createHash(‘md5‘);
md5sum.update(str);
str = md5sum.digest(‘hex‘);
return str;
}


exports.encrypt = function (str, secret) {
var cipher = crypto.createCipher(‘aes192‘, secret);
var enc = cipher.update(str, ‘utf8‘, ‘hex‘);
enc += cipher.final(‘hex‘);
return enc;
}

exports.decrypt = function (str, secret) {
var decipher = crypto.createDecipher(‘aes192‘, secret);
var dec = decipher.update(str, ‘hex‘, ‘utf8‘);
dec += decipher.final(‘utf8‘);
return dec;
}

node加密

标签:create   +=   encrypt   final   secret   upd   crypto   exp   nod   

原文地址:https://www.cnblogs.com/qiyc/p/9591911.html

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