Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "synapsis", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,6 @@ /** | ||
var crypto = require('crypto'); | ||
const crypto = require('crypto'); | ||
//const IV = new Buffer(crypto.randomBytes(12)).toString('hex').slice(0, 16); | ||
const IV = 'abcdefghiquejrkt'; | ||
const ALGO = 'aes-128-cbc'; | ||
@@ -15,10 +18,10 @@ /* | ||
function secure(msg, key) { | ||
var cipher = crypto.createCipher('aes-256-ctr', key); | ||
var cipher = crypto.createCipheriv(ALGO, key, IV); | ||
var hmac = crypto.createHmac('sha256', key); | ||
var plaintext = (typeof msg === "object") ? JSON.stringify(msg) : msg.toString(); | ||
var ciphertext = cipher.update(plaintext, 'utf8', 'base64') + cipher.final('base64'); | ||
var ciphertext = cipher.update(plaintext, 'utf8', 'hex') + cipher.final('hex'); | ||
hmac.update(ciphertext); | ||
var mac = hmac.digest('base64'); | ||
var mac = hmac.digest('hex'); | ||
@@ -37,7 +40,7 @@ return {payload: ciphertext, mac: mac}; | ||
hmac.update(msg.payload); | ||
var mac = hmac.digest('base64'); | ||
var mac = hmac.digest('hex'); | ||
if(mac === msg.mac) { | ||
var decipher = crypto.createDecipher('aes-256-ctr', key); | ||
var plaintext = decipher.update(msg.payload, 'base64', 'utf8') + decipher.final('utf8'); | ||
var decipher = crypto.createDecipheriv(ALGO, key, IV); | ||
var plaintext = decipher.update(msg.payload, 'hex', 'utf8') + decipher.final('utf8'); | ||
@@ -72,6 +75,6 @@ // attempt to parse as json | ||
wrapper.prime = dhObj.getPrime('base64'); | ||
wrapper.publicKey = dhObj.generateKeys('base64'); | ||
wrapper.publicKey = dhObj.generateKeys('hex'); | ||
wrapper.computeSecret = function(remotePublicKey) { | ||
return dhObj.computeSecret(remotePublicKey.toString(), 'base64', 'base64'); | ||
return dhObj.computeSecret(remotePublicKey.toString(), 'hex', 'hex'); | ||
}; | ||
@@ -78,0 +81,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
685
22008
11