Skip to content

Instantly share code, notes, and snippets.

@mattrubin
Created January 23, 2015 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrubin/dd2b43c0ad3f8acfc09b to your computer and use it in GitHub Desktop.
Save mattrubin/dd2b43c0ad3f8acfc09b to your computer and use it in GitHub Desktop.
Get every password in the keychain
+ (NSArray *)allKeychainItems
{
NSDictionary *queryDict = @{(__bridge id)kSecClass: (__bridge id)kSecClassGenericPassword,
(__bridge id)kSecMatchLimit: (__bridge id)kSecMatchLimitAll,
(__bridge id)kSecReturnPersistentRef: (id)kCFBooleanTrue,
(__bridge id)kSecReturnAttributes: (id)kCFBooleanTrue,
(__bridge id)kSecReturnData: (id)kCFBooleanTrue
};
CFTypeRef result = NULL;
OSStatus resultCode = SecItemCopyMatching((__bridge CFDictionaryRef)(queryDict),
&result);
if (resultCode != errSecSuccess) {
NSLog(@"Keychain result code: %d", (int)resultCode);
}
return (resultCode == errSecSuccess) ? (__bridge NSArray *)(result) : nil;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment