mogol / flutter_secure_storage

A Flutter plugin to store data in secure storage
https://pub.dartlang.org/packages/flutter_secure_storage
BSD 3-Clause "New" or "Revised" License
1.09k stars 342 forks source link

v7.0.1 PlatformException(Exception encountered, readAll, java.lang.SecurityException: Could not decrypt key. decryption failed #501

Open meomap opened 1 year ago

meomap commented 1 year ago

Hello, I think the option encryptedSharedPreferences: true works for read but not readAll. I can read value by specific key but cannot retrieve all values.

Errors thrown on some devices Android version 11, 12, 13.

Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(Exception encountered, readAll, java.lang.SecurityException: Could not decrypt key. decryption failed
    at androidx.security.crypto.EncryptedSharedPreferences.decryptKey(EncryptedSharedPreferences.java:7)
    at androidx.security.crypto.EncryptedSharedPreferences.getAll(EncryptedSharedPreferences.java:4)
    at p9.a.l(FlutterSecureStorage.java:2)
    at p9.e$b.run(FlutterSecureStoragePlugin.java:13)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.security.GeneralSecurityException: decryption failed
    at o4.c$a.b(DeterministicAeadWrapper.java:15)
    at androidx.security.crypto.EncryptedSharedPreferences.decryptKey(EncryptedSharedPreferences.java:4)
    ... 8 more
, null). Error thrown depricated2.exportAll error
error:PlatformException(Exception encountered, readAll, java.lang.SecurityException: Could not decrypt key. decryption failed
    at androidx.security.crypto.EncryptedSharedPreferences.decryptKey(EncryptedSharedPreferences.java:7)
    at androidx.security.crypto.EncryptedSharedPreferences.getAll(EncryptedSharedPreferences.java:4)
    at p9.a.l(FlutterSecureStorage.java:2)
    at p9.e$b.run(FlutterSecureStoragePlugin.java:13)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.security.GeneralSecurityException: decryption failed
    at o4.c$a.b(DeterministicAeadWrapper.java:15)
    at androidx.security.crypto.EncryptedSharedPreferences.decryptKey(EncryptedSharedPreferences.java:4)
    ... 8 more
, null).
tijee commented 1 year ago

Yes, same error for me with EncryptedSharedPreferences .getAll.

tijee commented 10 months ago

Hi, any update on this?

@meomap did you find a workaround?

meomap commented 10 months ago

@tijee We've already migrated from this lib. It's too painful when you have a large user base. 😓 If I remember correctly, instead of readAll, we use read on all keys that we've already indexed elsewhere.

mellowcello77 commented 1 month ago

Just to confirm: so we should not enable encryptedSharedPreferences: true when using readAll()?

(I am using readAll as a workaround for the cannot find key issue that popped up 5 days ago that is still open, and now this new error came up under our Android 14 users)