(plaintext: string)
| 22 | } |
| 23 | |
| 24 | encrypt(plaintext: string): string { |
| 25 | const iv = randomBytes(12); |
| 26 | const cipher = createCipheriv("aes-256-gcm", this.key, iv); |
| 27 | const ct = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]); |
| 28 | return JSON.stringify({ |
| 29 | iv: iv.toString("base64"), |
| 30 | tag: cipher.getAuthTag().toString("base64"), |
| 31 | ct: ct.toString("base64"), |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | decrypt(blob: string): string { |
| 36 | const { iv, tag, ct } = JSON.parse(blob) as { iv: string; tag: string; ct: string }; |
no test coverage detected