Clear Keychain for iPhone

Is there a way to clear the keyring for my iphone application? Either a cleanup command or a list of all keys, so I can delete them myself.

+4
source share
1 answer

There is no command like the purge command.
One way or another, since the keychain to which your application has access is intended only for your application, you can easily track what you wrote in it and delete it.

You can implement your own cleaning method, which will simply delete one after another all possible data types that you can store in the keychain. The following describes how I clear all GenericPassword entries:

- (BOOL)deleteKeychainData { /* delete custom data */ NSMutableDictionary *searchData = [NSMutableDictionary new]; [searchData setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; [searchData setObject:kTagKeychainService forKey:(id)kSecAttrService]; OSStatus statusData = SecItemDelete((CFDictionaryRef)searchData); [searchData release]; CHECK_CONDITION1(statusData == errSecSuccess || statusData == errSecItemNotFound, @"Error while deleting keychain data, OSStatus == %d", statusData); /* delete assymetric keys*/ return [self deleteKeyPair]; } 

So what you need to do is call this method for all possible kSecClass values.
NOTE that different data types require different dictionary flags to be set.

considers

+9
source

Source: https://habr.com/ru/post/1311114/


All Articles