What Is EMKeychain?
EMKeychain is a Cocoa wrapper class for Keychain, which has unfortunately been frozen in carbonite. It's much cleaner than interfacing with keychain yourself.
How Advanced Is EMKeychain?
It's usable in what we expect to be most scenarios. It's very basic right now considering the girth of Keychain itself, so we'll be evolving it with time as necessary. We recommend you check out the class overview to properly see if you should use EMKeychain in your project.
Usage
Adding a generic keychain item
[[EMKeychainProxy sharedProxy] addGenericKeychainItemForService:@"SomeApplicationService" withUsername:@"Joe" password:@"SuperSecure!"];
Adding an internet keychain item
[[EMKeychainProxy sharedProxy] addInternetKeychainItemForServer:@"apple.com" withUsername:@"sjobs" password:@"magic" path:@"/httpdocs/" port:21 protocol:kSecProtocolTypeFTP];
Note that the "protocol" asks for a SecProtocolType.
Working with a keychain item
EMInternetKeychainItem *keychainItem = [[EMKeychainProxy sharedProxy] internetKeychainItemForServer:@"apple.com" withUsername:@"sjobs" path:@"/httpdocs" port:21 protocol:kSecProtocolTypeFTP];
//Get the password
NSString *password = [keychainItem password];
//Change the password and user
[keychainItem setPassword:@"mynewpass"];
[keychainItem setUsername:@"phil"];
Class Overview
- EMKeychainProxy
- A singleton your application will speak with to get EMKeychainItems and add new keychain items.
- Basic Methods
- + (id)sharedProxy;
- - (void)lockKeychain;
- - (void)unlockKeychain;
- Getting a Keychain item
- - (EMGenericKeychainItem *)genericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString;
- - (EMInternetKeychainItem *)internetKeychainItemForServer:(NSString *)serverString withUsername:(NSString *)usernameString path:(NSString *)pathString port:(int)port protocol:(SecProtocolType)protocol;
- Adding a new keychain item
- - (EMGenericKeychainItem *)addGenericKeychainItemForService:(NSString *)serviceNameString withUsername:(NSString *)usernameString password:(NSString *)passwordString;
- - (EMInternetKeychainItem *)addInternetKeychainItemForServer:(NSString *)serverString withUsername:(NSString *)usernameString password:(NSString *)passwordString path:(NSString *)pathString port:(int)port protocol:(SecProtocolType)protocol;
- EMKeychainItem
- A container object that houses information about your keychain item, and provides modification functionality.
- Getters
- - (NSString *)password;
- - (NSString *)username;
- - (NSString *)label;
- Setters
- - (BOOL)setPassword:(NSString *)newPassword;
- - (BOOL)setUsername:(NSString *)newUsername;
- - (BOOL)setLabel:(NSString *)newLabel;
- Subclasses
- EMGenericKeychainItem
- Getters
- - (NSString *)serviceName;
- Setter Methods
- - (BOOL)setServiceName:(NSString *)newServiceName;
- EMInternetKeychainItem
- Getters
- - (NSString *)server;
- - (NSString *)path;
- - (int)port;
- - (SecProtocolType)protocol;
- Setters
- - (BOOL)setServer:(NSString *)newServer;
- - (BOOL)setPath:(NSString *)newPath;
- - (BOOL)setPort:(int)newPort;
- - (BOOL)setProtocol:(SecProtocolType)newProtocol;