GitXplorerGitXplorer
R

crypto-json

public
20 stars
8 forks
4 issues

Commits

List of commits on branch master.
Verified
3bfd2abbc583b16766a185c9b788982280db36e0

Update index.js

pperugini committed 4 years ago
Verified
412eca921cf582f897c3282c1af88c995b96d522

Fix deprecation warning (#16)

pperugini committed 4 years ago
Unverified
7fa6a6d10085be7103760ca9880ea258e500d280

update README

rroryrjb committed 5 years ago
Unverified
d45ebfd4cc456beb00a82420de33d221a701f5cc

chore: update dependencies

rroryrjb committed 6 years ago
Unverified
08520857830794342f3a1aacc0a6654b65ca169c

add react native support

rroryrjb committed 6 years ago
Unverified
596b437d9dfcf5e6e40199a9b9c31f6c4d0504e9

fix README, bump version

rroryrjb committed 6 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 }
    }
  }
}
*/