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

json-secure-crypt

v1.1.1

Published

A simple Node.js tool to encrypt and decrypt JSON files

Downloads

230

Readme

json-secure-crypt

json-secure-crypt is a Node.js package that provides tools to securely encrypt and decrypt JSON files using AES encryption. It supports both local files and remote files accessed via URLs, with optional proxy configuration.

Installation

To install the package, use one of the following commands:

Using npm:

npm install json-secure-crypt

Using Yarn:

yarn add json-secure-crypt

Usage

Command-Line Interface (CLI) Usage

This package provides two primary command-line tools: encrypt and decrypt, which can be executed via npm or Yarn scripts.

1. Encrypt a JSON File

Encrypt a local JSON file and save the encrypted content to a new file:

Using npm:

npm run encrypt -- <input-file-path> <output-file-path> <secret-key>

Using Yarn:

yarn encrypt <input-file-path> <output-file-path> <secret-key>
  • <input-file-path>: Path to the JSON file you want to encrypt.
  • <output-file-path>: Path where the encrypted file will be saved.
  • <secret-key>: The secret key used for encryption. Keep this key safe, as it will be required to decrypt the file.

Example:

npm run encrypt -- ./data.json ./encrypted-data.json mySecretKey123

or using Yarn:

yarn encrypt ./data.json ./encrypted-data.json mySecretKey123

2. Decrypt a Local JSON File

Decrypt a local encrypted JSON file and save the decrypted content to a new file:

Using npm:

npm run decrypt -- <input-file-path> <output-file-path> <secret-key>

Using Yarn:

yarn decrypt <input-file-path> <output-file-path> <secret-key>
  • <input-file-path>: Path to the encrypted JSON file.
  • <output-file-path>: Path where the decrypted file will be saved.
  • <secret-key>: The secret key used to decrypt the file.

Example:

npm run decrypt -- ./encrypted-data.json ./decrypted-data.json mySecretKey123

or using Yarn:

yarn decrypt ./encrypted-data.json ./decrypted-data.json mySecretKey123

3. Decrypt a Remote JSON File

You can also decrypt a JSON file hosted remotely via a URL:

Using npm:

npm run decrypt -- <url> <output-file-path> <secret-key> [proxy-host:proxy-port]

Using Yarn:

yarn decrypt <url> <output-file-path> <secret-key> [proxy-host:proxy-port]
  • <url>: The URL of the remote JSON file.
  • <output-file-path>: Path where the decrypted file will be saved.
  • <secret-key>: The secret key used to decrypt the file.
  • [proxy-host:proxy-port] (optional): If your network requires a proxy to access the internet, specify the proxy host and port here.

Example:

npm run decrypt -- https://example.com/encrypted.json ./decrypted.json mySecretKey123

or using Yarn:

yarn decrypt https://example.com/encrypted.json ./decrypted.json mySecretKey123

Example with Proxy:

npm run decrypt -- https://example.com/encrypted.json ./decrypted.json mySecretKey123 127.0.0.1:7890

or using Yarn:

yarn decrypt https://example.com/encrypted.json ./decrypted.json mySecretKey123 127.0.0.1:7890

Programmatic Usage

You can also use the encryption and decryption functions in your Node.js code.

const { encryptJson, decryptJson } = require('json-secure-crypt');

// Encrypt JSON data
const jsonData = { key: 'value' };
const secretKey = 'mySecretKey123';
const encryptedData = encryptJson(jsonData, secretKey);

// Decrypt JSON data
const decryptedData = decryptJson(encryptedData, secretKey);
console.log(decryptedData); // Output: { key: 'value' }

Decrypting from a URL in Your Code

If you need to decrypt JSON data from a remote URL within your application, you can do so as follows:

const { decryptJsonFromUrl } = require('json-secure-crypt');

const url = 'https://example.com/encrypted.json';
const secretKey = 'mySecretKey123';
const proxyConfig = {
    host: '127.0.0.1',
    port: 8080
};

decryptJsonFromUrl(url, secretKey, proxyConfig)
    .then(decryptedData => {
        console.log(decryptedData);
    })
    .catch(err => {
        console.error('Error during decryption:', err);
    });

License

This package is licensed under the MIT License. See the LICENSE file for more details.