| 25 | } |
| 26 | |
| 27 | class AesEncryption implements Encryption { |
| 28 | private readonly key; |
| 29 | private readonly iv; |
| 30 | |
| 31 | constructor({ key, iv }: EncryptionParams) { |
| 32 | this.key = parse(key); |
| 33 | this.iv = parse(iv); |
| 34 | } |
| 35 | |
| 36 | get getOptions() { |
| 37 | return { |
| 38 | mode: CTR, |
| 39 | padding: pkcs7, |
| 40 | iv: this.iv, |
| 41 | }; |
| 42 | } |
| 43 | |
| 44 | encrypt(plainText: string) { |
| 45 | return aesEncrypt(plainText, this.key, this.getOptions).toString(); |
| 46 | } |
| 47 | |
| 48 | decrypt(cipherText: string) { |
| 49 | return aesDecrypt(cipherText, this.key, this.getOptions).toString(UTF8); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Define a singleton class for Base64 encryption |
| 54 | class Base64Encryption implements Encryption { |
nothing calls this directly
no outgoing calls
no test coverage detected