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/

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-08-26
  • 2022-12-23
  • 2022-02-03
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-01-11
  • 2022-12-23
相关资源
相似解决方案