[FIXED] Sharing key chain variable in Xamarin

Issue

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;
        }

Solution

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;
    }

Answered By – ramdev

Answer Checked By – Katrina (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published