flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

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

Open meomap opened this issue 2 years ago • 4 comments

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

meomap avatar Jan 06 '23 01:01 meomap

Yes, same error for me with EncryptedSharedPreferences .getAll.

tijee avatar Jan 06 '23 13:01 tijee

Hi, any update on this?

@meomap did you find a workaround?

tijee avatar Aug 28 '23 13:08 tijee

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

meomap avatar Aug 29 '23 01:08 meomap

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)

mellowcello77 avatar May 15 '24 13:05 mellowcello77

I am closing all older issues. If this issue still exists in the latest version, please let me know.

juliansteenbakker avatar Aug 13 '24 19:08 juliansteenbakker