Skip to content

Latest commit

 

History

History
51 lines (42 loc) · 1.73 KB

README.md

File metadata and controls

51 lines (42 loc) · 1.73 KB

NPM Build Status

node-crypto-config

Small Node Config extension which supports encryption.

Installation

  npm install crypto-config

Usage

This library is a wrapper around Config. On instantiation, each string property value matching the pattern ENC(<encrypted-value>) will go through the handler specified in the constructor.

const assert = require('assert');
const crypto = require('crypto');
const algorithm = 'aes-256-ctr';
const Config = require('crypto-config');
// The key which has been used to encrypt the password
const salt = 'secret';

// This is the handler to decrypt your encrypted values
function decrypt(val) {
    assert(text, "Unspecified text");
    const decipher = crypto.createDecipher(algorithm, salt);
    let dec = decipher.update(text, 'hex', 'utf8');
    dec += decipher.final('utf8');
    return dec;
}

// 'crypto-config' instantiation with handler.
const config = new Config(val => {
    return decrypt(val);
}).config;

The Config contains two properties: orig (original configuration values) and config (the handled configuration values).

Thanks

To Jasypt for the inspiration.

License

May be freely distributed under the MIT license. Copyright (c) 2017 Christian Ribeaud