/ELKeychain

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

Primary LanguageSwiftMIT LicenseMIT

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.

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
}