Skip to content
A simple Objective-C wrapper around common use cases for the iOS keychain
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

GSKeychain – a simple Objective-C wrapper around the iOS keychain

This project provides a simple, NSUserDefaults-style interface over the iOS keychain.

This is currently work in progress.

Sample usage

// Store a secret
[[GSKeychain systemKeychain] setSecret:@"t0ps3kr1t" forKey:@"myAccessToken"];

// Fetch a secret
NSString *secret = [[GSKeychain systemKeychain] secretForKey:@"myAccessToken"];

// Delete a secret
[[GSKeychain systemKeychain] removeSecretForKey:@"myAccessToken"];

// Delete all secrets
[[GSKeychain systemKeychain] removeAllSecrets];

Adding to your project

Drag and drop

  1. Drag GSKeychain.h and GSKeychain.m into your project
  2. Add Security.framework to Link Binary With Libraries in your target settings in Xcode
  3. import "GSKeychain.h" where appropriate

GSKeychain uses ARC. If your project doesn't use ARC you could enable it for these files, or use GSArchive as a static library instead.

As a static library

  1. Download the project and build it
  2. Drag libGSKeychain.a and GSKeychain.h into your project
  3. Add Security.framework to Link Binary With Libraries in your target settings in Xcode
  4. import "GSKeychain.h" where appropriate


Work inspired by reading Peeking Inside App Bundles by Nick Arnott.


Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License.

You're free to use this code in any project, including commercial. Please include the following text somewhere suitable, e.g. your app's About screen:

Uses GSKeychain by Simon Whitaker

Something went wrong with that request. Please try again.