(text)
| 6 | const IV_LENGTH = 16; // AES block size in bytes |
| 7 | |
| 8 | function encrypt(text) { |
| 9 | // console.log("text", text); |
| 10 | if (!text) return text; |
| 11 | const iv = crypto.randomBytes(IV_LENGTH); |
| 12 | const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(SECRET_KEY, "hex"), iv); |
| 13 | let encrypted = cipher.update(text); |
| 14 | |
| 15 | encrypted = Buffer.concat([encrypted, cipher.final()]); |
| 16 | |
| 17 | return `${iv.toString("hex")}:${encrypted.toString("hex")}`; |
| 18 | } |
| 19 | |
| 20 | function decrypt(text) { |
| 21 | if (!text) return text; |
no test coverage detected