简体   繁体   English

正确的方法来删除(清除)iOS应用程序的所有钥匙串数据

[英]Correct way to remove(purge) all keychain data for an iOS app

I stored some information in the keychain, and there is a case that I need to remove all of the items, instead of doing [keychain removeObjectForKey:theKey] for all the keys, can I do: 我在钥匙串中存储了一些信息,有一种情况我需要删除所有项目,而不是为所有密钥执行[keychain removeObjectForKey:theKey] ,我可以这样做:

NSDictionary *spec = [NSDictionary dictionaryWithObjectsAndKeys:(id)kSecClassGenericPassword, kSecClass,
                      [self serviceName], kSecAttrService, nil];

return !SecItemDelete((CFDictionaryRef)spec);

instead? 代替?

I tried it and it worked, just not sure if I am doing the correct thing? 我尝试了它并且它有效,只是不确定我是否正在做正确的事情?

在我的应用程序中,我正在使用此行来清除我的钥匙串:

[[[KeychainItemWrapper alloc] initWithIdentifier:@"my_key" accessGroup:nil] resetKeychainItem]

I believe what you are doing is correct, in fact, you can avoid the kSecAttrService parameter in your query if you want. 我相信你所做的是正确的,事实上,你可以根据需要避免查询中的kSecAttrService参数。 On the other hand, the SecItemDelete returns a OSStatus value which you can check for more detailed information about the transaction. 另一方面,SecItemDelete返回OSStatus值,您可以检查该事务的更多详细信息。

    NSDictionary *spec = [NSDictionary dictionaryWithObjectsAndKeys:(id)kSecClassGenericPassword, kSecClass, nil];

    OSStatus status = SecItemDelete((CFDictionaryRef)spec);
    if (status == errSecSuccess)
       return YES;

    return NO;

Here are the codes and meanings for the possible status values 以下是可能的状态值的代码和含义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM