Skip to content

Commit

Permalink
refactor decrypt function
Browse files Browse the repository at this point in the history
  • Loading branch information
bhavanakarwade committed Dec 4, 2024
1 parent 2bb928d commit 7e56b0c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,15 @@ export const encryptData = (value: any): string => {
export const decryptData = (value: any): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`

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

export const setToLocalStorage = async (key: string, value: any) =>{
Expand All @@ -273,6 +274,7 @@ export const setToLocalStorage = async (key: string, value: any) =>{

export const getFromLocalStorage = async (key: string) =>{
const value = await localStorage.getItem(key)
console.log(value , 'local storage value ............................')
const convertedValue = value ? await decryptData(value) : ''
return convertedValue
}
Expand Down

0 comments on commit 7e56b0c

Please sign in to comment.