Skip to content

Commit

Permalink
fix: encrypt and decrypt data
Browse files Browse the repository at this point in the history
Signed-off-by: sanjay.khatal <[email protected]>
  • Loading branch information
sanjay-k1910 committed Mar 27, 2024
1 parent e4ca9bd commit f682ab2
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,12 @@ export const encryptData = (value: any): string => {
}
}

const parsedData = (value: any) => {
try {
return JSON.parse(value.toString(CryptoJS.enc.Utf8));
} catch (error) {
return value.toString(CryptoJS.enc.Utf8);
}
}

export const decryptData = (value: any): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`

try {
let bytes = CryptoJS.AES.decrypt(value, CRYPTO_PRIVATE_KEY);
return parsedData(bytes);
return bytes.toString(CryptoJS.enc.Utf8);
} catch (error) {
// Handle decryption error or invalid input
console.error('Decryption error:', error);
Expand Down

0 comments on commit f682ab2

Please sign in to comment.