How to save to keychain and have appear under Websites & App Passwords

Hi,

I stumbled across some code to save a record to the keychain and to retrieve the record. That works fine.

    public static bool SaveValueToKeyChain(string entryKey, string entryValue)
    {
        SecRecord record = new SecRecord(SecKind.GenericPassword)
        {
            Account = entryKey,
            Label = entryKey,
            Service = _keyChainServiceName
        };

        SecStatusCode resultCode;
        SecKeyChain.QueryAsRecord(record, out resultCode);

        if (resultCode == SecStatusCode.Success)
        {
            if (SecKeyChain.Remove(record) != SecStatusCode.Success)
            {
                return false;
            }
        }

        resultCode = SecKeyChain.Add(new SecRecord(SecKind.GenericPassword)
        {
            Label = entryKey,
            Account = entryKey,
            Service = _keyChainServiceName,
            Accessible = SecAccessible.Always,
            Synchronizable = false,
            ValueData = NSData.FromString(entryValue, NSStringEncoding.UTF8),

        });           

        return resultCode == SecStatusCode.Success;
    }

The question I have is how do I save the record and have it display under Settings -> Passwords and accounts -> Websites & App Passwords.

Tagged:
Sign In or Register to comment.