A Swift API for storing, retrieving, and removing generic password items in the system Keychain.
Swift Objective-C
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ELKeychain.xcodeproj
ELKeychain
ELKeychainTestHost
ELKeychainTests
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md

README.md

ELKeychain

Build Status Carthage Compatible

A Swift framework for storing, retrieving, and removing generic password items in the system Keychain.

Requirements

ELKeychain requires Swift 4 and Xcode 9.2.

Installation

Carthage

Install with Carthage by adding the framework to your project's Cartfile.

github "Electrode-iOS/ELKeychain"

Manual

Install manually by adding ELKeychain.xcodeproj to your project and configuring your target to link ELKeychain.framework.

There are two target that builds ELKeychain.framework.

  1. ELKeychain: Creates dynamically linked ELKeychain.framework.
  2. ELKeychain_static: Creates statically linked ELKeychain.framework.

Both targets build the same product (ELKeychain.framework), thus linking the same app against both ELKeychain and ELKeychain_static should be avoided.

Usage

Storing a Generic Password Item

let password = "12345"

do {
  try Keychain.set(password, account: "king-roland", service: "druidia-airshield")
} catch let error {
    // failed to store keychain item
}

Retrieving a Generic Password Item

do {
    if let password: String = try Keychain.get(account: "king-roland", service: "druidia-airshield") {
        Airshield.unlock(password: password)
    } else {
      // unable to find password to unlock
    }
} catch let error {
    // an error occurred while retrieving the keychain item
}


Removing a Generic Password Item

do {
    try Keychain.delete(account: "king-roland", service: "druidia-airshield")
} catch let error {
    // an error occurred while trying to delete the keychain item
}

Storing a Generic Password Item w/ Access Control

do {
    let accessControl = try AccessControl(protection: .whenPasscodeSetThisDeviceOnly, policy: .UserPresence)
    try Credential.keychain.set("12345", account: "king-roland", accessControl: accessControl)
} catch let error {
    // an error occurred
}