Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed decryption not working in the browser for messages > 15 #64

Merged
merged 7 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}
});
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ describe("ECIES", function() {
});
});

it("should encrypt and decrypt with message size > 15", function() {
YZhenY marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down