简体   繁体   中英

key chain not storing data in iOS simulator 11.2

I wrote below code in xamarin c# to store sensitive data in iPhone Keychain.

    void StoreKeysInKeychain(string key, string value)
    {

        var user = Settings.CurrentUser;
        var userstring = JsonConvert.SerializeObject(user);

        if (value == "logout")
        {
            userstring = string.Empty;
        };

        var record = new SecRecord(SecKind.GenericPassword)
        {
            ValueData = NSData.FromString(userstring),
            Generic = NSData.FromString(key),
            Label="Sanket",
        };
        SecKeyChain.Remove(record);
        SecKeyChain.Add(record);

    }

    SecRecord GetRecordsFromKeychain(string key)
    {
        SecStatusCode res;
        var rec = new SecRecord(SecKind.GenericPassword)
        {
            Generic = NSData.FromString(key)
        };
        return SecKeyChain.QueryAsRecord(rec, out res);
    }

Tested with the same code on another MAC simulator and it is working there but not on my MAC.

Both the MAC has same iOS 10.13.3 and simulator version 11.2. Even I tried to change the simulators but it doesn't store the data.

I tried to browse Keychain contents stored in sqlite format. Refer below link how to browse content stored in Keychain of simulator.

Link to : Browse Keychain Data stored in Simulator

I Tried to reset content of simulator but no luck.

Any help will be appreciated. Thanks :(

In iOS 10 keychain on the simulator broke. Check out this Xamarin forums post: https://forums.xamarin.com/discussion/77760/ios-10-keychain and the correlated apple post: https://forums.developer.apple.com/thread/51071 .

Here is the issue: Issue: SecKeyChain.Add() returns -34018 on iOS 10 simulator unless Enable Keychain Access Groups has been enabled in Entitlements.plist.

You need to update your Entitlements.plist for the simulator build configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM