Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As all of the answers so far relies on that you know the identifiers you want to delete I would like to submit the following solution that <strong>deletes ALL existing keys</strong> for the app (iOS only)</p> <pre><code>-(void)resetKeychain { [self deleteAllKeysForSecClass:kSecClassGenericPassword]; [self deleteAllKeysForSecClass:kSecClassInternetPassword]; [self deleteAllKeysForSecClass:kSecClassCertificate]; [self deleteAllKeysForSecClass:kSecClassKey]; [self deleteAllKeysForSecClass:kSecClassIdentity]; } -(void)deleteAllKeysForSecClass:(CFTypeRef)secClass { NSMutableDictionary* dict = [NSMutableDictionary dictionary]; [dict setObject:(__bridge id)secClass forKey:(__bridge id)kSecClass]; OSStatus result = SecItemDelete((__bridge CFDictionaryRef) dict); NSAssert(result == noErr || result == errSecItemNotFound, @"Error deleting keychain data (%ld)", result); } </code></pre> <p><strong>Swift 2.2</strong> version:</p> <pre><code>func resetKeychain() { self.deleteAllKeysForSecClass(kSecClassGenericPassword) self.deleteAllKeysForSecClass(kSecClassInternetPassword) self.deleteAllKeysForSecClass(kSecClassCertificate) self.deleteAllKeysForSecClass(kSecClassKey) self.deleteAllKeysForSecClass(kSecClassIdentity) } func deleteAllKeysForSecClass(secClass: CFTypeRef) { let dict: [NSString : AnyObject] = [kSecClass : secClass] let result = SecItemDelete(dict) assert(result == noErr || result == errSecItemNotFound, "Error deleting keychain data (\(result))") } </code></pre> <p><strong>Swift 3</strong> version</p> <pre><code>func resetKeychain() { deleteAllKeysForSecClass(kSecClassGenericPassword) deleteAllKeysForSecClass(kSecClassInternetPassword) deleteAllKeysForSecClass(kSecClassCertificate) deleteAllKeysForSecClass(kSecClassKey) deleteAllKeysForSecClass(kSecClassIdentity) } func deleteAllKeysForSecClass(_ secClass: CFTypeRef) { let dict: [NSString : Any] = [kSecClass : secClass] let result = SecItemDelete(dict as CFDictionary) assert(result == noErr || result == errSecItemNotFound, "Error deleting keychain data (\(result))") } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload