aes_crypt
aes_crypt copied to clipboard
When setting keys in ECB mode, don't check IV length.
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.