Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

crypto-json

2.0.2 • Public • Published

crypto-json Build Status js-standard-style

Recursively encrypt/decrypt objects selectively by keys.

Installation

$ npm install crypto-json --save

Usage

const cryptoJSON = require('crypto-json')

cryptoJSON.encrypt(object, password, [config]) => encryptedObject

cryptoJSON.decrypt(encryptedObject, password, [config]) => object

config (optional)

  • algorithm - select any supported by the version of Node you are using (default: aes256)
  • encoding - hex, base64, binary (default: hex)
  • keys - specify which keys to ignore when encrypting/decrypting (default: [], i.e. encrypt/decrypt everything)

Example

const cryptoJSON = require('crypto-json')
const algorithm = 'camellia-128-cbc'
const encoding = 'hex'
 
const input = {
  hello: {
    bar: ['hello', 'world'],
    baz: {
      a: {
        b: ['a', {test: 1}]
      }
    }
  }
}
 
const password = 'some random password'
 
// keys act like a white list, so for example if you want to encrypt a nested
// key "test" you also need to specify its parent keys,
// i.e. "b", "a", "baz", "hello" in the above input object
 
const keys = ['hello', 'bar', 'baz', 'a', 'b', 'test']
const algorithm = 'aes256'
const encoding = 'hex'
 
const output = cryptoJSON.encrypt(
  input, password, {encoding, keys, algorithm}
)
 
/*
 
{
    "hello": {
        "bar": ["297b274fcedbe37524bed6994d790eee", "7ab91684f3ab910423d724560205ac56"],
        "baz": {
            "a": {
                "b": ["79ca248dc3c51388ef923acea1397384", {
                    "test": "03f9900f6f7b5bbfb9be3be6d985faa5"
                }]
            }
        }
    }
}
 
*/
 

install

npm i crypto-json

Downloadsweekly downloads

633

version

2.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability