(encryptedText: string, secret: Buffer)
| 888 | }; |
| 889 | |
| 890 | export const decrypt = (encryptedText: string, secret: Buffer) => { |
| 891 | const [encrypted, iv] = encryptedText.toString().split(encryptionSep); |
| 892 | if (!iv) throw new ServerError('Bad or invalid encrypted format'); |
| 893 | const decipher = crypto.createDecipheriv( |
| 894 | encryptionAlgo, |
| 895 | secret, |
| 896 | Buffer.from(iv, 'hex'), |
| 897 | ); |
| 898 | return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8'); |
| 899 | }; |
| 900 | |
| 901 | interface RequestInitTimeout extends RequestInit { |
| 902 | timeout?: number; |