Skip to content

Commit

Permalink
Merge pull request #640 from credebl/fix/encryption-decryption
Browse files Browse the repository at this point in the history
fix: decryption error
  • Loading branch information
bhavanakarwade authored Mar 27, 2024
2 parents e36f4f4 + 64dc717 commit 1f76a48
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 1f76a48

Please sign in to comment.