1、安装依赖
npm i -S crypto
2、代码如下
const crypto = require(‘crypto’)
function md5Crypto(password){
const hash = crypto.createHash(‘md5’)
hash.update(password)
const md5Password = hash.digest(‘hex’)
return md5Password;
}
module.exports = md5Crypto
3、外部导入直接把md5Crypto当作一个函数使用