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): Invalid or corrupted pad block #337

Open
AhmedTawfiqM opened this issue Jun 8, 2024 · 12 comments
Open

Invalid argument(s): Invalid or corrupted pad block #337

AhmedTawfiqM opened this issue Jun 8, 2024 · 12 comments

Comments

@AhmedTawfiqM
Copy link

AhmedTawfiqM commented Jun 8, 2024

  • 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;
  }
}
@Mohamed1226
Copy link

the same issue
is there any solution?

@apackin
Copy link

apackin commented Jun 11, 2024

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

@Mr-yuwei
Copy link

same issue,need help

@neoacevedo
Copy link

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.

@plazareff
Copy link

Same issue, downgrading to 5.0.1 solved it.

@viniciusgiacomelli
Copy link

viniciusgiacomelli commented Jul 11, 2024

Same issue at 5.0.3

Replaced
IV.fromLength(16);
with
IV.allZerosOfLength(16);

worked for me.

@iamwilph
Copy link

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".

@reesaam
Copy link

reesaam commented Jul 20, 2024

Same problem here

@iamwilph
Copy link

fixed mine by using the below dependencies:

dependencies:
encrypt: 5.0.1

dependendependency_overrides:
pointycastle: 3.5.2

@lukaskris
Copy link

Same issue at 5.0.3

Replaced IV.fromLength(16); with IV.allZerosOfLength(16);

worked for me.

Solved by using this solution, but need first uninstall existing app

@Exception0x0194
Copy link

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.

@lakhanrathi1
Copy link

lakhanrathi1 commented Oct 26, 2024

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

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