Open kcibdev opened 2 years ago
observing this same issue...
I have the same issue...
I solved the problem,length to be supplemented.
String pad(String s){
int l = 16 - utf8.encode(s).length % 16;
return s + String.fromCharCode(0) * l;
}
String getSign() {
String str = "1234567890";
String password = "8A04D41F57EFCDA7";
String ivv = "8A04D41F57EFCDA7";
//加密key
final key = Encrypt.Key.fromUtf8(password);
//偏移量
final iv = Encrypt.IV.fromUtf8(ivv);
//设置cbc模式
final encrypter = Encrypt.Encrypter(Encrypt.AES(key, mode: Encrypt.AESMode.cbc, padding: null));
//加密
final encrypted = encrypter.encrypt(pad(str), iv: iv);
return encrypted.base64;
}
I am trying to encrypt and decrypt chat messages for my app using this code
I generated a unique 16 characters for key and iv for each chat room u know for security purpose Eg
But i keep getting the error
Invalid argument(s): Invalid or corrupted pad block
So i added padding to be nullfinal encrypter = Encrypter(AES(key, mode: AESMode.cbc, padding: null));
I still get another errorUnhandled Exception: Invalid argument(s): Input buffer too short
And if i use a particular non-generated dummy key
It works perfectly without any issue, but this isn't secured. So i want to ask if my problem is from the keys i generated or from somewhere else. Please help me out.