如何使用crypto做md5加密

2020-03-04  本文已影响0人  回不去的那些时光

安装 crypto 库

npm i -S crypto

index

// utils/index
const crypto = require('crypto')

function md5(s) {
  // 注意参数需要为 String 类型,否则会出错
  return crypto.createHash('md5')
    .update(String(s)).digest('hex');
}

constant

// utils/constant
module.exports = {
    PWD_SALT: 'admin_imooc_node',
}

使用

const { md5 } = require('../utils/index')
const { PWD_SALT } = require('../utils/constant')

md5(`${password}${PWD_SALT}`)
上一篇 下一篇

猜你喜欢

热点阅读