crypto.js 897 字节
Newer Older
Y
yinpengxiao 已提交
1 2 3
/*
 * @Author: 尹鹏孝
 * @Date: 2021-09-03 15:02:26
Y
yinpengxiao 已提交
4
 * @LastEditTime: 2021-09-03 16:53:33
Y
yinpengxiao 已提交
5 6 7 8 9 10 11 12
 * @LastEditors: Please set LastEditors
 * @Description: 密码加密
 * @FilePath: \koa2-test-api\src\utils\cropto.js
 */

const CryptoJS = require('crypto-js');
const config = require("../config/config.js")
console.log(config);
Y
yinpengxiao 已提交
13 14 15 16 17
/**
 * CryptoJS的MD5加密
 * @param {string} key MD5加密
 * @returns 
 */
Y
yinpengxiao 已提交
18 19 20 21
function enCrypto(key) {
    const result = CryptoJS.MD5(key + config.cryptoSecretKey).toString();
    return result;
}
Y
yinpengxiao 已提交
22 23 24 25 26
/**
 * CryptoJS的MD5解密
 * @param {string} cipherText 加密后的值
 * @returns 
 */
Y
yinpengxiao 已提交
27 28 29 30 31 32 33 34 35 36
function deCrypto(cipherText) {
    var bytes = CryptoJS.MD5.decrypt(cipherText, config.cryptoSecretKey);
    var originalText = bytes.toString(CryptoJS.enc.Utf8);
    console.log('MD5解密:', originalText);
    return originalText;
}
module.exports = {
    enCrypto,
    deCrypto
}