Latest 1.0.0
Homepage https://github.com/deniskr/KeychainSwiftAPI
License MIT
Platforms ios 8.0, requires ARC
Frameworks Security
Authors

This Keychain Swift API library is a wrapper of iOS C Keychain Framework.
It allows easily and securely storing sensitive data in secure keychain store
in Swift projects. Interfacing with the original C keychain API is combersome from
Swift, and is prone to errors which lead to security vulnerabilities. This
library is written according to the best security coding practices and guidelines.

Usage

Import the KeychainSwiftAPI

import KeychainSwiftAPI

Create a query object:

let q = Keychain.Query()

Populate the query object with data. Query properties correspond to attribute keys of the C Keychain API,
protery values correspond to attribute values of the C Keychain API.

q.kSecClass = Keychain.Query.KSecClassValue.kSecClassGenericPassword
q.kSecAttrDescription = "A password from my website"
q.kSecAttrGeneric = "VerySecurePassword".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
q.kSecAttrAccount = "admin"
q.kSecReturnData = true
q.kSecReturnAttributes = true
q.kSecReturnRef = true
q.kSecReturnPersistentRef = true

Call Keychain.secItemAdd, which returns a pair of success code and result object.

let r = Keychain.secItemAdd(query: q)

Success code is wrapped in Keychain.ResultCode enum for convenience.

if (r.status == Keychain.ResultCode.errSecSuccess) {
    println("Password saved. Returned object: (r.result)")
} else {
    println("Error saving password: (r.status.description)")
}

r.result contains the object that was retured by the C SecItemAdd underlying function call.

Requirements

iOS 8.0 or above
You have to use cocoapod compiled from the Swift branch, since the master branch of cocoapods still does not fully support Swift.
See: Using Cocoapods Unreleased Features

Installation

KeychainSwiftAPI is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "KeychainSwiftAPI"

Author

Denis Krivitski, [email protected]

Sponsor

Checkmarx LTD. Checkmarx is a provider of code analysis tools,
static code analysis, software code analysis. We help developers make flawless applications.

License

KeychainSwiftAPI is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "KeychainSwiftAPI",
    "version": "1.0.0",
    "summary": "Swift wrapper of iOS C Keychain Framework",
    "description": "                        This Keychain Swift API library is a wrapper of iOS C Keychain Framework.n                        It allows easily and securely storing sensitive data in secure keychain storen                        in Swift projects. Interfacing with the original C keychain API is combersome fromn                        Swift, and is prone to errors which lead to security vulnerabilities. Thisn                        library is written according to the best security coding practices and guidelines.n",
    "homepage": "https://github.com/deniskr/KeychainSwiftAPI",
    "license": "MIT",
    "authors": {
        "Denis Krivitski": "[email protected]"
    },
    "source": {
        "git": "https://github.com/deniskr/KeychainSwiftAPI.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/*.{h,m,swift}",
    "resource_bundles": {},
    "public_header_files": "Pod/Classes/**/*.h",
    "frameworks": "Security"
}

Pin It on Pinterest

Share This