使用访问组时如何从私有钥匙串中删除iOS钥匙串项目?

问题描述 投票:0回答:1

我在 iOS 上使用 Keychain 来存储一些数据。 该应用程序有权通过访问组访问

group.com.mycompany
。 我已在应用程序的私有钥匙串容器中的密钥
my_item_key
下添加了钥匙串项目,并在共享钥匙串容器中创建了一个条目(通过访问组)。 如果我尝试从私有钥匙串中读取
my_item_key
密钥,则返回私有密钥的值,如果我尝试从共享访问组钥匙串中读取
my_item_key
,它会返回存储在共享访问组下的正确值。一个。

但是,如果我尝试删除私有钥匙串中带有密钥

my_item_key
的项目,它也会删除共享容器中的钥匙串项目,尽管我没有指定访问组。 在不指定访问组的情况下删除:

let query: NSMutableDictionary = [ kSecClass as String: kSecClassGenericPassword, kSecAttrAccount as String: "my_item_key", kSecAttrService as String: "com.mycompany.appOne", ] let status = SecItemDelete(query) print("delete status: \(status)") // deletes keychain item from app private keychain and shared keychain. // even without specifying kSecAttrAccessGroup

这可能吗?或者删除意味着从两个容器中删除,我必须使用不同的 
kSecAttrAccount

键?

    

ios swift keychain
1个回答
0
投票
SecItemDelete

的字典是一个查询;它会搜索匹配的项目并删除它们。

您可以在查询字典中使用 

kSecUseKeychain

 来指定应搜索哪个钥匙串。
如果没有这个,将搜索所有可访问的钥匙串。

© www.soinside.com 2019 - 2024. All rights reserved.