(dataToDecrypt: string)
| 22 | } |
| 23 | |
| 24 | export function decrypt(dataToDecrypt: string): string { |
| 25 | if (!SECRET) { |
| 26 | throw new Error('missing secret'); |
| 27 | } |
| 28 | const [salt, encrypted] = dataToDecrypt.split(':'); |
| 29 | const key = scryptSync(SECRET, salt, 32); |
| 30 | const iv = Buffer.alloc(16, 0); // Initialization vector. |
| 31 | const decipher = createDecipheriv(algorithm, key, iv); |
| 32 | let decrypted = decipher.update(encrypted, 'hex', 'utf8'); |
| 33 | decrypted += decipher.final('utf8'); |
| 34 | return decrypted; |
| 35 | } |