不多说,直接上代码
//crypto是node.js内置的库var crypto = require("crypto");//可加密,可解密的aes192module.exports.aes192_encode = function(text, key) { var cipher = crypto.createCipher('aes192', key); var crypted = cipher.update(text+"", 'utf8', 'hex'); crypted += cipher.final('hex'); return crypted;};module.exports.aes192_decode = function(message, key) { var decipher = crypto.createDecipher('aes192', key); var dec = decipher.update(message, 'hex', 'utf8'); dec += decipher.final('utf8'); //解密之后的值 return dec;};//不可逆加密md5module.exports.md5 = function(data) { var buf = new Buffer(data+""); var str = buf.toString("binary"); return crypto.createHash("md5").update(str).digest("hex");};//需要密钥的不可逆加密hamcmodule.exports.hamc = function(data,key){ var buf = new Buffer(data); var str = buf.toString("binary"); return crypto.createHmac('sha1', key).update(str).digest("hex");};