How do you reset an iPhone App's Keychain?

前端 未结 4 1674
清酒与你
清酒与你 2020-12-13 06:44

I would like to know if there is a way to reset my app\'s Keychain. I am wondering whether anything like [NSUserDefaults resetStandardUserDefaults] exists for k

4条回答
  •  臣服心动
    2020-12-13 07:31

    Block-based version of Vegard’s solution:

    void (^deleteAllKeysForSecClass)(CFTypeRef) = ^(CFTypeRef secClass) {
        id dict = @{(__bridge id)kSecClass: (__bridge id)secClass};
        OSStatus result = SecItemDelete((__bridge CFDictionaryRef) dict);
        NSAssert(result == noErr || result == errSecItemNotFound, @"Error deleting keychain data (%d)", (int)result);
    };
    deleteAllKeysForSecClass(kSecClassGenericPassword);
    deleteAllKeysForSecClass(kSecClassInternetPassword);
    deleteAllKeysForSecClass(kSecClassCertificate);
    deleteAllKeysForSecClass(kSecClassKey);
    deleteAllKeysForSecClass(kSecClassIdentity);
    

    For those of us who like to just drop code in without having to have helper methods.

提交回复
热议问题