Platformsios 5.0, osx 10.7, watchos 2.0, tvos 9.0, requires ARC

Build Status
Coverage Status
Carthage Compatible
Pod Version
Pod Platform
Pod License
Readme Score

RGLockbox is a simple to use interface with the standard keychain. Using object-orientented approaches it is simple to pick a key and store any rudimentary value there.

Default supported types include:

  • NSData
  • NSString
  • NSDate
  • NSDictionary
  • NSArray
  • id<NSCoding>
    • NSURL
    • NSValue (including NSNumber and NSDecimalNumber)
    • NSNull

Note for safety Apple encourages developers to conform their objects to NSSecureCoding instead of NSCoding to prevent substitution attacks against your app.


NSData* data = [@"abcd" dataWithEncoding:NSUTF8StringEncoding];
RGLockbox* lockbox = [RGLockbox manager];
[lockbox setData:data forKey:@"myData"];

Writing data is as simple as creating it and applying it to your keychain manager. By default these managers are namespaced to your bundle’s identifier.

RGLockbox* lockbox = [RGLockbox manager];
NSData* data = [lockbox dataForKey:@"myData"];
NSString* string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
assert([string isEqual:@"abcd"]);

Retrieving data is as simple as remembering your key assuming you use the same manager throughout. Mixing and matching managers with different namespaces is possible, but more of an advanced use case.

In addition to the primitive interface supporting reading and writing raw NSData there is implicit support for a variety of types.

NSDate* date = [NSDate new];
RGLockbox* lockbox = [RGLockbox manager];
[lockbox setDate:date forKey:@"myDate"];
NSDate* readDate = [lockbox dateForKey:@"myDate"];
assert([readDate timeIntervalSince1970] == [date timeIntervalSince1970]);


NSString* string = @"aString";
RGLockbox* lockbox = [RGLockbox manager];
[lockbox setString:string forKey:@"stringKey"];
NSString* readString = [lockbox stringForKey:@"stringKey"];
assert([readString isEqual:string]);


NSDictionary* dictionary = @{ @"aKey" : @"aValue" };
RGLockbox* lockbox = [RGLockbox manager];
[lockbox setJSONObject:dictionary forKey:@"dictionaryKey"];
NSDictionary* readDictionary = [lockbox JSONObjectForKey:@"dictionaryKey"];
assert([readDictionary isEqual:dictionary]);


NSArray* array = @[ @"aValue1", @"aValue2" ];
RGLockbox* lockbox = [RGLockbox manager];
[lockbox setJSONObject:array forKey:@"arrayKey"];
NSArray* readArray = [lockbox JSONObjectForKey:@"arrayKey"];
assert([readArray isEqual:array]);


NSURL* url = [NSURL];
RGLockbox* lockbox = [RGLockbox manager];
[lockbox setCodeable:url forKey:@"urlKey"];
NSURL* readURL = [lockbox codeableForKey:@"urlKey"];
assert([readURL isEqual:url]);

Finally, this library supports arbitrary namespacing which allows sharing keychain data across app bundles as well as setting different item accessibility for advanced use cases.

NSDate* signupDate = [NSDate dateWithTimeIntervalSince1970:1453075980.0];
RGLockbox* lockbox = [[RGLockbox alloc] initWithNamespace:@"com.rglockbox.appbundle" accessibility:kSecAttrAccessibleAlways];
[lockbox setDate:signup forKey:@"userSignupDate"];
/* In another program, app extension, component framework, etc. ... */RGLockbox* lockbox = [[RGLockbox alloc] initWithNamespace:@"com.rglockbox.appbundle" accessibility:kSecAttrAccessibleAlways];
NSDate* signupDate = [lockbox dateForKey:@"userSignupDate"];
assert([signupDate timeIntervalSince1970] == 1453075980.0);


Using cocoapods add pod 'RGLockbox' to your Podfile and run pod install


BSD Simplied (2-clause)

Latest podspec

    "name": "RGLockbox",
    "version": "1.2.0",
    "license": "BSD",
    "summary": "A simpler & faster keychain interface",
    "homepage": "",
    "authors": {
        "Ryan Dignard": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.2.0"
    "requires_arc": true,
    "platforms": {
        "ios": "5.0",
        "osx": "10.7",
        "watchos": "2.0",
        "tvos": "9.0"
    "public_header_files": "RGLockbox/*.h",
    "source_files": "RGLockbox",
    "frameworks": "Security"

Pin It on Pinterest

Share This