npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@harshiyer/json-crypto

v1.0.8

Published

A npm package to convert JSON payload into Base 64 encoded 256 Bit AES Strings and reversal.

Downloads

53

Readme

json-crypto

This package can be used to convert a JSON payload and a password into a compressed 256 Bit AES string which can be later reversed to obtain the original payload.

Sample:

const {convertToAES, convertFromAES} = require('@harshiyer/json-crypto');
const object = {
  name:"John Doe",
  age:35
}
const encodedJSON = convertToAES(object , 'testpassword')
console.log(encodedJSON) // Returns derivedKey, salt, aesString, sha256key

//Now to reverse it, 
const aesString = encodedJSON.aesString;

const retrievedText = convertFromAES(aesString, password, salt); //Note: password stands for the original password converted to derivedKey
console.log(retrievedText) // Returns the original JSON which was encrypted

The original JSON is first split into 2 separate arrays, one containing all keys and one containing all values.

Now these 2 arrays are individually minified and then combined into 1 super string which is then converted to base64 to get encrypted into 256Bit AES.

Then the password is converted to 32 bytes using the PKBDF2 algorithm using a salt that is randomly generated.

This pkbdf2 derived key is then used to encrypt the Base64 encoded payload to return a 256 Bit AES string with its key as the pkbdf2 derived key.

Reversal

The AES string is then reversed using the derived key which returns us a base64 string.

This base64 string contains 2 individual arrays, one containing all keys and one containing all values.

Now these 2 arrays are then combined using combineArrays() which returns a javascript object which is then parsed to JSON format.

Compression

Converting the parent JSON payload into 2 separate individual arrays is essential for saving memory since in test cases with test payloads, while a JSON formatted object was taking upto 336 bytes in memory, 2 individual arrays added to a total of 248 bytes, thus marking a significant 26% in memory savings.

Function returns:

  • PKBDF2 Derived 32 byte key,
    • Accessible by convertToAES.derivedKey
  • The randomly generated salt,
    • Accessible by convertToAES.salt
  • The 256 Bit AES String,
    • Accessible by convertToAES.aesString
  • The original password hashed using SHA256
    • Accessible by convertToAES.sha256key

The encrypted AES string can be later decoded using the function convertFromAES(aesString, derivedKey)