Invalid argument(s): Invalid or corrupted pad block
- I can't decrypt encrypted Uint8List by below decrypt function the strange thing is it works fine with some data and not working with others my app is in production and users is crying now :( :) , any solution please ?
class EncryptDataBase {
static final key =
encryptLib.Key.fromUtf8('SOMEKEY');
static final iv = encryptLib.IV.allZerosOfLength(16);
static final Uint8List encryptionMarker =
Uint8List.fromList('EN:'.codeUnits);
static Uint8List encrypt(Uint8List data) {
final encrypter = encryptLib.Encrypter(encryptLib.AES(key));
final encrypted = encrypter.encryptBytes(data, iv: iv);
final markerAndData =
Uint8List(encryptionMarker.length + encrypted.bytes.length);
markerAndData.setRange(0, encryptionMarker.length, encryptionMarker);
markerAndData.setRange(
encryptionMarker.length,
markerAndData.length,
encrypted.bytes,
);
return markerAndData;
}
static Uint8List decrypt(Uint8List data) {
if (data.length >= encryptionMarker.length &&
data.sublist(0, encryptionMarker.length).toString() ==
encryptionMarker.toString()) {
final encryptedData = data.sublist(encryptionMarker.length);
final encrypter = encryptLib.Encrypter(encryptLib.AES(key));
return Uint8List.fromList(
encrypter.decryptBytes(encryptLib.Encrypted(encryptedData), iv: iv));
}
// If no marker, return the data as it is
return data;
}
}
the same issue is there any solution?
We had the same issue. Downgrading to version 5.0.1 worked for us. Looks like there is some kind of breaking change in 5.0.2
same issue,need help
We had the same issue. Downgrading to version 5.0.1 worked for us. Looks like there is some kind of breaking change in 5.0.2
I agree. I had the 5.0.3, with some code to decrypt I was receiving the same issue, but in addition to it, with the sample code in the repo but with a tiny modification to decrypt from plain text, not from an Encrypter object, it simply didn't decrypt, instead it left the same crypted value.
Same issue, downgrading to 5.0.1 solved it.
Same issue at 5.0.3
Replaced
IV.fromLength(16);
with
IV.allZerosOfLength(16);
worked for me.
Downgrading to 5.0.1 in my new app did not work for me. Now I've left with lots of encrypted data only my old app (also using 5.0.1) can "understand".
Same problem here
fixed mine by using the below dependencies:
dependencies: encrypt: 5.0.1
dependendependency_overrides: pointycastle: 3.5.2
Same issue at 5.0.3
Replaced
IV.fromLength(16);withIV.allZerosOfLength(16);worked for me.
Solved by using this solution, but need first uninstall existing app
The default encryption method is CBC, which requires an initial vector (IV) during encryption. The decryption will fail if provided IV is not the same as the one used in encryption.
It seems that IV.fromLength() creates a random IV, causing the decryption failure.
For me, saving the IV during encryption (same as the key itself), and load the same IV (through IV.fromBase64()) before the decryption works.
same issue anyone found any solution ??
I have encrypted data with 5.0.3 and now its not getting decrypted.
Any solution to get encrypted data back
any solution yet?
Solution its working for me
dependency_overrides: pointycastle: 3.2.0 encrypt: 5.0.1
Above solution does solve the problem but Is it safe to push new release with this version?