首页 > Web开发 > 详细

nodejs加密解密

时间:2015-08-26 13:35:01      阅读:243      评论:0      收藏:0      [点我收藏+]

nodejs是通集成在内核中的crypto模块来完成加密解密。

常用加密解密模块化代码:

/**
 * Created by linli on 2015/8/25.
 */
var crypto = require(‘crypto‘);

//加密
exports.cipher = function(algorithm, key, buf) {
    var encrypted = "";
    var cip = crypto.createCipher(algorithm, key);
    encrypted += cip.update(buf, ‘binary‘, ‘hex‘);
    encrypted += cip.final(‘hex‘);
    return encrypted
};

//解密
exports.decipher = function(algorithm, key, encrypted) {
    var decrypted = "";
    var decipher = crypto.createDecipher(algorithm, key);
    decrypted += decipher.update(encrypted, ‘hex‘, ‘binary‘);
    decrypted += decipher.final(‘binary‘);
    return decrypted
};

此处,只针对可逆加密。

更详细内容请访问:http://blog.fens.me/nodejs-crypto/

 

nodejs加密解密

原文:http://www.cnblogs.com/kevalin/p/4759898.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!