util.js 434 Bytes
Newer Older
xulili's avatar
xulili committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
const CryptoJS = require('crypto-js')

let util = {};
let key = 'guobomimajiamics'
let cryptKey = CryptoJS.enc.Utf8.parse(key);

// 加密
util.encrypt = function (str) {
  if (!str) return null
  let srcs = CryptoJS.enc.Utf8.parse(str);
  const cryptInfo = CryptoJS.AES.encrypt(srcs, cryptKey, {
    iv: cryptKey,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7
  })
  return cryptInfo.toString()
}

export default util