1.2.2 • Published 7 years ago

diffie-hellman-key-exchange v1.2.2

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

Diffie Hellman Key Exchange :key:

Build Status

Diffie Hellman key exchange framework

Install

To install diffie-hellman-key-exchange, simply use npm:

npm install diffie-hellman-key-exchange --save

Example

Alice

const Dh = require('diffie-hellman-key-exchange')

const alice = Dh('alice', {
  prime: 'prime',
  listen: 8000,
  log_level: 'info',
  apps: {
    'bob': {
      host: '127.0.0.1',
      port: '8001'
    }
  }
})

// on incoming message

const decrypted = alice.decrypt('bob', message)

Bob

const Dh = require('diffie-hellman-key-exchange')

const bob = Dh('bob', {
  prime: 'prime',
  listen: 8001,
  apps: {
    'alice': {
      host: '127.0.0.1',
      port: '8000'
    }
  }
})

if (bob.getAppPublicKey('alice')) {
  const message = this.encrypt('alice', 'hello')

  // send message
} else {
  bob.initalizeSession('alice', function(err, secret) {
    const message = this.encrypt('alice', 'hello')

    // send message
  })
}

Swimming Bob

const Swim = require('swim')
const Dh = require('diffie-hellman-key-exchange')

const swim = new Swim({
    local: {
        host: 'my_host:port',
        meta: {
          // must have this object in order to communicate my connection info
          dh: {
            name: 'bob',
            host: 'my_host',
            port: 8001
          }
        }
    }
})

swim.bootstrap(hostsToJoin)

const bob = Dh('bob', {
  prime: 'prime',
  listen: 8001,
  apps: swim // it will load all the app from swim
})

API

  • Dh()
  • instance.createDH()
  • instance.generateNewKeys()
  • instance.initalizeSession()
  • instance.addApp()
  • instance.setAppPublicKey()
  • instance.getAppPublicKey()
  • instance.encrypt()
  • instance.decrypt()
  • instance.dh
  • instance.crypter

Dh(app_name, opts)

Creates a new instance of Dh.


instance.createDH()

Set a new DH instance, available by the dh attribute. es: instance.dh


instance.generateNewKeys()

Generate a new pair of keys


instance.initalizeSession(other_app_name, cb)

Initialize the public key (each other) in order to start the communication

  • other_app_name, app that i want to communicate
  • cb, function(err, secret_key) { assert.ok(this instanceof Dh) }

instance.addApp(app_name, opts)

Add one app connection to che instance configuration


instance.setAppPublicKey(app_name, public_key)

Set the public key for the specified app


instance.getAppPublicKey(app_name)

Return the public key if present

  • app_name

instance.encrypt(app_name, data)

Encrypt data for the given app name


instance.decrypt(app_name, data)

Decrypt data with the public key of the given app name


instance.dh

Attribute with the DH nodejs crypto class


instance.crypter

Attribute with the Crypter class

Methods:

  • encrypt(data, secret)
  • decrypt(data, secret)
1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago