Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / React

Introducing node.data.obfuscator

4.11/5 (2 votes)
10 Aug 2022CPOL1 min read 3.5K  
This library is built so that you could secure JSON or string data in JS files. The library will shuffle the data in memory and make it unreadable for the naked eye.
This is a cli that could shuffle data between many files so that it will not be readable for the user.

Background

Well, I have built an app with React Native and had to have some sensitive data for Firebase and others.

The solution could be to include that data in a native side, but doing this will result in having to build a native module for IOS, Android and Windows. I wanted to skip that and an idea come to me.

When you build a React Native app, it will create a JS bundle. What if the data is shuffled and unreadable so even if someone looks at it, he wouldn't understand any of it anyway? And this is how I came up with this idea to hide the data in JS files.

Platforms

This library will work with any platforms React, React Native and web.

Installation

npm i -D node.data.obfuscator 

OR:

npm i node.data.obfuscator -g

Using the Code

For help, simply execute cla help secure.

Let's say we have secure.json that contains the following JSON:

TypeScript
{
  "user": "test",
  "password": "test.password"
}

To obfuscate a file, simple execute cla secure -f "../secure.json" -p "./data" -c 3

The library will know if the file content is a JSON or simple string and return it as it should be. The command above will create a folder with name 'data' that will contain the following files:

To make it create less files, simply remove or increase --counter.

As for the content or the files, it will be the following. For the preview below, I removed --counter so it creates two files for the preview:

JavaScript
// x0.js
// the array below is impossible to read as it is shuffled.
const x0= ['\u0074','\u003a','\u0022','\u000a','\u007b','\u0070',
           '\u0077','\u0073','\u002c','\u0064','\u0072','\u0065','\u002e',
           '\u006f','\u0061','\u007d','\u0020','\u000d','\u0075'];
export default [x0, ""];
JavaScript
// index.js
import x0 from './x0'
let x36=x0[0X1];
x36+=x0[0X0][0X4];
x36+=x0[0X0][0X11];
x36+=x0[0X0][0X3];
x36+=x0[0X0][0X10];
x36+=x0[0X0][0X10];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X12];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0XB];
x36+=x0[0X0][0XA];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X1];
x36+=x0[0X0][0X10];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X0];
x36+=x0[0X0][0XB];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0X0];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X8];
x36+=x0[0X0][0X11];
x36+=x0[0X0][0X3];
x36+=x0[0X0][0X10];
x36+=x0[0X0][0X10];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X5];
x36+=x0[0X0][0XE];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0X6];
x36+=x0[0X0][0XD];
x36+=x0[0X0][0XA];
x36+=x0[0X0][0X9];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X1];
x36+=x0[0X0][0X10];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X0];
x36+=x0[0X0][0XB];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0X0];
x36+=x0[0X0][0XC];
x36+=x0[0X0][0X5];
x36+=x0[0X0][0XE];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0X7];
x36+=x0[0X0][0X6];
x36+=x0[0X0][0XD];
x36+=x0[0X0][0XA];
x36+=x0[0X0][0X9];
x36+=x0[0X0][0X2];
x36+=x0[0X0][0X11];
x36+=x0[0X0][0X3];
x36+=x0[0X0][0XF];
export default JSON.parse(x36)

Now for use, you can simply do the following;

JavaScript
import secureJSON from './data'
console.log(secureJSON.password);

Points of Interest

This is a simple library that will make your data available in JS and secured.

History

  • 11th August, 2022: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)