A Swift framework for storing, retrieving, and removing generic password items in the system Keychain.
ELKeychain requires Swift 5 and Xcode 10.2.
Install with Carthage by adding the framework to your project's Cartfile.
github "Electrode-iOS/ELKeychain"
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
.
ELKeychain
: Creates dynamically linkedELKeychain.framework.
ELKeychain_static
: Creates statically linkedELKeychain.framework
.
Both targets build the same product (ELKeychain.framework
), thus linking the same app against both ELKeychain
and ELKeychain_static
should be avoided.
let password = "12345"
do {
try Keychain.set(password, account: "king-roland", service: "druidia-airshield")
} catch let error {
// failed to store keychain 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
}
do {
try Keychain.delete(account: "king-roland", service: "druidia-airshield")
} catch let error {
// an error occurred while trying to delete the keychain item
}
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
}