Skip to content

Latest commit

 

History

History
175 lines (124 loc) · 7.12 KB

api.md

File metadata and controls

175 lines (124 loc) · 7.12 KB

json-cipher-value API Reference

This module is a simple (de)ciphering module based on the build-in crypto node module. It performs recursive (de)ciphering of the values of an object remaining their types.

It is mainly based on the crypto.createcipheriv function and corrolary to the crypto.createdecipheriv one using a randomly generated initalization vector.

The entry point is the cipher object factory that creates a (de)ciphering object.

Note default settings use aes-256-crt ciphering.

See: https://nodejs.org/api/crypto.html for further information.
Version: 3.0.1

json-cipher-value.factory(secret, [options]) : CipherObject

Factory that creates a (de)ciphering object.

Kind: static method of json-cipher-value

Param Type Description
secret string The secret key or pawssord that will be used to create the key for (de)ciphering step.
[options] Options (De)Ciphering Settings. Use of default settings performs an aes-256-crt ciphering.

Example

import createCipherObject form 'json-cipher-value'

const secret = 'My secret password'
const object = {...} // Object to cipher

const cipherObject = createCipherObject(secret)

const cipheredObject = cipherObject.perform('cipher', object)

const decipheredObject = cipherObject.perform('decipher', cipheredObject)

json-cipher-value~CipherObject

Object in charge to cipher both supported primitive type or values of object.

Kind: inner class of json-cipher-value

new CipherObject(secret, [options])

Create a new Cipher object.

Param Type Description
secret string The secret key or password that will be used to create key for (de)ciphering step.
[options] Options (De)Ciphering Settings. Note Use of default settings performs an aes-256-crt ciphering.

Example

import { CipherObject } from 'json-cipher-value'

const secret = 'My secret password'

const obj = {...} // Object to cipher

const cipherObject = new CipherObject(secret)
const cipheredObject = cipherObject.perform('cipher', object)
const decipheredObject = cipherObject.perform('decipher', cipheredObject)

cipherObject.perform(action, value) : *

(De)Cipher content.

Note about Ciphering case:

  • Supported input are number, boolean, string or object (including array). All other kind of values will be treated as string.
  • An iv vector is randomly generated at each ciphering of values i.e. for each object properties with a primitive type as value.
  • The return value concatenates the iv vector and the ciphertext.

Kind: instance method of CipherObject

Param Type Description
action 'cipher' | 'decipher' action to perform.
value * Input to (de)cipher.

cipherObject.cipher(value) : string

Cipher a primitive type.

At each call, an iv vector is randomly generated.

Supported type are number, boolean, or string. All other kind of values will be treated as a string.

Kind: instance method of CipherObject

Param Type Description
value string | number | boolean | * value to cipher.

Example

import { CipherObject } from 'json-cipher-value'

const secret = 'My secret password'

const value = 'my value' // Value to cipher

const cipherObject = new CipherObject(secret)
const cipheredValue = cipherObject.cipher(value)

cipherObject.decipher(cipheredText) : string | number | boolean

Decipher primitive type.

Kind: instance method of CipherObject

Param Type Description
cipheredText string ciphered data

Example

import { CipherObject } from 'json-cipher-value'

const secret = 'My secret password'

const cipheredText = ...

const cipherObject = new CipherObject(secret)
const decipheredValue = cipherObject.decipher(cipheredText)

json-cipher-value~Options : Object

Settings for (de)ciphering.

Kind: inner typedef of json-cipher-value
Category: Typedefs
See: https://nodejs.org/api/crypto.html for further information; in particular about available algorithms and theirs iv lengths.
Properties

Name Type Default Description
[algo] string "aes-256-crt" the algorithm to use.
[ivLength] int 16 its initialization vector length.