This commit is contained in:
2025-03-25 09:56:54 +08:00
parent 79fcae935b
commit 2179f3f8b7
4 changed files with 49 additions and 0 deletions

30
src/utils/AESCrypto.js Normal file
View File

@@ -0,0 +1,30 @@
import AES from 'crypto-js/aes.js';
import utf8 from 'crypto-js/enc-utf8.js';
class AESCrypto {
/**
* 密钥
* @type {string}
*/
static #AES_KEY = process.env.VITE_AES_KEY;
/**
* AES加密
* @param context {string} 加密内容
*/
static encrypt = (context) => {
return AES.encrypt(context, this.#AES_KEY).toString();
}
/**
* AES解密
* @param context {string}
* @return {string}
*/
static decrypt = (context) => {
const bytes = AES.decrypt(context, this.#AES_KEY);
return bytes.toString(utf8);
}
}
export default AESCrypto;