🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-npm-encrypt-decrypt

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-npm-encrypt-decrypt - npm Package Compare versions

Comparing version

to
1.0.40

techus-libraries/techus-api-service.js

2

package.json
{
"name": "react-npm-encrypt-decrypt",
"version": "1.0.39",
"version": "1.0.40",
"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');
import keysService from './techus-api-service'

@@ -7,74 +8,40 @@ const SKEY = process.env.REACT_APP_TECHUS_AES_ENC_SECRET_KEY;

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;
try {
decrypted = JSON.parse(value);
} catch (error) {
decrypted = value;
}
if (typeof decrypted === 'string') {
const decryptedString = CryptoJS.AES.decrypt(value, key, {
keySize: 256 / 32,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}).toString(CryptoJS.enc.Utf8);
return decryptedString;
} else {
const decryptedJSON = CryptoJS.AES.decrypt(value, key, {
keySize: 256 / 32,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}).toString(CryptoJS.enc.Utf8);
function techusDecryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) {
const res = keysService(AES_ENC_SECRET_KEY, AES_ENC_IV);
console.log(res)
if(res.data.is_valid == 0){
const key = CryptoJS.enc.Utf8.parse(AES_ENC_SECRET_KEY);
const iv = CryptoJS.enc.Utf8.parse(AES_ENC_IV);
let decrypted;
try {
return JSON.parse(decryptedJSON);
decrypted = JSON.parse(value);
} catch (error) {
// Handle JSON parsing errors if needed
return null;
decrypted = value;
}
}
}
if (typeof decrypted === 'string') {
const decryptedString = CryptoJS.AES.decrypt(value, key, {
keySize: 256 / 32,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}).toString(CryptoJS.enc.Utf8);
async function techusDecryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) {
const apiUrl = 'https://beta.tech.us:4177/app/user/v1/verify_npm_crypto_keys';
const aesSecretKey = AES_ENC_SECRET_KEY;
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)
return decryptedString;
} else {
const decryptedJSON = CryptoJS.AES.decrypt(value, key, {
keySize: 256 / 32,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}).toString(CryptoJS.enc.Utf8);
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
data: {
aes_secret_key: aesSecretKey,
aes_iv_key: aesIvKey
try {
return JSON.parse(decryptedJSON);
} catch (error) {
// Handle JSON parsing errors if needed
return null;
}
});
console.log('response keys',response)
if (response.ok) {
const responseData = await response.json();
console.log('API Response:', responseData);
console.log('API Response data:', responseData.data);
console.log('API Response data:', responseData.data.is_valid);
if (responseData.data.is_valid == 0) {
let datas = await keyDecryptionExpiry(value, AES_ENC_SECRET_KEY, AES_ENC_IV);
console.log(datas)
} else {
let response = { message: 'Keys are expired' };
return JSON.stringify(response);
}
} else {
console.error('Error making API call:', response.statusText);
}
} catch (error) {
// Handle errors here
console.error('Error making API call:', error.message);
}else{
}

@@ -81,0 +48,0 @@ }

const CryptoJS = require('crypto-js');
const axios = require('axios');
import keysService from './techus-api-service'

@@ -8,52 +8,23 @@ const SKEY = process.env.REACT_APP_TECHUS_AES_ENC_SECRET_KEY;

console.log('SKEY', SKEY)
function keyEncryptionExpiry(value, AES_ENC_SECRET_KEY , AES_ENC_IV){
const key = CryptoJS.enc.Utf8.parse(AES_ENC_SECRET_KEY);
const iv = CryptoJS.enc.Utf8.parse(AES_ENC_IV);
const isJSON = typeof value === 'object';
const valueToEncrypt = isJSON ? JSON.stringify(value) : value;
const encrypted = CryptoJS.AES.encrypt(valueToEncrypt, key, {
keySize: 256 / 32,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
return encrypted.toString();
}
async function techusEncryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV) {
const apiUrl = 'https://beta.tech.us:4177/app/user/v1/verify_npm_crypto_keys';
const aesSecretKey = AES_ENC_SECRET_KEY;
const aesIvKey = AES_ENC_IV;
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
data: {
aes_secret_key: aesSecretKey,
aes_iv_key: aesIvKey
}
function techusEncryptHandler(value, AES_ENC_SECRET_KEY = SKEY, AES_ENC_IV = IV){
const res = keysService(AES_ENC_SECRET_KEY, AES_ENC_IV);
console.log(res)
if(res.data.is_valid == 0){
const key = CryptoJS.enc.Utf8.parse(AES_ENC_SECRET_KEY);
const iv = CryptoJS.enc.Utf8.parse(AES_ENC_IV);
const isJSON = typeof value === 'object';
const valueToEncrypt = isJSON ? JSON.stringify(value) : value;
const encrypted = CryptoJS.AES.encrypt(valueToEncrypt, key, {
keySize: 256 / 32,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
console.log('response keys',response)
if (response.ok) {
const responseData = await response.json();
// Handle the response here
console.log('API Response:', responseData);
if (responseData.valid) {
keyEncryptionExpiry(value, AES_ENC_SECRET_KEY, AES_ENC_IV);
} else {
let response = { message: 'Keys are expired' };
return JSON.stringify(response);
}
} else {
console.error('Error making API call:', response.statusText);
}
} catch (error) {
// Handle errors here
console.error('Error making API call:', error.message);
return encrypted.toString();
}else{
let response = { message: 'Keys are expired' };
return JSON.stringify(response);
}
}

@@ -60,0 +31,0 @@