青鸟ai,pc版仓库
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.

49 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 javaAesUtil.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 javaAesUtil.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)
}
}