ioskeychainkeychainitemwrapper

How many keyChain can I store in iOS?


I'm using keychainWrapper. The keychain in ios stored using a pre-defined constant, which are these:

kSecAttrAccessGroup
kSecAttrCreationDate
kSecAttrModificationDate
kSecAttrDescription
kSecAttrComment
kSecAttrCreator
kSecAttrType
kSecAttrLabel
kSecAttrIsInvisible
kSecAttrIsNegative
kSecAttrAccount
kSecAttrService
kSecAttrGeneric

Does that mean I have restricted number of keychain I can use? I once used a custom key, and it doesn't work:

KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:[[NSBundle mainBundle] bundleIdentifier] accessGroup:nil];
[keychain setObject:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:@"myUDID"];

But this does:

[keychain setObject:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forKey:(__bridge NSString *)kSecValueData];

So, is there anyway for me to save many keychain? Can I to init my keychain with a different identifier to get save more keychain? Like this:

anotherKeychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"TestUDID" accessGroup:nil];
[anotherKeychain setObject:udid forKey:(__bridge id)(kSecAttrAccount)];

How to store a string in KeyChain , iOS?


Solution

  • You can have any number of keychain items (what you are referring to as key chains are actually keychain items). Each item only has a limited number of attributes defined - you have listed these. The identifier is whatever string you like and the data is the value you want to store against that item.

    There are also a number of frameworks you can use to simplify things - http://cocoapods.org/?q=Keychain