diff --git a/browser.js b/browser.js index 11cb609..c9847df 100644 --- a/browser.js +++ b/browser.js @@ -78,13 +78,15 @@ function getAes(op) { } else { if (op === 'encrypt') { var cipher = nodeCrypto.createCipheriv('aes-256-cbc', key, iv); - cipher.update(data); - resolve(cipher.final()); + let firstChunk = cipher.update(data); + let secondChunk = cipher.final(); + resolve(Buffer.concat([firstChunk, secondChunk])); } else if (op === 'decrypt') { var decipher = nodeCrypto.createDecipheriv('aes-256-cbc', key, iv); - decipher.update(data); - resolve(decipher.final()); + let firstChunk = decipher.update(data); + let secondChunk = decipher.final(); + resolve(Buffer.concat([firstChunk, secondChunk])); } } }); diff --git a/test.js b/test.js index cd40f31..4da5607 100644 --- a/test.js +++ b/test.js @@ -217,6 +217,14 @@ describe("ECIES", function() { }); }); + it("should encrypt and decrypt with message size > 15", function() { + return eccrypto.encrypt(publicKeyA, Buffer.from("message size that is greater than 15 for sure =)")).then(function(enc) { + return eccrypto.decrypt(privateKeyA, enc); + }).then(function(msg) { + expect(msg.toString()).to.equal("message size that is greater than 15 for sure =)"); + }); + }); + it("should encrypt with compressed public key", function() { return eccrypto.encrypt(publicKeyBCompressed, Buffer.from("test"), encOpts) .then(function(enc) {