(plaintext: string)
| 20 | } |
| 21 | |
| 22 | export function encrypt(plaintext: string): string { |
| 23 | const key = getKey(); |
| 24 | const iv = randomBytes(IV_LENGTH); |
| 25 | const cipher = createCipheriv(ALGORITHM, key, iv); |
| 26 | const encrypted = Buffer.concat([ |
| 27 | cipher.update(plaintext, 'utf8'), |
| 28 | cipher.final(), |
| 29 | ]); |
| 30 | const tag = cipher.getAuthTag(); |
| 31 | // Format: base64(iv + tag + ciphertext) |
| 32 | return Buffer.concat([iv, tag, encrypted]).toString(ENCODING); |
| 33 | } |
| 34 | |
| 35 | export function decrypt(ciphertext: string): string { |
| 36 | const key = getKey(); |
no test coverage detected