SecureStorage SetAsync Crash on Android when Device Locale is Arabic
Steps to Reproduce
- Use a device with Android version 5.1 (We tried on 6.0 and newer and they're fine)
- Make sure the device locale is set to Arabic
- Use the SecureStorage.SetAsycn API
Expected Behavior
The value should be set normally
Actual Behavior
An exception will be thrown, and the value is not set.
[0:] Java.Lang.IllegalArgumentException: invalid date string: Unparseable date: "aha``aaaacdaGMT+00:00" (at offset 0)
at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <034d4a9852dd45bea9353cc7776c99f0>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <034d4a9852dd45bea9353cc7776c99f0>:0
at Java.Security.KeyPairGenerator.GenerateKeyPair () [0x0000a] in <a10f61e70eeb434e952fef884856c199>:0
at Xamarin.Essentials.AndroidKeyStore.GetAsymmetricKeyPair () [0x000f2] in <230d0ea83c464f9180c0ddb04a444efe>:0
at Xamarin.Essentials.AndroidKeyStore.GetKey () [0x00034] in <230d0ea83c464f9180c0ddb04a444efe>:0
at Xamarin.Essentials.AndroidKeyStore.Encrypt (System.String data) [0x00000] in <230d0ea83c464f9180c0ddb04a444efe>:0
at Xamarin.Essentials.SecureStorage.PlatformSetAsync (System.String key, System.String data) [0x00014] in <230d0ea83c464f9180c0ddb04a444efe>:0
at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value) [0x00021] in <230d0ea83c464f9180c0ddb04a444efe>:0
at MyProj.WelcomeViewModel+<SaveAuthInfo>d__5.MoveNext () [0x0001a] in C:\Source\Code\Tests\MyProj\MyProj\Views\WelcomePage.xaml.cs:84
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <43dbbdc147f2482093d8409abb04c233>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <43dbbdc147f2482093d8409abb04c233>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <43dbbdc147f2482093d8409abb04c233>:0
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <43dbbdc147f2482093d8409abb04c233>:0
at MyProj.WelcomeViewModel+<Register>d__8.MoveNext () [0x001ec] in C:\Source\Code\Tests\MyProj\MyProj\Views\WelcomePage.xaml.cs:109
--- End of managed Java.Lang.IllegalArgumentException stack trace ---
java.lang.IllegalArgumentException: invalid date string: Unparseable date: "aha``aa`eeeiGMT+00:00" (at offset 0)
at com.android.org.bouncycastle.asn1.DERUTCTime.<init>(DERUTCTime.java:98)
at com.android.org.bouncycastle.asn1.x509.Time.<init>(Time.java:62)
at com.android.org.bouncycastle.x509.X509V3CertificateGenerator.setNotBefore(X509V3CertificateGenerator.java:112)
at android.security.AndroidKeyPairGenerator.generateKeyPair(AndroidKeyPairGenerator.java:127)
at java.security.KeyPairGenerator$KeyPairGeneratorImpl.generateKeyPair(KeyPairGenerator.java:276)
at mono.java.lang.RunnableImplementor.n_run(Native Method)
at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5668)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
Basic Information
- Version with issue: tested on 0.10.0-preview
- IDE: VS 2017 15.8
- Platform Target Frameworks:
- Android: Testing on Android 5.1, Compiled against and Targetting 8.1
- Android Support Library Version: 27.0.2.1
- Affected Devices: testing on a Huawei TIT-U02
Additional Info:
It also crashed on a Nexus 5X 5.1 emulator, but oddely it didn't crash when I tried the 5.0 version of the same emulator.
Related
https://stackoverflow.com/questions/35987510/illegalargumentexception-unparseable-date-during-androidkeystore-key-generatio
This is how to change to the Arabic language

Can you provide the code you are using. Key and Value you are setting.
I see you have already fixed it, nonetheless, here is a repro project SecureStorageTest.zip
:) <3 I appreciate it! I believe I have fixed it. Can you try out this NuGet for me: Xamarin.Essentials.0.10.1-preview.zip
Worked flawlessly 👍 I tested it on the emulator as I don't have the device on me right now. Will test on the device later on and will let you know.
RAD!
Flawless on the device as well 👍