diff --git a/index.js b/index.js index 61fcc00..2a65715 100644 --- a/index.js +++ b/index.js @@ -521,7 +521,7 @@ } ModeOfOperationCFB.prototype.encrypt = function(plaintext) { - if ((plaintext.length % this.segmentSize) != 0) { + if (((plaintext.length * this.segmentSize) % this.segmentSize) != 0) { throw new Error('invalid plaintext size (must be segmentSize bytes)'); } @@ -543,7 +543,7 @@ } ModeOfOperationCFB.prototype.decrypt = function(ciphertext) { - if ((ciphertext.length % this.segmentSize) != 0) { + if (((ciphertext.length * this.segmentSize) % this.segmentSize) != 0) { throw new Error('invalid ciphertext size (must be segmentSize bytes)'); } diff --git a/test/test-errors.js b/test/test-errors.js index 93bac12..04180aa 100644 --- a/test/test-errors.js +++ b/test/test-errors.js @@ -61,7 +61,7 @@ module.exports = { var moo = new aes.ModeOfOperation.cfb(key, iv, i); - test.throws(function() { + test.doesNotThrow(function() { moo.encrypt(newBuffer(j)); }, function(error) { return (error.message === 'invalid plaintext size (must be segmentSize bytes)');