/**
* @description 加密
*/
const crypto = require('crypto') // nodejs 内置加密模块
const { CRPYTO_SECRET_KEY } = require('../conf/secretKeys') // 密钥,其实就是一个字符串
/**
* md5 加密
* @param content
*/
function _md5(content) {
const md5 = crypto.createHash('md5')
return md5.update(content).digest('hex')
}
/**
* 加密方法
* @param content 需要加密的字符串
*/
function doCrypto(content) {
const str = `password=${content}&key=${CRPYTO_SECRET_KEY}` // 拼接字符串,具体看项目要求
return _md5(str) // 返回加密后的字符串
}
// 导出函数
module.exports = {
doCrypto
}
// 使用
doCrypto(123)