KeyClip is yet another Keychain library written in Swift.

Related tags

Security KeyClip
Overview

KeyClip

Build Status Carthage compatible

KeyClip is yet another Keychain library written in Swift.

Features

Usage

String

KeyClip.save("access_token", string: "********") // -> Bool

let token = KeyClip.load("access_token") as String?

KeyClip.delete("access_token") // Remove the data

KeyClip.clear() // Remove all the data

KeyClip.exists("access_token") // -> Bool

NSDictionary

Must be compatible to NSJSONSerialization.

Valid JSON elements are Dictionary, Array, String, Number, Boolean and null.

KeyClip.save("account", dictionary: ["name": "aska", "token": "******"]) // -> Bool

let dictionary = KeyClip.load("account") as NSDictionary?

NSData

KeyClip.save("data", data: NSData()) // -> Bool

let data = KeyClip.load("data") as NSData?

Your Class

KeyClip.save("account", dictionary: account.dictionaryValue)

let account = KeyClip.load("account") { (dictionary) -> Account in
    return Account(dictionary)
}

class Account {
    let name: String
    let password: String

    init(_ dictionary: NSDictionary) {
        self.name = dictionary["name"] as String
        self.password = dictionary["password"] as String
    }

    var dictionaryValue: [String: String] {
        return ["name": name, "password": password]
    }
}

Error Handling

Return value

let success = KeyClip.save("password", string: "********")
if !success {
    // Show Alert "Saving password to keychain failed"
}

Clojure

KeyClip.save("password", string: "********") { error in
    let status = error.code // OSStatus
    // Show Alert "Saving failed \(error.localizedDescription)(\(error.code))"
}

Debug print

KeyClip.printError(true)

Settings

let clip = KeyClip.Builder()

    // kSecAttrService
    .service(NSBundle.mainBundle().bundleIdentifier) // default

    // kSecAttrAccessible
    .accessible(kSecAttrAccessibleAfterFirstUnlock) // default

    // kSecAttrAccessGroup
    .accessGroup("XXXX23F3DC53.com.example.share") // default is nil

    .build()

Note to accessGroup

⚠️ iOS Simulator's keychain implementation does not support kSecAttrAccessGroup. (always "test")

⚠️ kSecAttrAccessGroup must match the App Identifier prefix. https://developer.apple.com/library/mac/documentation/Security/Reference/keychainservices/index.html

How to check the App Identifier

Entitlement.plist's keychain-access-groups or App Identifier.

KeyClip.defaultAccessGroup() // -> String (eg. XXXX23F3DC53.*)

Requirements

  • iOS 8.0+ / Mac OS X 10.10+
  • Xcode 8

Installation

Carthage

Add the following line to your Cartfile

github "s-aska/KeyClip"

CocoaPods

Add the following line to your Podfile

use_frameworks!
pod 'KeyClip'

License

KeyClip is released under the MIT license. See LICENSE for details.

Comments
  • Crash on Line #158

    Crash on Line #158

    depending on the provisioning profile I use, sometimes this line crashes

    https://github.com/s-aska/KeyClip/blob/master/KeyClip/KeyClip.swift#L158

    Not sure what I'm doing wrong

    opened by fwhenin 13
  • Remove wrong social_media_url

    Remove wrong social_media_url

    You specify wrong social_media_url in your podspec. Then CocoaPods new pod feed bot announce your pod with wrong Twitter account . https://twitter.com/CocoaPodsFeed/status/633634262147825664 😅

    opened by kishikawakatsumi 1
  • Add Podspec file for Cocoapods support

    Add Podspec file for Cocoapods support

    It would be really great if a Podspec was added to take advantage of the package management system Cocoapods. I would be happy to help with a PR, but in the end you will have to register the plugin (which I can walk you through)

    opened by kfarst 1
  • Swift 2.3 support...

    Swift 2.3 support...

    Hello. Thanks for KeyClip - it's a great library.

    I've just upgraded to Xcode 8 and a bunch of other libraries I use are still working on Swift 3 support, so I'm trying the Swift 2.3 route. However, this library doesn't seem to compile while targeting Swift 2.3.

    Cartfile:

    github "s-aska/KeyClip" == 1.4.0
    

    Carthage command:

    carthage update --platform iOS --toolchain com.apple.dt.toolchain.Swift_2_3 KeyClip
    

    Fails citing a bunch of syntax errors (because it's Swift 3 syntax).

    And then:

    Cartfile:

    github "s-aska/KeyClip" == 1.3.4
    

    Carthage command:

    carthage update --platform iOS --toolchain com.apple.dt.toolchain.Swift_2_3 KeyClip
    

    Fails citing ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/Developer/Library/Frameworks'.

    Would you consider a 1.3.5 with support for Swift 2.3 and Xcode 8?

    opened by smebberson 0
  • Unable to save

    Unable to save

    I have the following code to produce a Dictionary for KeyClip:

    var serialized: [String: String] {
    
        var dict = [
            "username": self.username,
            "password": self.password
        ]
    
        if let accessToken = self.accessToken {
            dict["accessToken"] = accessToken
        }
    
        if let refreshToken = self.refreshToken {
            dict["refreshToken"] = refreshToken
        }
    
        return dict
    
    }
    

    I use the following to get KeyClip to save the data:

    KeyClip.save("fb-account", dictionary: account.serialized as NSDictionary)
    

    I receive the following error:

    [KeyClip] function:save(_:data:failure:) line:77 Error Domain=pw.aska.KeyClip Code=-34018 "Refer to SecBase.h for description (status:-34018)" UserInfo={NSLocalizedDescription=Refer to SecBase.h for description (status:-34018)}
    

    This code used to work fine before Xcode 8, and KeyClip 1.4.0. I was using KeyClip 1.3.4. This occurs running on Simulator iPhone 6 with both iOS 9.0 and 10.0.

    Do you have any idea of what is happening?

    opened by smebberson 1
  • Carthage build Xcode 8 GM

    Carthage build Xcode 8 GM

    I'm having problems building KeyClip, and I also can't get it to save any data. When running:

    carthage update --platform iOS --no-use-binaries KeyClip
    

    I get:

    ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/Developer/Library/Frameworks'
    ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk/Developer/Library/Frameworks'
    ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/Developer/Library/Frameworks'
    ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.0.sdk/Developer/Library/Frameworks'
    
    • Carthage version: 0.18
    • Version 8.0 (8A218a)

    Cartfile:

    github "s-aska/KeyClip" == 1.4.0
    
    opened by smebberson 3
  • KeyClip.load error with Xcode 8

    KeyClip.load error with Xcode 8

    Hello, i was trying to implement this wrapper for keychain, but i definitely got some problem working with swift 3 on the new Xcode 8, when trying to reading a key from the keychain. The problem is related to the (simple) class func load, which gets just the key to perform loading) In terms of code:

    //This line produces the error Ambiguous use of 'load(_:failure:)' KeyClip.load("my_key")

    Just to let you know, i will try to use the load with closure, as it does not produce any error Thank you for the attention.

    opened by siideffect 3
  • Unable to build

    Unable to build

    Running Carthage 0.8.0 and xcode 6.3.2 I'm constantly running into issues with Keyclip for some reason

    The following build commands failed:
        CompileSwift normal x86_64 /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift
        CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
    (2 failures)
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:211:31: error: consecutive statements on a line must be separated by ';'
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:216:15: error: expected 'while' in 'do-while' loop
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:216:31: error: consecutive statements on a line must be separated by ';'
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:216:32: error: expected expression
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:216:43: error: braced block of statements is an unused closure
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:252:46: error: consecutive statements on a line must be separated by ';'
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:257:19: error: expected 'while' in 'do-while' loop
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:257:35: error: consecutive statements on a line must be separated by ';'
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:257:36: error: expected expression
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:257:47: error: braced block of statements is an unused closure
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:301:27: warning: 'failure failure' can be expressed more succinctly as '#failure'
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:322:30: warning: 'status status' can be expressed more succinctly as '#status'
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:327:30: warning: 'error error' can be expressed more succinctly as '#error'
            private func failure(error error: NSError, function: String = __FUNCTION__, line: Int = __LINE__, failure: ((NSError) -> Void)?) {
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:216:25: error: type annotation missing in pattern
    /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift:257:29: error: type annotation missing in pattern
    A shell task failed with exit code 65:
    ** BUILD FAILED **
    
    
    The following build commands failed:
        CompileSwift normal x86_64 /Users/localstackpro/Github/getclink-ios/Carthage/Checkouts/KeyClip/KeyClip/KeyClip.swift
        CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
    (2 failures)
    
    opened by katoree 2
Owner
Shinichiro Aska
Shinichiro Aska
A simple wrapper for the iOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift.

SwiftKeychainWrapper A simple wrapper for the iOS / tvOS Keychain to allow you to use it in a similar fashion to User Defaults. Written in Swift. Prov

Jason 1.5k Dec 30, 2022
A powerful, protocol-oriented library for working with the keychain in Swift.

Locksmith A powerful, protocol-oriented library for working with the keychain in Swift. ?? iOS 8.0+ ?? Mac OS X 10.10+ ⌚️ watchOS 2 ?? tvOS ?? I make

Matthew Palmer 2.9k Dec 21, 2022
LocalAuth - Another Fusion library to implement the local authentication using Biometry

FusionLocalAuth Another Fusion library to implement the local authentication usi

Vedant Jha 0 Jan 13, 2022
Simple Swift wrapper for Keychain that works on iOS, watchOS, tvOS and macOS.

KeychainAccess KeychainAccess is a simple Swift wrapper for Keychain that works on iOS and OS X. Makes using Keychain APIs extremely easy and much mor

Kishikawa Katsumi 7.2k Dec 30, 2022
A simple Swift Keychain Wrapper for iOS, watchOS, and OS X.

Latch A simple Swift 2.0 Keychain Wrapper for iOS, watchOS 2, and OS X. Usage A proper example of how to use Latch can be seen in the tests. import La

Danielle 56 Oct 25, 2022
Helper functions for saving text in Keychain securely for iOS, OS X, tvOS and watchOS.

Helper functions for storing text in Keychain for iOS, macOS, tvOS and WatchOS This is a collection of helper functions for saving text and data in th

Evgenii Neumerzhitckii 2.3k Dec 28, 2022
Generate passwords and save them in Keychain. Made with SwiftUI.

lockd Generate strong passwords and save them in Keychain. Join lockd Beta on TestFlight: https://testflight.apple.com/join/xJ5AlvS3 Features: Generat

Iliane 56 Dec 29, 2022
Simple Objective-C wrapper for the keychain that works on Mac and iOS

SAMKeychain SAMKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keyc

Sam Soffes 5.4k Dec 29, 2022
A really simple key-value wrapper for keychain.

PlainKeychain A really simple key-value wrapper for keychain. Features ✅ Key-value pairs using kSecClassGenericPassword. ❌ Internet passwords (kSecCla

Benjamin Barnard 0 Nov 27, 2021
A wrapper to make it really easy to deal with iOS, macOS, watchOS and Linux Keychain and store your user's credentials securely.

A wrapper (written only in Swift) to make it really easy to deal with iOS, macOS, watchOS and Linux Keychain and store your user's credentials securely.

Ezequiel Aceto 2 Mar 29, 2022
A wrapper for Apple's Common Crypto library written in Swift.

IDZSwiftCommonCrypto A Swift wrapper for Apple's CommonCrypto library. IDZSwiftCommonCrypto works with both CocoaPods and Cathage. For more details on

idz 472 Dec 12, 2022
A framework for the JOSE standards JWS, JWE, and JWK written in Swift.

JOSESwift is a modular and extensible framework for the JOSE standards JWS, JWE, and JWK written in Swift. ?? Please note that this implementation of

Airside Mobile, Inc. 162 Dec 15, 2022
An iOS passcode lock with TouchID authentication written in Swift.

PasscodeLock A Swift implementation of passcode lock for iOS with TouchID authentication. Installation PasscodeLock requires Swift 2.0 and Xcode 7 Car

Yanko Dimitrov 679 Nov 26, 2022
An iOS passcode lock with TouchID authentication written in Swift.

PasscodeLock A Swift implementation of passcode lock for iOS with TouchID authentication. Originally created by @yankodimitrov, hope you're doing well

Serge Velikan 203 Dec 6, 2022
Swift cross-platform crypto library using CommonCrypto/libcrypto

BlueCryptor Swift cross-platform crypto library derived from IDZSwiftCommonCrypto. IMPORTANT NOTE: This release is NOT entirely source code compatible

Kitura 183 Oct 15, 2022
Swift cross-platform crypto library using CommonCrypto/libcrypto

BlueCryptor Swift cross-platform crypto library derived from IDZSwiftCommonCrypto. IMPORTANT NOTE: This release is NOT entirely source code compatible

Kitura 183 Oct 15, 2022
A library for make a beautiful Passcode Lock View

SmileLock A library for make a beautiful Passcode Lock View, also support Touch ID. Requirements iOS 9.0+ Swift 4 (pod version 3.x), Swift 3 (pod vers

Recruit Lifestyle Co. Ltd. 607 Sep 18, 2022
SVPinView is a light-weight customisable library used for accepting pin numbers or one-time passwords.

SVPinView SVPinView is a light-weight customisable library used for accepting pin numbers or one-time passwords. Getting Started An example project is

Srinivas Vemuri 246 Jan 4, 2023
iOS library for device fingerprinting. Does not require server APIs to work, fully client-side operation.

Lightweight iOS library for local device fingerprinting Installation (CocoaPods) # Podfile pod 'FingerprintJS' Note: If you've never used CocoaPods fo

FingerprintJS 45 Dec 17, 2022