aes_crypt icon indicating copy to clipboard operation
aes_crypt copied to clipboard

When setting keys in ECB mode, don't check IV length.

Open smaxa20 opened this issue 4 years ago • 0 comments

I was trying to encrypt a string using a generated key and no IV because I'm using ECB. Here's my code:

var crypt = AesCrypt();
crypt.aesSetMode(AesMode.ecb);
Uint8List key = crypt.createKey();
crypt.aesSetKeys(key);
...

When I go to set the key it fails giving this error: Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null.

With this partial stack trace:


E/flutter ( 7509): #1      _Aes.aesSetKeys          package:aes_crypt/src/aes.dart:199
E/flutter ( 7509): #2      AesCrypt.aesSetKeys      package:aes_crypt/src
...

Following this trace to aes_crypt/src/aes.dart:199 I find this code: https://github.com/alexgoussev/aes_crypt/blob/68cb8f74705d46f060d30b237dd19f4b7170a763/lib/src/aes.dart#L199

It checks the length of the IV even in ECB mode when ECB mode doesn't require an IV (if my understanding is correct). I've made this check only occur when the mode is not ECB.

smaxa20 avatar Apr 24 '20 18:04 smaxa20