feat: (Web-210) Added encryption for my-booking Urls
This commit is contained in:
18
server/routers/utils/encryptValue.ts
Normal file
18
server/routers/utils/encryptValue.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import crypto from "crypto"
|
||||
|
||||
export default function encryptValue(originalString: string) {
|
||||
const encryptionKey = process.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)])
|
||||
let encryptedValue = cipher
|
||||
.update(paddedStr)
|
||||
.toString("base64")
|
||||
.replace(/\+/g, "-")
|
||||
cipher.final()
|
||||
|
||||
return encryptedValue
|
||||
}
|
||||
Reference in New Issue
Block a user