为什么需要加密?
后端存储用户的密码,存放在数据库都是要进行加密处理的。
下图是官网的代码采用的是 sha256
加密,最下面的代码写的是 MD5加密
const crypto = require("crypto");
/**
* md5 加密
* @param {string} content 明文
* @returns
*/
function _md5(content) {
const md5 = crypto.createHash("md5");
return md5.update(content).digest("hex");
}
/**
* 加密方法
* @param {string} content 明文
* @returns
*/
function doCrypto(content) {
const str = `password=${content}&key=sd123ui_sd$@`;
return _md5(str);
}
module.exports = {
doCrypto,
};