xaldarof / encrypted-shared-preferences

Perfect for developers prioritizing security, Encrypted Shared Preferences integrates effortlessly into your projects, offering peace of mind and enhancing data privacy. Safeguard your app's data with this essential encryption solution
Apache License 2.0
10 stars 2 forks source link

Can't save string when the value is empty #3

Closed Mingyueyixi closed 7 months ago

Mingyueyixi commented 7 months ago

hi, When i save data with a empty string, It will throw Exception.

The code is:

EncryptedSharedPreferences.getInstance().setString("abc", "");

The Exception is:

E/flutter (26499): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (start): Invalid value: Only valid value is 0: -16 E/flutter (26499): #0 RangeError.checkValidRange (dart:core/errors.dart:360:7) E/flutter (26499): #1 _TypedIntListMixin.sublist (dart:typed_data-patch/typed_data_patch.dart:466:31) E/flutter (26499): #2 PaddedBlockCipherImpl.doFinal (package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart:87:64) E/flutter (26499): #3 PaddedBlockCipherImpl.process (package:pointycastle/padded_block_cipher/padded_block_cipher_impl.dart:74:25) E/flutter (26499): #4 AES.encrypt (package:encrypt/src/algorithms/aes.dart:38:32) E/flutter (26499): #5 Encrypter.encryptBytes (package:encrypt/src/encrypter.dart:12:19) E/flutter (26499): #6 Encrypter.encrypt (package:encrypt/src/encrypter.dart:20:12) E/flutter (26499): #7 AESEncryptor.encrypt (package:encrypt_shared_preferences/src/crypto/aes.dart:14:46) E/flutter (26499): #8 SharedPreferencesDecorator.save (package:encrypt_shared_preferences/src/shared_preferences_decorator.dart:155:22) E/flutter (26499): #9 SharedPreferencesDecorator.setString (package:encrypt_shared_preferences/src/shared_preferences_decorator.dart:148:12) E/flutter (26499): #10 EncryptedSharedPreferences.setString (package:encrypt_shared_preferences/src/enc_shared_pref.dart:66:23)

xaldarof commented 7 months ago

Hi, can u provide MRE?

Mingyueyixi commented 7 months ago

Last week my project used a temporary solution where the empty string was saved with the key removed instead of stored.

Maybe that's probably not a good idea, and the other way is not encrypty the empty string, but I'm in the country this weekend, and I can't verify it.

Sorry about that

xaldarof commented 7 months ago

Great, send me the MRE when it is possible. Good luck. I will close the issue if you can send me the MRE; I can reopen the issue.