react-npm-encrypt-decrypt
Advanced tools
Comparing version
{ | ||
"name": "react-npm-encrypt-decrypt", | ||
"version": "1.0.37", | ||
"version": "1.0.38", | ||
"description": "The package used to encrypt and decrypt the data dynamically with keys.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
const CryptoJS = require('crypto-js'); | ||
const axios = require('axios'); | ||
const SKEY = process.env.REACT_APP_TECHUS_AES_ENC_SECRET_KEY; | ||
const IV = process.env.REACT_APP_TECHUS_AES_ENC_IV; | ||
console.log(SKEY) | ||
console.log(SKEY); | ||
function keyExpiry(value, AES_ENC_SECRET_KEY , AES_ENC_IV){ | ||
function keyDecryptionExpiry(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) { | ||
const key = CryptoJS.enc.Utf8.parse(AES_ENC_SECRET_KEY); | ||
const iv = CryptoJS.enc.Utf8.parse(AES_ENC_IV); | ||
let decrypted; | ||
let valid = false | ||
if(valid == false){ | ||
let response = {message :'Keys are expired'} | ||
return JSON.stringify(response) | ||
}else{ | ||
try { | ||
@@ -24,3 +29,3 @@ decrypted = JSON.parse(value); | ||
}).toString(CryptoJS.enc.Utf8); | ||
console.log('decryptedString',decryptedString) | ||
return decryptedString; | ||
@@ -36,4 +41,2 @@ } else { | ||
try { | ||
console.log('decryptedJSON',decryptedJSON) | ||
return JSON.parse(decryptedJSON); | ||
@@ -46,2 +49,4 @@ } catch (error) { | ||
} | ||
} | ||
async function techusDecryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) { | ||
@@ -53,2 +58,3 @@ const apiUrl = 'https://beta.tech.us:4177/app/user/v1/verify_npm_crypto_keys'; | ||
console.log('AES_ENC_IV keys',AES_ENC_IV) | ||
try { | ||
@@ -60,3 +66,3 @@ const response = await fetch(apiUrl, { | ||
}, | ||
data:{ | ||
data: { | ||
aes_secret_key: aesSecretKey, | ||
@@ -67,12 +73,8 @@ aes_iv_key: aesIvKey | ||
console.log('response keys',response) | ||
if (response.ok) { | ||
const responseData = await response.json(); | ||
// Handle the response here | ||
console.log('API Response:', responseData); | ||
if (responseData.data.is_valid == 0) { | ||
keyExpiry(value, AES_ENC_SECRET_KEY, AES_ENC_IV); | ||
} else { | ||
keyDecryptionExpiry(value, AES_ENC_SECRET_KEY, AES_ENC_IV); | ||
} else { | ||
let response = { message: 'Keys are expired' }; | ||
@@ -89,2 +91,3 @@ return JSON.stringify(response); | ||
} | ||
module.exports = techusDecryptHandler; |
@@ -19,3 +19,2 @@ const CryptoJS = require('crypto-js'); | ||
}); | ||
console.log('encrypted', encrypted) | ||
return encrypted.toString(); | ||
@@ -27,4 +26,2 @@ } | ||
const aesIvKey = AES_ENC_IV; | ||
console.log('AES_ENC_SECRET_KEY keys',AES_ENC_SECRET_KEY) | ||
console.log('AES_ENC_IV keys',AES_ENC_IV) | ||
@@ -42,3 +39,3 @@ try { | ||
}); | ||
console.log('response keys',response) | ||
console.log('response keys',response) | ||
@@ -51,3 +48,3 @@ if (response.ok) { | ||
if (responseData.data.is_valid == 0) { | ||
if (responseData.valid) { | ||
keyEncryptionExpiry(value, AES_ENC_SECRET_KEY, AES_ENC_IV); | ||
@@ -54,0 +51,0 @@ } else { |
7199
-1.93%136
-0.73%