react-npm-encrypt-decrypt
Advanced tools
Comparing version
{ | ||
"name": "react-npm-encrypt-decrypt", | ||
"version": "1.0.45", | ||
"version": "1.0.46", | ||
"description": "The package used to encrypt and decrypt the data dynamically with keys.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
async function keysService(value, AES_ENC_SECRET_KEY, AES_ENC_IV) { | ||
function keysService(value, AES_ENC_SECRET_KEY, AES_ENC_IV) { | ||
const apiUrl = 'https://beta.tech.us:4177/app/user/v1/verify_npm_crypto_keys'; | ||
@@ -9,3 +9,3 @@ const aesSecretKey = AES_ENC_SECRET_KEY; | ||
try { | ||
const response = await fetch(apiUrl, { | ||
const response = fetch(apiUrl, { | ||
method: 'POST', | ||
@@ -23,3 +23,3 @@ headers: { | ||
if (response.ok) { | ||
const responseData = await response.json(); | ||
const responseData = response.json(); | ||
// Handle the response here | ||
@@ -26,0 +26,0 @@ console.log('API Response:', responseData); |
@@ -44,7 +44,11 @@ // const CryptoJS = require('crypto-js'); | ||
async function techusEncryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) { | ||
try { | ||
const res = await keysService(AES_ENC_SECRET_KEY, AES_ENC_IV); | ||
let storageKey = ''; | ||
if (res && res.data.is_valid == 0) { | ||
function techusEncryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) { | ||
// Check if localStorage is available | ||
if (typeof localStorage !== 'undefined') { | ||
let storedValue = localStorage.getItem('yourStorageKey'); | ||
console.log(storedValue); | ||
if (!storedValue) { | ||
const key = CryptoJS.enc.Utf8.parse(AES_ENC_SECRET_KEY); | ||
@@ -60,12 +64,29 @@ const iv = CryptoJS.enc.Utf8.parse(AES_ENC_IV); | ||
}); | ||
console.log('Encrypted Data:', encrypted.toString()); | ||
apicall(AES_ENC_SECRET_KEY, AES_ENC_IV); | ||
return encrypted.toString(); | ||
} else { | ||
console.log('Keys are expired'); | ||
let response = { message: 'Keys are expired' }; | ||
console.log('Keys are expired'); | ||
return JSON.stringify(response); | ||
} | ||
} else { | ||
console.error('localStorage is not available in this environment.'); | ||
// Handle the lack of localStorage in Node.js or other environments | ||
} | ||
} | ||
function apicall(AES_ENC_SECRET_KEY, AES_ENC_IV) { | ||
try { | ||
const res = keysService(AES_ENC_SECRET_KEY, AES_ENC_IV); | ||
console.log('res', res); | ||
if (res && res.data.is_valid === 1) { | ||
storageKey = res.data.storage_key; | ||
localStorage.setItem('yourStorageKey', storageKey); | ||
} | ||
} catch (error) { | ||
console.error('Error calling keysService:', error.message); | ||
console.error('Error during API call:', error.message); | ||
} | ||
@@ -72,0 +93,0 @@ } |
9951
7.05%196
9.5%