Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Simple Objective-C wrapper for the keychain that works on Mac and iOS

branch: master

This branch is 0 commits ahead and 0 commits behind master

Merge pull request #10 from jparise/header-comments

Improving some header file comment blocks.
latest commit e3736a3581
Sam Soffes soffes authored
Octocat-spinner-32 Tests Version 0.1.3 May 08, 2012
Octocat-spinner-32 .gitignore Version 0.1.2 October 18, 2011
Octocat-spinner-32 Changelog.markdown Version 0.1.3 May 08, 2012
Octocat-spinner-32 LICENSE Bump license year and add podspec June 02, 2012
Octocat-spinner-32 Rakefile Updated readme October 18, 2011
Octocat-spinner-32 Readme.markdown Version 0.1.3 May 08, 2012
Octocat-spinner-32 SSKeychain.h Improving some header file comment blocks. September 03, 2012
Octocat-spinner-32 SSKeychain.m Fix ARC issues May 09, 2012
Octocat-spinner-32 SSKeychain.podspec Bump license year and add podspec June 02, 2012
Octocat-spinner-32 VERSION Bump license year and add podspec June 02, 2012


SSKeychain is a simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system Keychain on Mac OS X and iOS. SSKeychain works in ARC and non-ARC projects.

This was originally inspired by EMKeychain and SDKeychain (both of which are now gone). Thanks to the authors. SSKeychain has since switched to a simpler implementation that was abstracted from SSToolkit.

Adding to your project

  1. Add Security.framework to your target
  2. Add SSKeychain.h and SSKeychain.m to your project.

You don't need to do anything regarding ARC. SSKeychain will detect if you're not using ARC and add the required memory management code.

Note: Currently SSKeychain does not support Mac OS 10.6.

Working with the keychain

SSKeychain has the following class methods for working with the system keychain:

+ (NSArray *)allAccounts;
+ (NSArray *)accountsForService:(NSString *)serviceName;
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account;
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account;
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account;

Easy as that. (See SSKeychain.h for all of the methods.)


Install the documentation into Xcode with the following steps:

  1. Open Xcode Preferences
  2. Choose Downloads
  3. Choose the Documentation tab
  4. Click the plus button in the bottom right and enter the following URL:
  5. Click Install next the new row reading "SSKeychain Documentation". (If you don't see it and didn't get an error, try restarting Xcode.)

Be sure you have the docset selected in the organizer to see results for SSKeychain.

You can also read the SSKeychain Documentation online.


If you saving to the keychain fails, you use the error codes provided in SSKeychain.h. Here's an example:

NSError *error = nil;
NSString *password = [SSKeychain passwordForService:@"MyService" account:@"samsoffes" error:&error];

if ([error code] == SSKeychainErrorNotFound) {
    NSLog(@"Password not found");

Obviously, you should do something more sophisticated. Working with the keychain is pretty sucky. You should really check for errors and failures. This library doesn't make it any more stable, it just wraps up all of the annoying C APIs.

Something went wrong with that request. Please try again.