feat: WEB-210 Update env path & try catch handling
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { env } from "process"
|
|
||||||
|
|
||||||
import { Lang } from "@/constants/languages"
|
import { Lang } from "@/constants/languages"
|
||||||
|
import { env } from "@/env/server"
|
||||||
import * as api from "@/lib/api"
|
import * as api from "@/lib/api"
|
||||||
import {
|
import {
|
||||||
protectedProcedure,
|
protectedProcedure,
|
||||||
|
|||||||
@@ -3,22 +3,25 @@ import crypto from "crypto"
|
|||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
|
|
||||||
export default function encryptValue(originalString: string) {
|
export default function encryptValue(originalString: string) {
|
||||||
let result: String = ""
|
|
||||||
try {
|
try {
|
||||||
const encryptionKey = env.BOOKING_ENCRYPTION_KEY
|
const encryptionKey = env.BOOKING_ENCRYPTION_KEY
|
||||||
const bufferKey = Buffer.from(encryptionKey, "utf8")
|
const bufferKey = Buffer.from(encryptionKey, "utf8")
|
||||||
let cipher = crypto.createCipheriv("DES-ECB", bufferKey, null)
|
const cipher = crypto.createCipheriv("DES-ECB", bufferKey, null)
|
||||||
cipher.setAutoPadding(false)
|
cipher.setAutoPadding(false)
|
||||||
let bufferString = Buffer.from(originalString, "utf8")
|
const bufferString = Buffer.from(originalString, "utf8")
|
||||||
let paddingSize =
|
const paddingSize =
|
||||||
bufferKey.length - (bufferString.length % bufferKey.length)
|
bufferKey.length - (bufferString.length % bufferKey.length)
|
||||||
let paddedStr = Buffer.concat([bufferString, Buffer.alloc(paddingSize, 0)])
|
const paddedStr = Buffer.concat([
|
||||||
|
bufferString,
|
||||||
|
Buffer.alloc(paddingSize, 0),
|
||||||
|
])
|
||||||
const buffers: Buffer[] = []
|
const buffers: Buffer[] = []
|
||||||
buffers.push(cipher.update(paddedStr))
|
buffers.push(cipher.update(paddedStr))
|
||||||
buffers.push(cipher.final())
|
buffers.push(cipher.final())
|
||||||
result = Buffer.concat(buffers).toString("base64").replace(/\+/g, "-")
|
const result = Buffer.concat(buffers).toString("base64").replace(/\+/g, "-")
|
||||||
|
return result
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user