From 9b67a253f1b371dc7cf46e714f9fba0d4a3d2da3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 12 Aug 2022 19:39:03 +0000 Subject: [PATCH] fix: decryption errors --- apps/api/src/lib/common.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index c9ce0e6df..a2b78bf50 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -96,17 +96,23 @@ export const base64Decode = (text: string): string => { }; export const decrypt = (hashString: string) => { if (hashString) { - const hash = JSON.parse(hashString); - const decipher = crypto.createDecipheriv( - algorithm, - process.env['COOLIFY_SECRET_KEY'], - Buffer.from(hash.iv, 'hex') - ); - const decrpyted = Buffer.concat([ - decipher.update(Buffer.from(hash.content, 'hex')), - decipher.final() - ]); - return decrpyted.toString(); + try { + const hash = JSON.parse(hashString); + const decipher = crypto.createDecipheriv( + algorithm, + process.env['COOLIFY_SECRET_KEY'], + Buffer.from(hash.iv, 'hex') + ); + const decrpyted = Buffer.concat([ + decipher.update(Buffer.from(hash.content, 'hex')), + decipher.final() + ]); + return decrpyted.toString(); + } catch (error) { + console.log({ decryptionError: error.message }) + return hashString + } + } }; export const encrypt = (text: string) => {