Keychain Manager
Keychain Manager is a Layer-2 framework built over Keychain API which helps in using Keychain in all your Apple devices with easiness and flexibility. It focuses on using all the power of Keychain with high simplicity. The easy to use methods of Keychain Manager helps to setup Keychain on any Apple device with great convenience.
đ Usage
âī¸ Intilisation
Before using any Keychain Manager methods we need to intialise the class. Keychain Manager supports various types of inilisation which depends upon variety of use cases
đŗ Basic Initialisation
- This initilisation stores all the Keychain items on the local device.
- Such initilisations are best used when the app is single login based.
let KCM = KeychainManager()
đŗ Prefix Initiliser
- This initiliser helps to add a prefix value in your account string.
- Such initilisations are best used when performing tests (Eg: test_account1_).
let KCM = KeychainManager(keyPrefix: "test")
đŗ Sharable Initiliser
- Keychain Manger allowes developers to share the keychain values to other apps also synchronise with iCloud.
- Such initilisations are best used when you need to share Keychain values among apps.
- Eg: A same app running on two different devices with same iCloudID & To share data between Different apps running on same or different device
let KCM = KeychainManager(accessGroup: "TeamID.KeychainGroupID", synchronizable: true)
đŗ Prefix + Sharable
- When you need to add both prefix and sharable propert on keychain then this initialisation is the best one to use
let KCM = KeychainManager(keyPrefix: "test", accessGroup: "TeamID.KeychainGroupID", synchronizable: true)
đ Operations
Following are the methods which help to perfrom various operations:
đ SET
- Used to save data on keychain.
- Keychain Manager Supports variety of data storage
String
KCM.set(value: "value", service: service_ID, account: account_name)
Bool
KCM.set(value: true, service: service_ID, account: account_name)
Custom Object
KCM.set(object: Any_Codable_Object, service: service_ID, account: account_name)
Web Credentials
KCM.set(server: server_ID, account: account_name, password: password)
Tip: Make sure Account, Service & Server parameter must be unique for every item.
đ GET
- Used to get Keychain Items.
- Keychain Manager helps to GET variety of format of Data from Keychain Storage
String
let value = KCM.get(service: service_ID, account: account_name)
Bool
let value = KCM.getBool(service: service_ID, account: account_name)
Custom Object
let value = KCM.get(object: Any_Codable_Object, service: service_ID, account: account_name)
Web Credentials
let value = KCM.get(server: server_ID, account: account_name)
Get All Values
- Generic Password
let value = KCM.getAllValues(secClass: .genericPassword)
- Web Credentials
let value = KCM.getAllValues(secClass: .webCredentials)
đ UPDATE
- Used to update Kechain Item Values
- Since we have variety of SET and GET methods, similarly to update them we have variety of UPDATE methods
String
KCM.update(value: "value", service: service_ID, account: account_name)
Bool
KCM.update(value: true, service: service_ID, account: account_name)
Custom Object
KCM.update(object: Any_Codable_Object, service: service_ID, account: account_name)
Web Credentials
KCM.update(server: server_ID, account: account_name, password: password)
đ DELETE
- Used to delete Keychain Items
Service Deletion
do {
try KCMTest.delete(service: service_ID, isCustomObjectType: false)
}
catch {
print(error.localizedDescription)
}
- isCustomObjectType is used to explicitly tell Keychain Manager to delete a custom Object type.
- By default the value of isCustomObjectType is
false
Server Deletion
do {
try KCMTest.delete(server: server_ID)
}
catch {
print(error.localizedDescription)
}
đ VALIDATE
- Is used to check if a certain Server or Service based keychain is valid/present.
Service
if KCM.isValidService(service: service_ID, account: account_name) {
print("đ")
} else {
print("âšī¸")
}
Server
if KCM.isValidService(server: server_ID, account: account_name) {
print("đ")
} else {
print("âšī¸")
}
âī¸ iCloud Sync
- iCloud synchronisation needs to be set during initilisation.
- Make sure to use the sharable initialisation at every method to save all changes on cloud.
đą Device Supported
| No | Device | Version |
| â | â | â |
| 1 | iOS | 13.0.0 + |
| 2 | iPadOS | 13.0.0 + |
| 3 | WatchOS | 6.0.0 +|
| 4 | MacOS | 11.0.0 + |
| 5 | tvOS | 11.0.0 + |
đ Keynotes
Make sure you know these keynotes before using Keychain Manager
- GET Bool will return false even after deleting the Keychain item.
- To delete a custom object make sure you explicitly tell Keychain Manager that its a custom object in the delete method.
- By enabling iCloud sync you also enable Keychain Access Group, thus adding Keychain Sharing capability is important (How to do it?).
- Every Keychain item stored through MacOS is also saved in form of iOS, making it easy for developers to share same keychain data among all platforms. Thus keychain manager will give access to your MacOS based keychain items on other platforms too (Read this).
- Keychain Items stored on tvOS will not sync with other platforms (Read this).
đĻ SPM
Keychain Manger is available through Swift Package Manager. To add Keychain Manager through SPM
- Open project in Xcode
- Select
File > Add Packages
https://github.com/gokulnair2001/KeychainManager
đ Keychain Sharing
- Open your project target
- Select
Signing & Capabilities
option
- Click plus button and search for
Keychain Sharing
- Make sure to use the same Keychain Item in other apps you add the Keychain access group ID of the initial project.
đĒ How to contribute ?
- Use the framework through SPM
- If you face issues in any step open a new issue.
- To fix issues: Fork this repository, make your changes and make a Pull Request.
âī¸ License
- Keychain Manager is available under GNU General Public License.
Like the framework ?
- If you liked
Keychain Manager
do consider buying me a coffee đ
Made with â¤ī¸ in đŽđŗ By Gokul Nair