(text: string, secret: Buffer)
| 877 | }; |
| 878 | |
| 879 | export const encrypt = (text: string, secret: Buffer) => { |
| 880 | const iv = crypto.randomBytes(16); |
| 881 | const cipher = crypto.createCipheriv(encryptionAlgo, secret, iv); |
| 882 | const encrypted = cipher.update(text, 'utf8', 'hex'); |
| 883 | |
| 884 | return [ |
| 885 | encrypted + cipher.final('hex'), |
| 886 | Buffer.from(iv).toString('hex'), |
| 887 | ].join(encryptionSep); |
| 888 | }; |
| 889 | |
| 890 | export const decrypt = (encryptedText: string, secret: Buffer) => { |
| 891 | const [encrypted, iv] = encryptedText.toString().split(encryptionSep); |