UP AES 加解密增加提示&iv,mode,padding可配置
This commit is contained in:
parent
e572eb6593
commit
682ee54596
|
|
@ -137,17 +137,22 @@ tool.crypto = {
|
||||||
},
|
},
|
||||||
//AES加解密
|
//AES加解密
|
||||||
AES: {
|
AES: {
|
||||||
encrypt(data, secretKey){
|
encrypt(data, secretKey, config={}){
|
||||||
|
if(secretKey.length % 8 != 0){
|
||||||
|
console.warn("[SCUI error]: 秘钥长度需为8的倍数,否则解密将会失败。")
|
||||||
|
}
|
||||||
const result = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(secretKey), {
|
const result = CryptoJS.AES.encrypt(data, CryptoJS.enc.Utf8.parse(secretKey), {
|
||||||
mode: CryptoJS.mode.ECB,
|
iv: CryptoJS.enc.Utf8.parse(config.iv || ""),
|
||||||
padding: CryptoJS.pad.Pkcs7
|
mode: CryptoJS.mode[config.mode || "ECB"],
|
||||||
|
padding: CryptoJS.pad[config.padding || "Pkcs7"]
|
||||||
})
|
})
|
||||||
return result.toString()
|
return result.toString()
|
||||||
},
|
},
|
||||||
decrypt(cipher, secretKey){
|
decrypt(cipher, secretKey, config={}){
|
||||||
const result = CryptoJS.AES.decrypt(cipher, CryptoJS.enc.Utf8.parse(secretKey), {
|
const result = CryptoJS.AES.decrypt(cipher, CryptoJS.enc.Utf8.parse(secretKey), {
|
||||||
mode: CryptoJS.mode.ECB,
|
iv: CryptoJS.enc.Utf8.parse(config.iv || ""),
|
||||||
padding: CryptoJS.pad.Pkcs7
|
mode: CryptoJS.mode[config.mode || "ECB"],
|
||||||
|
padding: CryptoJS.pad[config.padding || "Pkcs7"]
|
||||||
})
|
})
|
||||||
return CryptoJS.enc.Utf8.stringify(result);
|
return CryptoJS.enc.Utf8.stringify(result);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue