Xamarin - Issue is coming while Loading keytstore in Android

Mukul Bhardwaj 0 Reputation points
2024-02-15T12:57:52.3433333+00:00

This Exception is coming while using KeyChainHelper wrapper of Xamarin using this code:- keyChainHelper = new KeyChain.Net.XamarinAndroid.KeyChainHelper(context, "password"); The same is working fine Android12 but the issue is coming in Android13 Exception of type 'Java.IO.IOException' was thrown.

This Exception is coming while using KeyChainHelper wrapper of Xamarin using this code:-
keyChainHelper = new KeyChain.Net.XamarinAndroid.KeyChainHelper(context, "password");
The same is working fine Android12 but the issue is coming in Android13
Exception of type 'Java.IO.IOException' was thrown.
StackTrace :   at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <4d66ec627ead464ebcce4aa6164f7aa1>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002b] in <4d66ec627ead464ebcce4aa6164f7aa1>:0
at Java.Security.KeyStore.Load (System.IO.Stream stream, System.Char[] password) [0x00043] in <039327fe74f14973afaddc03c02ec4d0>:0
at KeyChain.Net.XamarinAndroid.KeyChainHelper..ctor (System.Func`1[TResult] context, System.String keyStoreFileProtectionPassword, System.String fileName, System.String serviceId) [0x000af] in <09887da633ad457f806c800538c7f9a4>:0    at KeyChain.Net.XamarinAndroid.KeyChainHelper..ctor (System.Func`1[TResult] context, System.String keyStoreFileProtectionPassword) [0x00000] in <09887da633ad457f806c800538c7f9a4>:0

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,386 Reputation points Microsoft Vendor
    2024-02-16T05:36:28.44+00:00

    Hello,

    KeyChain.Net project do not update for 9 years.

    You should not use this NuGet package anymore. Xamarin.Essentials provide similar API: Secure Storage.

    As note: Your KeyChain entries will get lost, if you just exchange the NuGet packages and do your modifications to match the API. You need to migrate your data. You should not try to use the data from this project with the Secure Storage to access your KeyChain

    For example, before you use this Secure Storage, you need to read all data by KeyChain.Net, then save it by Secure Storage.

    Best Regards, Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.