leocavalcante / encrypt

🔒 A set of high-level APIs over PointyCastle for two-way cryptography.
BSD 3-Clause "New" or "Revised" License
343 stars 139 forks source link

[v5.0.3][Web] decrypt incorrect #334

Open zs-dima opened 4 months ago

zs-dima commented 4 months ago

decrypt incorrect in case of Web release. the same code decrypt correctly in the debug or encrypt v5.0.1

final key = Key.fromUtf8("key");
final initializationVector = IV.fromLength(16);
final encrypter = Encrypter(AES(key, mode: AESMode.cbc, padding: 'PKCS7'));
return encrypter.decrypt64(this, iv: initializationVector);

Flutter 3.16.4 encrypt v5.0.3

tipu0710 commented 4 months ago

Facing same issue on web. I'm using encrypt: ^5.0.3. It was working well before. Here is my code.

final _encrypter = Encrypter(
    AES(Key.fromUtf8('key')),
  );
  static final _iv = IV.fromLength(16);
 String encrypt(String value) {
    final encrypted = _encrypter.encrypt(value, iv: _iv);
    return encrypted.base64;
  }

 String decrypt(String value) {
    var decrypt = _encrypter.decrypt64(value, iv: _iv);
    return decrypt;
  }
ArslanKhan99 commented 4 months ago

Same issue encryption is also wrong as when going to decrypt it its give symbols in return

ArslanKhan99 commented 4 months ago

THIS ID DECRYPTED Value. This is printing console as it was working fine earlier ���Pl��fY�#��~675

ArslanKhan99 commented 4 months ago

It is encryption seems okay but its also wrong because when try to decrypt it on server side it gives the same decrypt show above "x1kNa/Tk0yH13GhvwmfRGirqGqBFxOt03zqWOf5A6WQ="

wsk321 commented 3 months ago

I encountered this issue today, and after reverting to version 5.0.0, it no longer appeared. I hope the author can address this issue for versions post 5.0.0.

ArslanKhan99 commented 3 months ago

the old version was not longer available I sort this issue like below

get version 5.0.1 directory from my pub cached. update the project according to my project and use this as local dependency its worked now.

yogithesymbian commented 1 day ago

I think I misunderstood the documentation.

Finally, I solved it with the help of ChatGPT! After using this library since 2022, the same problem resurfaced in 2024. Now it's resolved. I’m using it on my mobile (Android), and I believe it will work on other specific devices as well. I used padding set to 'PKCS7'.

My issue(story) is that when the decryption has different lengths, it produces different ASCII symbols. 😅 Two years ago, I solved it by simply replacing everything ascii thats already known by debugging.

[log] data encryption : AjLQ/Htb7J/10101p2XXXXXXXXXXXXXXXqFS5fqkBdo=  // "I have censored this data."
[log] data result decryption : {"id": 100001, "XXXX_XXXX": 1}//  "I have censored this data."
The numbers below are IDs:
1-99 are safe.
100 contains random ASCII characters (weird characters: ).

101-999 are safe (solved by replacing all ASCII with empty strings).
1,000 contains random ASCII characters (• weird characters: ).

1,001-9,999 are safe (solved by replacing all ASCII with empty strings).
10,000 contains random ASCII characters (• weird characters: ).

10,001-99,999 are safe (solved by replacing all ASCII with empty strings).
100,000 contains random ASCII characters (• weird ASCII characters: ).

100,001-999,999 are safe.

That means my system has encrypted/decrypted more than 100,000 pieces of data :D

Here’s an example for decryption my code :

final encrypter = aes.Encrypter(
        aes.AES(
          key,
          mode: aes.AESMode.cbc,
          padding: 'PKCS7', //  solved !!!
        ),
);