()
| 6 | const ENCODING = 'base64'; |
| 7 | |
| 8 | function getKey(): Buffer { |
| 9 | const raw = process.env.ENCRYPTION_KEY; |
| 10 | if (!raw) { |
| 11 | throw new Error('ENCRYPTION_KEY environment variable is not set'); |
| 12 | } |
| 13 | const buf = Buffer.from(raw, 'hex'); |
| 14 | if (buf.length !== 32) { |
| 15 | throw new Error( |
| 16 | 'ENCRYPTION_KEY must be a 64-character hex string (32 bytes)' |
| 17 | ); |
| 18 | } |
| 19 | return buf; |
| 20 | } |
| 21 | |
| 22 | export function encrypt(plaintext: string): string { |
| 23 | const key = getKey(); |
no test coverage detected