crypto.js 730 字节
Newer Older
Y
yinpengxiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * @Author: 尹鹏孝
 * @Date: 2021-09-03 15:02:26
 * @LastEditTime: 2021-09-03 15:43:03
 * @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);

function enCrypto(key) {
    const result = CryptoJS.MD5(key + config.cryptoSecretKey).toString();
    return result;
}

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
}