ioskeychainkeychainitemwrapper

Keychain Wrapper erminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSZeroData _fastCharacterContents]


I am using the keychain wrapper found here:

https://gist.github.com/1170641

Like this:

.h :

    #import "KeychainItemWrapper.h"

    KeychainItemWrapper *keychainItem;

.m:

 keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"login" accessGroup:nil];

NSString *password = [keychainItem objectForKey:(__bridge id)kSecValueData];
NSString *username = [keychainItem objectForKey:(__bridge id)kSecAttrAccount];

Then it crashes with:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSZeroData _fastCharacterContents]: unrecognized selector sent to instance 0x14dcba60'

EDIT:

The crash is no longer present thanks to a user who answered the question but when I retrieve the username or password they are sometimes swaped and I mean 80% of the time.


Solution

  • Edit: I'm using kSecValueData but commented out //#define PASSWORD_USES_DATA in KeychainItemWrapper.m. Also I started using resetKeychainItem instead of trying to override the values myself.

    Old Answer: I had this issue until I changed kSecValueData to kSecAttrService, which can be used for passwords also according to SecItem.h. Now everything seems to work fine (setting and retrieving).