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.
48 lines
1.5 KiB
48 lines
1.5 KiB
import CryptoJS from 'crypto-js' |
|
|
|
export default class crypto { |
|
/** |
|
* token加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致 |
|
* @type {string} |
|
*/ |
|
|
|
static cryptoKey: string = 'Zc72Ghs63Z2b8jl7PXnr68r7B69xmRLX' |
|
/** |
|
* 报文加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致 |
|
* @type {string} |
|
*/ |
|
static aesKey: string = 'OPGbg7HHRiClg4u9euSPXt5Dtwed9qcG' |
|
|
|
/** |
|
* 本地加密key 使用@org.springblade.test.CryptoKeyGenerator获取,需和后端配置保持一致 |
|
* @type {string} |
|
*/ |
|
static localKey: string = 'LaiJiangKeLiuXingMing_LaoTie6666' |
|
|
|
/** |
|
* aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey); |
|
*/ |
|
static encryptAES(data: string, key: string) { |
|
const dataBytes = CryptoJS.enc.Utf8.parse(data) |
|
const keyBytes = CryptoJS.enc.Utf8.parse(key) |
|
const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, { |
|
iv: keyBytes, |
|
mode: CryptoJS.mode.CBC, |
|
padding: CryptoJS.pad.Pkcs7, |
|
}) |
|
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext) |
|
} |
|
|
|
/** |
|
* aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey); |
|
*/ |
|
static decryptAES(data: string | CryptoJS.lib.CipherParams, key: string) { |
|
const keyBytes = CryptoJS.enc.Utf8.parse(key) |
|
const decrypted = CryptoJS.AES.decrypt(data, keyBytes, { |
|
iv: keyBytes, |
|
mode: CryptoJS.mode.CBC, |
|
padding: CryptoJS.pad.Pkcs7, |
|
}) |
|
return CryptoJS.enc.Utf8.stringify(decrypted) |
|
} |
|
}
|
|
|