Diffie Hellman key exchange framework
npm install diffie-hellman-key-exchangeDiffie Hellman key exchange framework
To install diffie-hellman-key-exchange, simply use npm:
```
npm install diffie-hellman-key-exchange --save
`javascript
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)
`
`javascript
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
})
}
`
`javascript
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
})
`
* Dh()
* instance.createDH()
* instance.generateNewKeys()
* instance.initalizeSession()
* instance.addApp()
* instance.setAppPublicKey()
* instance.getAppPublicKey()
* instance.encrypt()
* instance.decrypt()
* instance.dh
* instance.crypter
-------------------------------------------------------
Creates a new instance of Dh.
* app_name, the unique name of this appopts
* prime
* , the prime for DHgenerator
* , the generator for DHlisten
* , on which port the application will listen for the handshake public key exchange [default: 8000]log_level
* , log level for the pino instance [default: warn]crypter
* algorithm
* , algorithm used to encrypt [default: aes-256-ctr]apps
* , could be a Swim instance or object that contains all the apps [es: 'bob': { host: '127.0.0.1', port: 8000 } ]
-------------------------------------------------------
Set a new DH instance, available by the dh attribute. [es: instance.dh]
-------------------------------------------------------
Generate a new pair of keys
-------------------------------------------------------
Initialize the public key (each other) in order to start the communication
* other_app_name, app that i want to communicatecb
* , function(err, secret_key) { assert.ok(this instanceof Dh) }
-------------------------------------------------------
Add one app connection to che instance configuration
* app_nameopts
* , [es: 'bob': { host: '127.0.0.1', port: 8000 } ]
-------------------------------------------------------
Set the public key for the specified app
* app_namepublic_key
* , [type: 'hex']
-------------------------------------------------------
Return the public key if present
* app_name
-------------------------------------------------------
Encrypt data for the given app name
* app_namedata
* , [type: 'string']
-------------------------------------------------------
Decrypt data with the public key of the given app name
* app_namedata
* , [type: 'string']
-------------------------------------------------------
Attribute with the DH nodejs crypto class
-------------------------------------------------------
Attribute with the Crypter class
Methods:
* encrypt(data, secret)decrypt(data, secret)`
*