perf: move src/types to root

This commit is contained in:
Vben
2021-02-26 20:09:24 +08:00
parent a84586e2f4
commit fcee7d4eb7
36 changed files with 195 additions and 162 deletions

View File

@@ -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;

View File

@@ -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;
/**
*