13 changed files with 108 additions and 102 deletions
@ -0,0 +1,38 @@ |
|||
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; |
|||
@ -1,35 +0,0 @@ |
|||
import CryptoES from 'crypto-es'; |
|||
|
|||
export interface EncryptionParams { |
|||
key: string; |
|||
iv: string; |
|||
} |
|||
|
|||
export class Encryption { |
|||
private key; |
|||
|
|||
private iv; |
|||
|
|||
constructor(opt: EncryptionParams) { |
|||
const { key, iv } = opt; |
|||
this.key = CryptoES.enc.Utf8.parse(key); |
|||
this.iv = CryptoES.enc.Utf8.parse(iv); |
|||
} |
|||
|
|||
get getOptions(): CryptoES.lib.CipherCfg { |
|||
return { |
|||
mode: CryptoES.mode.CBC, |
|||
padding: CryptoES.pad.Pkcs7, |
|||
iv: this.iv, |
|||
}; |
|||
} |
|||
|
|||
encryptByAES(str: string) { |
|||
return CryptoES.AES.encrypt(str, this.key, this.getOptions).toString(); |
|||
} |
|||
|
|||
decryptByAES(str: string) { |
|||
return CryptoES.AES.decrypt(str, this.key, this.getOptions).toString(CryptoES.enc.Utf8); |
|||
} |
|||
} |
|||
export default Encryption; |
|||
@ -1,9 +0,0 @@ |
|||
import { getEnv } from '/@/utils/env'; |
|||
import { useGlobSetting } from '/@/hooks/setting'; |
|||
import pkg from '../../../package.json'; |
|||
const globSetting = useGlobSetting(); |
|||
|
|||
// Generate cache key according to version
|
|||
export function getStorageShortName() { |
|||
return `${globSetting.shortName}__${getEnv()}${`__${pkg.version}`}__`.toUpperCase(); |
|||
} |
|||
Loading…
Reference in new issue