| 11 | } |
| 12 | |
| 13 | export class Encryption implements EncryptionInterface { |
| 14 | private password: string |
| 15 | private keyId: string |
| 16 | |
| 17 | constructor(hash: string, keyId: string) { |
| 18 | this.password = hash |
| 19 | this.keyId = keyId |
| 20 | } |
| 21 | |
| 22 | getEncryptedString(data: string): string { |
| 23 | if (!this.password) { |
| 24 | return data |
| 25 | } |
| 26 | return CryptoJS.AES.encrypt(data, this.password).toString() |
| 27 | } |
| 28 | |
| 29 | decryptSecretString(secret: string): string | null { |
| 30 | try { |
| 31 | if (!this.password) { |
| 32 | return secret |
| 33 | } |
| 34 | |
| 35 | const decryptedSecret = CryptoJS.AES.decrypt( |
| 36 | secret, |
| 37 | this.password |
| 38 | ).toString(CryptoJS.enc.Utf8) |
| 39 | |
| 40 | if (!decryptedSecret) { |
| 41 | return null |
| 42 | } |
| 43 | |
| 44 | if (decryptedSecret.length < 8) { |
| 45 | return null |
| 46 | } |
| 47 | |
| 48 | // Validate secret format |
| 49 | if ( |
| 50 | !/^[A-Z2-7]+=*$/i.test(decryptedSecret) && // Base32 format |
| 51 | !/^[0-9a-f]+$/i.test(decryptedSecret) && // Hex format |
| 52 | !/^blz-/.test(decryptedSecret) && // Blizzard format |
| 53 | !/^bliz-/.test(decryptedSecret) && // Alternative Blizzard format |
| 54 | !/^stm-/.test(decryptedSecret) // Steam format |
| 55 | ) { |
| 56 | return null |
| 57 | } |
| 58 | |
| 59 | return decryptedSecret |
| 60 | } catch (error) { |
| 61 | return null |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | decryptEncSecret(entry: any): any | null { |
| 66 | try { |
| 67 | if (!entry.encData || !this.password) { |
| 68 | return null |
| 69 | } |
| 70 |
nothing calls this directly
no outgoing calls
no test coverage detected