多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
893 B

2 years ago
  1. const CryptoJS = require('crypto-js') // 引用AES源码js
  2. const key = CryptoJS.enc.Utf8.parse('1234125432ABDDFF') // 十六位十六进制数作为密钥
  3. const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234121134') // 十六位十六进制数作为密钥偏移量
  4. // 加密方法
  5. export function Encrypt (word) {
  6. let srcs = CryptoJS.enc.Utf8.parse(word)
  7. let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
  8. return encrypted.ciphertext.toString().toUpperCase()
  9. }
  10. // 解密方法
  11. export function Decrypt (word) {
  12. let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
  13. let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
  14. let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
  15. let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
  16. return decryptedStr.toString()
  17. }