GitXplorerGitXplorer
R

crypto-json

public
20 stars
8 forks
4 issues

Commits

List of commits on branch master.
Unverified
4244e74382e3edc801dce2a6f2bcef2a1e75165e

bump version

rroryrjb committed 7 years ago
Unverified
7a44cff22a47670ea3a94bcb4dd724045b2dcd0d

update readme

rroryrjb committed 7 years ago
Unverified
641ea1219e27f6eb30c120d13c960ec17ed182b4

fixes and tests

rroryrjb committed 7 years ago
Unverified
3bacd3a5622ee8bef126fe6299dcfc0b4f86613e

modernise

rroryrjb committed 7 years ago
Unverified
eb6715a5dde657461e9d1b0e231b9449233358a3

reverse key inclusion logic

rroryrjb committed 9 years ago
Unverified
892841d3be405893c8411fc3ca8d49bd91877979

typo

rroryrjb committed 9 years ago

README

The README file for this repository.

Looking for a new maintainer

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

password

Random password, length according to the selected algorithm, e.g. 32 bytes length with aes-256-cbc.

config (optional)

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

Example

const util = require('util')
const cryptoJSON = require('crypto-json')
const algorithm = 'aes-256-cbc'
const encoding = 'hex'

const input = {
  hello: {
    bar: ['hello', 'world'],
    baz: {
      secret: 'hide a secret',
      b: {test: 1}
      }
    }
  }

const password = 'random password 32 bytes length.'

// keys act like a white list, so for example if you want to encrypt a nested
// key "secret" you also need to specify its parent keys,
// i.e. "secret", "baz", "hello" in the above input object

const keys = ['hello', 'baz', 'secret']

const output = cryptoJSON.encrypt(
  input, password, {encoding, keys, algorithm}
)
console.log(util.inspect(input ,{showHidden: false, depth: null, colors: true}))
console.log(util.inspect(output ,{showHidden: false, depth: null, colors: true}))

/*

{
  hello: {
    bar: [ 'hello', 'world' ],
    baz: {
      secret: 'b2114cc78fcee8c58a14ba2df511dd05:e5a58d9b9eaab60ca0830d1c7ad4fd41',
      b: { test: 1 }
    }
  }
}
*/