| 11 | } |
| 12 | |
| 13 | export class AesEncryption { |
| 14 | private key; |
| 15 | private iv; |
| 16 | |
| 17 | constructor(opt: Partial<EncryptionParams> = {}) { |
| 18 | const { key, iv } = opt; |
| 19 | if (key) { |
| 20 | this.key = parse(key); |
| 21 | } |
| 22 | if (iv) { |
| 23 | this.iv = parse(iv); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | get getOptions() { |
| 28 | return { |
| 29 | mode: ECB, |
| 30 | padding: pkcs7, |
| 31 | iv: this.iv, |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | encryptByAES(cipherText: string) { |
| 36 | return encrypt(cipherText, this.key, this.getOptions).toString(); |
| 37 | } |
| 38 | |
| 39 | decryptByAES(cipherText: string) { |
| 40 | return decrypt(cipherText, this.key, this.getOptions).toString(UTF8); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | export function encryptByBase64(cipherText: string) { |
| 45 | return UTF8.parse(cipherText).toString(Base64); |
nothing calls this directly
no outgoing calls
no test coverage detected