Skip to content

(De)Cipher values of objects/json files retaining their types

License

Notifications You must be signed in to change notification settings

nbarikipoulos/json-cipher-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Cipher Value

NPM version JavaScript Style Guide Maintainability

json-cipher-value is a simple (de)ciphering module for node.js that recursively performs encryption of the values of object/json files retaining their types.

Note:

  • This module is based on the build-in crypto node module,
  • Default settings perform an aes-256-ctr ciphering,
  • An iv is randomly generated for each value.

Furthermore, it is provided with a CLI in order to simply cipher json files.

Table of Contents

Install

npm install json-cipher-value

Usage

import createCipherObject from 'json-cipher-value'

const secret = 'My secret password'
const cipherObject = createCipherObject(secret)

const object = {
  a: 'a value',
  b: {
    a: [1, 3.1, '2.2', true, true, false]
  }
}

const cipheredObject = cipherObject.perform('cipher', object)
//{
//  a: '35747569f964d575521a0205b8d21af8eab60b69c30d2fe5',
//  b: {
//    a: [
//        '7f7e507e96b07807661d6e531f6b4e489205',
//        'a6af3a7c1d52a8163a196c4487256c584a0943e9',
//        'eed2d3bf77a9d0fa51449268dc6c1553fd6257ba',
//        'bf0fca31bf46d5611899cf9e53f49f28d317bebcf8',
//        '10c58a69fd3bcf904cf5860e423d081cf6d2646227',
//        'dda317d5e23e5f14423c44ee46b9bf49c762ee23ed49'
//    ]
//  }
//}

const decipheredObject = cipherObject.perform('decipher', cipheredObject)
// { a: 'a value', b: { a: [ 1, 3.1, '2.2', true, true, false ] } }

CLI

This module is provided with a CLI in order to simply cipher json files:

  • It performs (de)ciphering with the default algorithm used by this package i.e. the aes-256-ctr one's,
  • It optionnally allows modifying ciphered file extension (.cjson as default) or target folder.
cipher-json cipher src/data/**/*.json 'My secret password'
cipher-json decipher src/data/**/*.cjson 'My secret password'

Use -h for further details/available options.

API

See API.md for more details.

Tests

Typing:

npm run test

will launch a set of unit and functional tests as well as checking the compliancy of code with standardjs.

Credits

License

This module is MIT licensed. See LICENSE.

About

(De)Cipher values of objects/json files retaining their types

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published