New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

json-crypto

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-crypto

Encrypt and decrypt JSON objects easily and safely

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
1.2K
2.31%
Maintainers
1
Weekly downloads
 
Created
Source

json-crypto

Easy to use abstraction on top of Node's native crypto module to safely encrypt and decrypt JSON objects.

Installation

npm install json-crypto

Usage

const { createKey, createCodec } = require('json-crypto');

// Create a random encryption key
const key = createKey();

// Create our codec with { encrypt, decrypt }
const codec = createCodec(key);

// Encrypt a JSON object and return the ciphertext
const ciphertext = codec.encrypt({ message: 'my secret message' })

// Decrypt the ciphertext back into a JSON object
const secret = codec.decrypt(ciphertext)
// secret === { message: 'my secret message' }

NB: You'll probably want to persist the generated key and store it somewhere safe.

Benefits

  • Safe by nature (only uses native crypto functions)
  • Safer by forcing you to use unique nonces (see why it matters)
  • Easy to use interface for JSON objects
  • Ciphertexts are valid URL query argument strings (using encodeURIComponent)

Keywords

crypto

FAQs

Package last updated on 13 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts