SecKeyChain SecKeyChain Class


Access to the operating system keychain.

public class SecKeyChain : ObjCRuntime.INativeObject
type SecKeyChain = class
    interface INativeObject


This class can be used to add, remove, update or query the iOS or MacOS keychain. MacOS is limited to a single kind of password (SecKind.InternetPassword) while iOS offers a wider range of options.

Use QueryAsData(SecRecord, Boolean, Int32, SecStatusCode) to get values from the keychain as a binary blob. Some of the overloads can also return binary blobs that are suitable to be stored on disk, or passed to another process.

Use QueryAsConcreteType(SecRecord, SecStatusCode) to get a SecCertificate, a SecKey or a SecIdentity back from the keychain.

Use M:Security.SecKeyChain.QueryAsRecord* to get a strongly typed SecRecord with the results of your query.

var query = new SecRecord (SecKind.InternetPassword) {
   Sever = "",
   Account = "miguel"
var password = SecKeyChain.QueryAsData (query);
Console.WriteLine ("The password for the account is: {0}", password);


Handle Handle

Handle (pointer) to the unmanaged object representation.


Add(SecRecord) Add(SecRecord)

Adds the specified record to the keychain.

AddIdentity(SecIdentity) AddIdentity(SecIdentity)
FindIdentity(SecCertificate, Boolean) FindIdentity(SecCertificate, Boolean)
QueryAsConcreteType(SecRecord, SecStatusCode) QueryAsConcreteType(SecRecord, SecStatusCode)

Use this method to query the KeyChain and get back a SecCertificate, a SecKey or a SecIdentity.

QueryAsData(SecRecord) QueryAsData(SecRecord)

Fetches an NSData record from the Keychain.

QueryAsData(SecRecord, Int32) QueryAsData(SecRecord, Int32)

Fetches a set of NSData records from the Keychain.

QueryAsData(SecRecord, Boolean, SecStatusCode) QueryAsData(SecRecord, Boolean, SecStatusCode)

Fetches a set of NSData records from the Keychain.

QueryAsData(SecRecord, Boolean, Int32, SecStatusCode) QueryAsData(SecRecord, Boolean, Int32, SecStatusCode)

Fetches a set of NSData records from the Keychain.

QueryAsRecord(SecRecord, SecStatusCode) QueryAsRecord(SecRecord, SecStatusCode)

Fetches a single SecRecord.

QueryAsRecord(SecRecord, Int32, SecStatusCode) QueryAsRecord(SecRecord, Int32, SecStatusCode)

Fetches one or more SecRecords.

QueryAsReference(SecRecord, Int32, SecStatusCode) QueryAsReference(SecRecord, Int32, SecStatusCode)
Remove(SecRecord) Remove(SecRecord)

Removes the specified record from the keychain.

RemoveIdentity(SecIdentity) RemoveIdentity(SecIdentity)
Update(SecRecord, SecRecord) Update(SecRecord, SecRecord)

Updates the record matching the query with the provided data.

Applies to

See also