Keychain

public class Keychain

This class offers an interface to the Keychain services.

They Keychain basically is a collection of items with attributes. Some attributes are stored securely and require user authorization to be accessed.

  • Defines errors that might occur during interaction with the systems Keychain service.

    See more

    Declaration

    Swift

    public enum Error : Swift.Error
  • Adds a new generic password to the Keychain.

    If the item already exists the itemAlreadyExists error will be thrown.

    Declaration

    Swift

    public static func store(password: Data, in item: GenericPasswordItem, with label: String? = nil) throws

    Parameters

    password

    The actual password that should be stored securely.

    item

    The item that should contain the password.

    label

    A label for the item.

  • Adds a new generic password to the Keychain.

    If the item already exists the itemAlreadyExists error will be thrown.

    Declaration

    Swift

    public static func store(password: String, in item: GenericPasswordItem, with label: String? = nil) throws

    Parameters

    password

    The actual password that should be stored securely.

    item

    The item that should contain the password.

    label

    A label for the item.

  • Updates the generic password for a given item.

    Declaration

    Swift

    public static func update(password: Data, for item: GenericPasswordItem) throws

    Parameters

    password

    The new password.

    item

    The item, that should be updated.

  • Updates the generic password for a given item.

    Declaration

    Swift

    public static func update(password: String, for item: GenericPasswordItem) throws

    Parameters

    password

    The new password.

    item

    The item, that should be updated.

  • Convenience function that updates the password if it exists or creates it otherwise.

    Declaration

    Swift

    public static func updateOrCreate(password: Data, for item: GenericPasswordItem) throws

    Parameters

    password

    The new password.

    item

    The item, that should be updated or created.

  • Convenience function that updates the password if it exists or creates it otherwise.

    Declaration

    Swift

    public static func updateOrCreate(password: String, for item: GenericPasswordItem) throws

    Parameters

    password

    The new password.

    item

    The item, that should be updated or created.

  • Retrieve a generic password for a given item.

    Declaration

    Swift

    public static func retrievePassword(for item: GenericPasswordItem) throws -> Data

    Parameters

    item

    The item, for which the password should be retrieved.

    Return Value

    The password stored for the given item.

  • Retrieve a generic password for a given item.

    Declaration

    Swift

    public static func retrievePassword(for item: GenericPasswordItem) throws -> String?

    Parameters

    item

    The item, for which the password should be retrieved.

    Return Value

    The password stored for the given item.

  • Removes an item from the Keychain.

    Declaration

    Swift

    public static func delete(item: KeychainItem) throws

    Parameters

    item

    The item that should be removed.