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

Invalid argument(s): Initialization vector must be the same length as block size #322

Open
NaarGes opened this issue Dec 13, 2023 · 0 comments

Comments

@NaarGes
Copy link

NaarGes commented Dec 13, 2023

Hi, when I run the below code it causes error: Invalid argument(s): Initialization vector must be the same length as block size
but if I replace 32 with 16 in both key and iv it gives me result without error. why is that?

final plainText = data.toString();
    final key = Key.fromLength(32);
    final iv = IV.fromLength(32);
    final aesEncrypter = Encrypter(AES(key, mode: AESMode.cbc));
    final encryptedJson = aesEncrypter.encrypt(plainText, iv: iv);

I'm using encrypt: ^5.0.3 version

full error log

 [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): Initialization vector must be the same length as block size
E/flutter ( 8817): #0      CBCBlockCipher.init (package:pointycastle/block/modes/cbc.dart:52:7)
E/flutter ( 8817): #1      PaddedBlockCipherImpl.init (package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart:47:12)
E/flutter ( 8817): #2      AES.encrypt (package:encrypt/src/algorithms/aes.dart:40:9)
E/flutter ( 8817): #3      Encrypter.encryptBytes (package:encrypt/src/encrypter.dart:12:19)
E/flutter ( 8817): #4      Encrypter.encrypt (package:encrypt/src/encrypter.dart:28:12)
E/flutter ( 8817): #5      KonectPlateEncrypter.getEncryptedData (package:marginal_parking_app/data/encrypter.dart:20:40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant