update
This commit is contained in:
30
src/utils/AESCrypto.js
Normal file
30
src/utils/AESCrypto.js
Normal 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;
|
||||
Reference in New Issue
Block a user