sskeychain

Introduction

sskeychain is a simple library for accessing the keychain on iOS and macOS. It provides a convenient and secure way to store sensitive information such as passwords, tokens, or cryptographic keys.

Features

  • Easy integration into iOS and macOS projects
  • Securely store and retrieve sensitive information
  • Simple and intuitive API
  • Supports keychain management for multiple accounts
  • Highly customizable with various configuration options

Installation

To integrate sskeychain into your iOS or macOS project, you can choose one of the following methods:

  1. Using Cocoapods:
  2. Add the following line to your Podfile:

    pod 'SSKeychain'
  3. Manually:
  4. Download the latest release and manually include the files in your project.

Usage

Once you have integrated sskeychain into your project, you can start using it to store and retrieve sensitive information.

Storing a Password

To store a password in the keychain, use the following method:

// Swift
SSKeychain.setPassword("myPassword", forService: "MyApp", account: "user123")

// Objective-C
[SSKeychain setPassword:@"myPassword" forService:@"MyApp" account:@"user123"];

Retrieving a Password

To retrieve a stored password, use the following method:

// Swift
let password = SSKeychain.password(forService: "MyApp", account: "user123")

// Objective-C
NSString *password = [SSKeychain passwordForService:@"MyApp" account:@"user123"];

Deleting a Password

If you want to delete a previously stored password, use the following method:

// Swift
SSKeychain.deletePassword(forService: "MyApp", account: "user123")

// Objective-C
[SSKeychain deletePasswordForService:@"MyApp" account:@"user123"];

Configuring Access Control

You can configure access control options for the stored password by using the setAccessControlList(_:keychainQuery:) method:

// Swift
let accessControlList = SSKeychainAccessControlList().addAccessControl(.userPresence)
SSKeychain.setAccessControlList(accessControlList, keychainQuery: ["service": "MyApp", "account": "user123"])

// Objective-C
SSKeychainAccessControlList *accessControlList = [[SSKeychainAccessControlList new] addAccessControl:SSKeychainAccessControl.userPresence];
[SSKeychain setAccessControlList:accessControlList keychainQuery:@{ @"service": @"MyApp", @"account": @"user123" }];

More Information

For additional details on how to use the sskeychain library, you can refer to the official GitHub repository.

Conclusion

sskeychain is a reliable and easy-to-use library for securely storing sensitive information in the keychain. It provides a robust set of features and a simple API, making it a preferred choice for iOS and macOS developers.