I store shared passwords in the key chain after the Apple example code in the Key Key Programming Guide.
Everything works fine while I run the application in debug mode from Xcode. However, when I archive and export the application, it will still save passwords (visible in Keychain Access), but will not be able to recover them.
The key fob always returns errSecAuthFailed (-25293). This happens on Mountain Lion, but not on Snow Leopard. My application has code signed and isolated. It seems to me that when receiving a password, keychain does not recognize the application as the one that stores the password, because when I set a password to access any application, it also works well.
I am using the following code:
+ (NSString*) retrievePasswordFromKeychainWithKey: (NSString*) theKey { SecKeychainUnlock(NULL, 0, NULL, FALSE); const char* userNameUTF8 = [NSUserName() UTF8String]; uint32_t userNameLength = (uint32_t)strlen(userNameUTF8); uint32_t serviceNameLength = (uint32_t)strlen([theKey UTF8String]); uint32_t pwLength = 0; void* pwBuffer = nil; SecKeychainItemRef itemRef = nil; OSStatus status1 = SecKeychainFindGenericPassword (NULL, serviceNameLength, serviceNameUTF8, userNameLength, userNameUTF8, &pwLength, &pwBuffer, &itemRef); if (status1 == noErr) { NSData* pwData = [NSData dataWithBytes:pwBuffer length:pwLength]; SecKeychainItemFreeContent (NULL,
source share