node加密
Posted qiyc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node加密相关的知识,希望对你有一定的参考价值。
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加密的主要内容,如果未能解决你的问题,请参考以下文章