Introduction
MiniKeychain is a lightweight Swift framework for securely handling keychain operations in iOS apps. It provides a convenient wrapper around the Keychain Services API, making it easier to securely store sensitive information such as passwords, tokens, and other user data.
Features
- Simple and intuitive API for accessing keychain services
- Securely store and retrieve sensitive data
- Supports string, data, and arbitrarily sized objects
- Handles keychain item attributes such as accessibility, inclusive access groups, and more
- Supports keychain item deletion
- Well-documented codebase
- Compatible with iOS 11 and above
Installation
To integrate MiniKeychain into your iOS project, you can use one of the following methods:
Podfile:
target 'YourApp' do use_frameworks! pod 'MiniKeychain' end
Usage
To get started with MiniKeychain, follow the steps below:
1. Import the framework
Add the following import statement at the top of your Swift file:
Import Statement:
import MiniKeychain
2. Store data in the keychain
Use the following code snippet to securely store data in the keychain:
Storing Data:
let keychain = MiniKeychain() do { try keychain.set("mySecretPassword", forKey: "userPassword") } catch { // Handle error }
3. Retrieve data from the keychain
Use the following code snippet to retrieve data securely from the keychain:
Retrieving Data:
let keychain = MiniKeychain() do { if let password = try keychain.get("userPassword") { // Use the retrieved password } else { // No password found } } catch { // Handle error }
API Reference
MiniKeychain provides the following methods:
Method: set(_:forKey:)
Sets the value for the specified key in the keychain.
Signature:
func set(_ value: Any, forKey key: String, accessible: CFString = kSecAttrAccessibleWhenUnlocked) throws
Method: get(_:)
Retrieves the value for the specified key from the keychain.
Signature:
func get(_ key: String) throws -> Any?
Method: delete(_:)
Deletes the value for the specified key from the keychain.
Signature:
func delete(_ key: String) throws