mirror of
https://gitcode.com/gh_mirrors/vue/vue-vben-admin
synced 2026-05-18 01:27:47 +00:00
perf: move src/types to root
This commit is contained in:
38
src/utils/cache/aesEncryption.ts
vendored
38
src/utils/cache/aesEncryption.ts
vendored
@@ -1,38 +0,0 @@
|
||||
import type { lib } from 'crypto-js';
|
||||
|
||||
import { encrypt, decrypt } from 'crypto-js/aes';
|
||||
import Uft8, { parse } from 'crypto-js/enc-utf8';
|
||||
import pkcs7 from 'crypto-js/pad-pkcs7';
|
||||
|
||||
export interface EncryptionParams {
|
||||
key: string;
|
||||
iv: string;
|
||||
}
|
||||
|
||||
export class Encryption {
|
||||
private key: lib.WordArray;
|
||||
private iv: lib.WordArray;
|
||||
|
||||
constructor(opt: EncryptionParams) {
|
||||
const { key, iv } = opt;
|
||||
this.key = parse(key);
|
||||
this.iv = parse(iv);
|
||||
}
|
||||
|
||||
get getOptions() {
|
||||
return {
|
||||
// mode: mode.CBC,
|
||||
padding: pkcs7,
|
||||
iv: this.iv,
|
||||
};
|
||||
}
|
||||
|
||||
encryptByAES(str: string) {
|
||||
return encrypt(str, this.key, this.getOptions).toString();
|
||||
}
|
||||
|
||||
decryptByAES(str: string) {
|
||||
return decrypt(str, this.key, this.getOptions).toString(Uft8);
|
||||
}
|
||||
}
|
||||
export default Encryption;
|
||||
8
src/utils/cache/storageCache.ts
vendored
8
src/utils/cache/storageCache.ts
vendored
@@ -1,6 +1,8 @@
|
||||
import { cacheCipher } from '/@/settings/encryptionSetting';
|
||||
|
||||
import Encryption, { EncryptionParams } from './aesEncryption';
|
||||
import type { EncryptionParams } from '/@/utils/cipher';
|
||||
|
||||
import { AesEncryption } from '/@/utils/cipher';
|
||||
|
||||
export interface CreateStorageParams extends EncryptionParams {
|
||||
prefixKey: string;
|
||||
@@ -20,7 +22,7 @@ export const createStorage = ({
|
||||
throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
|
||||
}
|
||||
|
||||
const encryption = new Encryption({ key, iv });
|
||||
const encryption = new AesEncryption({ key, iv });
|
||||
|
||||
/**
|
||||
*Cache class
|
||||
@@ -31,7 +33,7 @@ export const createStorage = ({
|
||||
const WebStorage = class WebStorage {
|
||||
private storage: Storage;
|
||||
private prefixKey?: string;
|
||||
private encryption: Encryption;
|
||||
private encryption: AesEncryption;
|
||||
private hasEncrypt: boolean;
|
||||
/**
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user