on-site-robots-screen/src/utils/encrypt.js

30 lines
879 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 加解密方法
import CryptoJS from 'crypto-js'
// const key = 'zhst@bonus@zhst@bonus@1234567890' // 加密密钥
const key = 'jjbns@jysoft1088' // 加密密钥
const utf8Key = CryptoJS.enc.Utf8.parse(key)
// AES 加密UTF-8 处理)
export const encrypt = (message) => {
const utf8Message = CryptoJS.enc.Utf8.parse(message)
const encrypted = CryptoJS.AES.encrypt(utf8Message, utf8Key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
return encrypted.toString()
}
// AES 解密
export const decrypt = (encryptedBase64) => {
try {
const decrypted = CryptoJS.AES.decrypt(encryptedBase64, utf8Key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
return JSON.parse(CryptoJS.enc.Utf8.stringify(decrypted))
} catch (error) {
return encryptedBase64
}
}