Home > Enterprise >  Sharing key chain variable in Xamarin
Sharing key chain variable in Xamarin

Time:08-05

We have an iOS app that is built in different platform(swift,xamarin). We have a requirements that required those app to share variables using keychain. The keychain sharing is working for swift to swift App but for swift to Xamarin App it is not working. Possible something wrong with my code. I don't see much documentation in Xamarin on how to access keychain.

        SecStatusCode res;
        var rec = new SecRecord(SecKind.GenericPassword)
        {
            Generic = NSData.FromString("sharedKey"),
            AccessGroup = ""
        };
        var match = SecKeyChain.QueryAsRecord(rec, out res);

        if (match != null)
        {
            var dt = match.ValueData.ToString();

           return dt;
        }

CodePudding user response:

This might be caused by your Xamarin app not being access the keychain.

I don't know if you have this implemented, but if this is missing, try to Enable Keychain Access in your Xamarion iOS application.

CodePudding user response:

I figure out my issue.

SecStatusCode res;
    var rec = new SecRecord(SecKind.GenericPassword)
    {
        AccessGroup = "Shared access group example MC123.com.test.shared",
        Account = "SharedKey that you are looking for"
    };
    var match = SecKeyChain.QueryAsRecord(rec, out res);

    if (match != null)
    {
        var dt = match.ValueData.ToString();

       return dt;
    }
  • Related