Skip to content

blobr-io/crypto-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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"
                }]
            }
        }
    }
}

*/

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%