encrypt icon indicating copy to clipboard operation
encrypt copied to clipboard

[v5.0.3][Web] decrypt incorrect

Open zs-dima opened this issue 9 months ago • 7 comments

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

zs-dima avatar May 14 '24 11:05 zs-dima

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;
 }

tipu0710 avatar May 18 '24 03:05 tipu0710

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

ArslanKhan99 avatar May 22 '24 12:05 ArslanKhan99

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

ArslanKhan99 avatar May 22 '24 12:05 ArslanKhan99

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

ArslanKhan99 avatar May 22 '24 12:05 ArslanKhan99

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.

wsk321 avatar May 30 '24 02:05 wsk321

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.

ArslanKhan99 avatar Jun 03 '24 10:06 ArslanKhan99

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 !!!
        ),
);

yogithesymbian avatar Sep 20 '24 14:09 yogithesymbian