@venncity/clou-utils
Advanced tools
Comparing version 1.2.1 to 2.0.0
@@ -6,2 +6,19 @@ # Change Log | ||
# [2.0.0](https://github.com/venn-city/graphql-clou/compare/@venncity/clou-utils@1.2.1...@venncity/clou-utils@2.0.0) (2020-01-01) | ||
### Bug Fixes | ||
* **clou-utils:** get encryption key from ssm ([e145299](https://github.com/venn-city/graphql-clou/commit/e145299fbc9066498205ea8fab6bb0d89ed44197)) | ||
* **clou-utils:** pass encryptionKey as parameter ([8ead158](https://github.com/venn-city/graphql-clou/commit/8ead1588b2b7c58533b070fdb21340fb49d0899d)) | ||
### BREAKING CHANGES | ||
* **clou-utils:** extract it from ssm instead of keeping it in default config | ||
## [1.2.1](https://github.com/venn-city/graphql-clou/compare/@venncity/clou-utils@1.2.0...@venncity/clou-utils@1.2.1) (2019-12-16) | ||
@@ -8,0 +25,0 @@ |
@@ -5,5 +5,4 @@ { | ||
"inputEncoding": "utf8", | ||
"outputEncoding": "hex", | ||
"key": "[109,222,210,53,239,58,28,172,79,35,200,88,235,138,81,100,4,140,42,96,186,184,134,14,158,247,116,197,238,167,60,57]" | ||
"outputEncoding": "hex" | ||
} | ||
} |
{ | ||
"name": "@venncity/clou-utils", | ||
"version": "1.2.1", | ||
"version": "2.0.0", | ||
"author": "Venn Engineering", | ||
@@ -45,3 +45,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "15c95596b1a8281135a070303cbe6942d467de66" | ||
"gitHead": "ad34bf71961e80cc7b7610c51a8895bdf8a960c8" | ||
} |
@@ -0,1 +1,2 @@ | ||
const crypto = require('crypto'); | ||
const utils = require('./generalUtils'); | ||
@@ -30,15 +31,17 @@ | ||
}); | ||
test('decrypt should return original value', () => { | ||
const originalData = utils.generateRandomInteger(10).toString(); | ||
const encryptedData = utils.encrypt(originalData); | ||
const decryptedData = utils.decrypt(encryptedData); | ||
expect(decryptedData).toEqual(originalData); | ||
describe('Encrypt/Decrypt', () => { | ||
const key = crypto.randomBytes(32); | ||
test('decrypt should return original value', () => { | ||
const originalData = utils.generateRandomInteger(10).toString(); | ||
const encryptedData = utils.encrypt(originalData, key); | ||
const decryptedData = utils.decrypt(encryptedData, key); | ||
expect(decryptedData).toEqual(originalData); | ||
}); | ||
test('encrypt output should not be the same input', () => { | ||
const originalData = utils.generateRandomString(20); | ||
const encryptedData = utils.encrypt(originalData, key); | ||
const encryptedDataSecond = utils.encrypt(originalData, key); | ||
expect(encryptedData).not.toEqual(encryptedDataSecond); | ||
}); | ||
}); | ||
test('encrypt output should not be the same input', () => { | ||
const originalData = utils.generateRandomString(20); | ||
const encryptedData = utils.encrypt(originalData); | ||
const encryptedDataSecond = utils.encrypt(originalData); | ||
expect(encryptedData).not.toEqual(encryptedDataSecond); | ||
}); | ||
describe('extractWhereFromFederationReference', () => { | ||
@@ -45,0 +48,0 @@ test('should succesfully delete the __typename key from the given object', () => { |
@@ -5,3 +5,2 @@ const crypto = require('crypto'); | ||
const encryptionKey = Buffer.from(JSON.parse(config.get('encryption.key'))); | ||
const encryptionAlgorithm = config.get('encryption.algorithm'); | ||
@@ -39,3 +38,3 @@ const inputEncoding = config.get('encryption.inputEncoding'); | ||
function encrypt(data) { | ||
function encrypt(data, encryptionKey) { | ||
const iv = crypto.randomBytes(IV_LENGTH); | ||
@@ -49,3 +48,3 @@ const cipher = crypto.createCipheriv(encryptionAlgorithm, Buffer.from(encryptionKey), iv); | ||
function decrypt(data) { | ||
function decrypt(data, encryptionKey) { | ||
const dataBuffer = Buffer.from(data, outputEncoding); | ||
@@ -52,0 +51,0 @@ const dataLength = dataBuffer.length; |
13255
298