Novelty Polygonal Mathematics
Wondering what’s next for npm?Check out our public roadmap! »

This package has been deprecated

Author message:

This module is looking for a new maintainer.

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

360

Version

2.0.2

License

MIT

Unpacked Size

6.89 kB

Total Files

4

Last publish

Collaborators

  • avatar