Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encrypted-config

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encrypted-config

Safely store secrets in configuration objects.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

EncryptedConfig

Safely store secrets in configuration objects.

npm install encrypted-config

Basic usage

var EncryptedConfig = require('encrypted-config')

// We'll use a not-so-secure encryption algorithm of reversing the string
var configWithSecrets = {
  // by default, keys of secret values are prefixed with an underscore
  // the prefix will be removed when the configuration is decrypted
  _band: 'traeH eht dna daeH ehT',
  $album: 'Let\'s Be Still',
  things: {
    sounds: {
      songs: {
        // deep nesting works
        _shake: 'yrd nar nep ym ni kni eht lleW',
        'homecoming heroes': 'So now I know'
      }
    }
  }
}

function decrypt(encryptedValue, callback) {
  // this should be a more secure system
  var plaintext = encryptedValue.split('').reverse().join('')

  // callback is (err, value), can be async
  setImmediate(callback.bind(null, null, plaintext))
}

var encryptedConfig = EncryptedConfig.create(configWithSecrets, decrypt)

// read values via promises
encryptedConfig.read().then(function (config) {
  // config is now our converted object with plaintext values and prefixes removed from
  // encrypted keys

  console.log(config.band)
  // 'The Head and the Heart'

  console.log(config.things.sounds.songs.shake)
  // 'Well the ink in my pen ran dry'
})

// read nested values
encryptedConfig.readPath('band').then(function (band) {
  console.log(band)
  // 'The Head and the Heart'
})

// no errors if values are not set
encryptedConfig.readPath('path.to.fake.data').then(function (data) {
  console.log(data)
  // undefined
})

More realistic usage

A more reasonable usage would be to store data encrypted with something like AWS's Key Management Service.

function decrypt(encryptedValue, callback) {
  var kms = new AWS.KMS()
  kms.decrypt({
    CiphertextBlob: new Buffer(encryptedValue, 'base64')
  }, function (err, result) {
    if (err) return callback(err)
    callback(null, result.Plaintext.toString())
  })
}

var encryptedConfig = EncryptedConfig.create(congigWithSecrets, decrypt)
encryptedConfig.read().then(function (config) {
  // all secrets in config have been decrypted via KMS
})

Options

If you don't like underscores as your key prefix, pass {prefix: 'whatever'} as the third argument to EncryptedConfig.create().

FAQs

Package last updated on 18 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc