DES加密方式已证实可被破解,客户要求跟换,故采用AES加密
import CryptoJS from "crypto-js"
const key = CryptoJS.enc.Utf8.parse('key');
const iv = CryptoJS.enc.Utf8.parse('iv');
export const encodeData = function(data) {
if (data) {
return CryptoJS.AES.encrypt(data, key, {
iv,
padding: CryptoJS.pad.Pkcs7, // 偏移量web端都是7
mode: CryptoJS.mode.CBC // 模式
}).toString()
} else {
return ""
}
}
export const decodeData = function(data) {
if (data) {
try {
return CryptoJS.AES.decrypt(data, key, {
iv,
padding: CryptoJS.pad.Pkcs7,
mode: CryptoJS.mode.CBC
}).toString(CryptoJS.enc.Utf8)
} catch (e) {
return "decode failure"
} finally {}
} else {
return ""
}
}