*/
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
};
此处,只针对可逆加密。
总结
以上所述是小编给大家介绍的NodeJS加密解密及node-rsa加密解密用法详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!









