maui icon indicating copy to clipboard operation
maui copied to clipboard

SecureStorage.RemoveAll() exception

Open JORGEGO opened this issue 1 year ago • 3 comments

Description

When I run SecureStorage.RemoveAll() in android Produce: androidx.security.crypto.EncryptedSharedPreferences.decryptKey EncryptedSharedPreferences.java

java.security.GeneralSecurityException: decryption failed com.google.crypto.tink.daead.DeterministicAeadWrapper$WrappedDeterministicAead.decryptDeterministically DeterministicAeadWrapper.java:121 androidx.security.crypto.EncryptedSharedPreferences.decryptKey EncryptedSharedPreferences.java:622 androidx.security.crypto.EncryptedSharedPreferences.getAll EncryptedSharedPreferences.java:416 androidx.security.crypto.EncryptedSharedPreferences$Editor.clearKeysIfNeeded EncryptedSharedPreferences.java:372 androidx.security.crypto.EncryptedSharedPreferences$Editor.apply EncryptedSharedPreferences.java:362 androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.n_onClick(Native Method) androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick AlertDialog_IDialogInterfaceOnClickListenerImplementor.java:31 androidx.appcompat.app.AlertController$ButtonHandler.handleMessage AlertController.java:167 android.os.Handler.dispatchMessage Handler.java:106 android.os.Looper.loopOnce Looper.java:226 android.os.Looper.loop Looper.java:313 android.app.ActivityThread.main ActivityThread.java:8762 java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:604 com.android.internal.os.ZygoteInit.main ZygoteInit.java:1067

Java.Interop.JniEnvironment.InstanceMethods.CallVoidMethod(JniObjectReference instance, JniMethodInfo method) Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject, IntPtr jmethod) Android.Content.ISharedPreferencesEditorInvoker.Apply() Microsoft.Maui.Storage.SecureStorageImplementation.PlatformRemoveAll() Microsoft.Maui.Storage.SecureStorageImplementation.RemoveAll() Microsoft.Maui.Storage.SecureStorage.RemoveAll() greenyng.mobile.citizen.Helpers.Settings.ClearBarrelInformation() greenyng.mobile.citizen.AppShell.Button_Clicked(Object sender, EventArgs e) System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state) Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0() Java.Lang.Thread.RunnableImplementor.Run() Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) java.lang.SecurityException: Could not decrypt key. decryption failed androidx.security.crypto.EncryptedSharedPreferences.decryptKey EncryptedSharedPreferences.java:631 androidx.security.crypto.EncryptedSharedPreferences.getAll EncryptedSharedPreferences.java:416 androidx.security.crypto.EncryptedSharedPreferences$Editor.clearKeysIfNeeded EncryptedSharedPreferences.java:372 androidx.security.crypto.EncryptedSharedPreferences$Editor.apply EncryptedSharedPreferences.java:362 androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.n_onClick(Native Method) androidx.appcompat.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick AlertDialog_IDialogInterfaceOnClickListenerImplementor.java:31 androidx.appcompat.app.AlertController$ButtonHandler.handleMessage AlertController.java:167 android.os.Handler.dispatchMessage Handler.java:106 android.os.Looper.loopOnce Looper.java:226 android.os.Looper.loop Looper.java:313 android.app.ActivityThread.main ActivityThread.java:8762 java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:604 com.android.internal.os.ZygoteInit.main ZygoteInit.java:1067 Caused by: java.security.GeneralSecurityException: decryption failed com.google.crypto.tink.daead.DeterministicAeadWrapper$WrappedDeterministicAead.decryptDeterministically DeterministicAeadWrapper.java:121 androidx.security.crypto.EncryptedSharedPreferences.decryptKey EncryptedSharedPreferences.java:622

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.7 SR2

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

No for the moment

Relevant log output

No response

JORGEGO avatar Apr 04 '24 15:04 JORGEGO

Of course. From last version when I try to remove the local storage information using Microsoft.Maui.Storage produce an exception. If I use Remove(Key) works. Steps to reproduce it is very simple. Create a project set a pair (Key/Value) for example more that one and try to remove in Android platform. In Windows works. public static void ClearBarrelInformation() { try { SecureStorage.RemoveAll(); } catch (Exception) { return; } }

JORGEGO avatar Apr 04 '24 16:04 JORGEGO

Verified this issue with Visual Studio 17.10.0 Preview 3 (8.0.6 & 8.0.10 & 8.0.20). Can not repro it. image

ninachen03 avatar Apr 12 '24 08:04 ninachen03

I just came across this issue also

Microsoft Visual Studio Community 2022 Version 17.9.6 VisualStudio.17.Release/17.9.6+34728.123 Microsoft .NET Framework Version 4.8.09032

steps to reproduce: simply try running SecureStorage.Default.RemoveAll();

No known workarounds yet.

TemaTechUnLtd avatar Apr 28 '24 00:04 TemaTechUnLtd