Files
web/server/routers/utils/encryptValue.ts
2024-07-10 11:37:26 +02:00

25 lines
805 B
TypeScript

import crypto from "crypto"
import { env } from "@/env/server"
export default function encryptValue(originalString: string) {
let result = ""
console.log(process.env.NODE_OPTIONS)
try {
const encryptionKey = env.BOOKING_ENCRYPTION_KEY
const bufferKey = Buffer.from(encryptionKey, "utf8")
let cipher = crypto.createCipheriv("DES-ECB", bufferKey, null)
cipher.setAutoPadding(false)
let bufferString = Buffer.from(originalString, "utf8")
let paddingSize =
bufferKey.length - (bufferString.length % bufferKey.length)
let paddedStr = Buffer.concat([bufferString, Buffer.alloc(paddingSize, 0)])
result = cipher.update(paddedStr).toString("base64").replace(/\+/g, "-")
cipher.final()
} catch (e) {
console.log(e)
result = "error"
}
return result
}