Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Supports iOS only.

Keychain is a wrapper library built around a small subset of features offered by Keychain Services to simplify saving and retrieving data to and from the iOS Keychain using kSecClassGenericPassword class.

While the Keychain Services offer comprehensive set of APIs and could be used directly, the app-side implementation for saving and retrieving data will most likely be verbose.

In a nutshell, to securely store an item using Keychain Services, a dictionary of predefined keys and values, also referred to as the keychain query, must be created first. This query must contain valid values for predefined set of keys that depend on a security class being used. To reduce the amount of manual work required to create a keychain query, this framework takes advantage of Swift features such as default implementation for protocols, generics and Codable for automatic encoding of models into external representation.

This approach leads to a much cleaner interaction with iOS Keychain that's enjoyable to use.


  • Simple to setup, easy to use & efficient
  • Supports custom data types
  • Supports storing multiple instances of the same type
  • Supports app and group-specific keychain configurations
  • Supports selective Type synchronization through iCloud
  • Handles object encoding and decoding from data returned by the iOS keychain
  • Comprehensive Unit Test Coverage
  • Complete Documentation


  • iOS 10.0+
  • Xcode 9.0+
  • Swift 4.0+


Carthage is the only supported way to install Keychain framework.

git "" "v1.0.0"

For more information on getting started with Carthage, visit the repo.


Keychain framework currently supports two access types - App Specific and Group Specific.

Getting started is easy. First, create the keychain instance using one of the supported access types.

let keychain = Keychain(access: .appSpecific(serviceName: "App"))

Any custom type you want to encrypt and store in iOS Keychain needs to conform and implement the KeychainItem protocol. The KeychainItem protocol provides default implementation for all of its properties - except the idKey. See documentation for more information.

struct Credential: KeychainItem {
    let username: String
    let password: String

    // MARK: KeychainItem

    var idKey: String {
        return username

Keychain offers a handful of methods that will allow you to save, delete, or retrieve items.

let user = User(username: "username", password: "password")

// save

// retrieve users
let users = try? keychain.items(ofType: User.self)

// retrieve a single user
let user = try? keychain.item(ofType: User.self, idKey: "username")

For group specific configuration, please see documentation.


The following tests were performed on an iPad Mini 4 WiFi + Cellular. The numbers are the average for performing each operation 3000 times.

  • Deleting: 0.00662
  • Inserting: 0.00862
  • Reading: 0.00291
  • Replacing: 0.00858


  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.



You can’t perform that action at this time.