encrypt icon indicating copy to clipboard operation
encrypt copied to clipboard

Bad state: IV is required

Open dushiling opened this issue 3 years ago • 4 comments

在encrypt和decrypt方法里,iv是可选参数,即 {IV? iv},但方法中写到 if (iv == null) { throw StateError('IV is required.'); },这导致我不传iv这个参数就会抛异常,这就表示,不管哪种加密方式,都必须传 iv,我认为这里逻辑写的有问题。希望能及时修正。

dushiling avatar Nov 16 '21 11:11 dushiling

for the RSA Algorithm, it doesn't require IV, so I guess I understand why the author put it as optional

farukprogrammer avatar Nov 16 '21 13:11 farukprogrammer

for the RSA Algorithm, it doesn't require IV, so I guess I understand why the author put it as optional

My current problem is: in my previous project, AES encryption was used, version 4.0.3 was used, iv was not passed (because iv was optional), there was no null-safe at that time; Now, after I upgrade to 5.0.1, if I do not upload IV, I will pass null exception, which makes me very helpless, so I have to upload IV, but this leads to the encryption method is different from the previous project.

Latest 5.0.1 release: Encrypted encrypt/decrypt (Uint8List bytes, {IV? iv}) { if (iv == null) { throw StateError('IV is required.'); }

xxxxxxxxxxx } (This means that either method will run a null-exception if iv is not passed.)

In version 4.0.3, it looks like this: Encrypted encrypt/decrypt (Uint8List bytes, {IV iv}) {

xxxxxxxxxxx } (IV value is not required)

dushiling avatar Nov 17 '21 02:11 dushiling

I also think this is a bug

yangyxd avatar Jun 11 '22 17:06 yangyxd

You can pass final IV iv = IV.fromLength(0); to skip this bug, if you confirm the mode desn't need IV.

jack24254029 avatar Apr 06 '23 08:04 jack24254029