crypto-js md5加密和解密

直接上代码:

import CryptoJS from 'crypto-js'

const encodeFactor = 'zq87dopenf67eg'

// 加密
export function encrypt(txt) {
  var key = CryptoJS.enc.Utf8.parse(encodeFactor)
  var srcs = CryptoJS.enc.Utf8.parse(txt)
  var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
  return encrypted.toString()
}

// 解密
export function decrypt(txt) {
  var key = CryptoJS.enc.Utf8.parse(encodeFactor)
  var decrypt = CryptoJS.AES.decrypt(txt, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
  return CryptoJS.enc.Utf8.stringify(decrypt).toString()
}

你可能感兴趣的:(js,js)