[英]Do not restore passwords inserted in iOS Keychain issue
I'm developing an application for an iPad2 that needs to write some items in Keychain but I don't want it replicates in every computer I plug, doing a backup/restore of the device. 我正在为iPad2开发一个应用程序,该应用程序需要在“钥匙串”中编写一些项目,但我不希望它在插入的每台计算机中都进行复制,而是对设备进行备份/还原。 I'm using kSecAttrAccessible key to select the kind of accesibility I want with kSecAttrAccessibleWhenUnlockedThisDeviceOnly value to be sure that if I do a backup of all things that are in the device, the Keychain is not going to be present in that backup. 我正在使用kSecAttrAccessible密钥来选择我想要的具有kSecAttrAccessibleWhenUnlockedThisDeviceOnly值的可访问性类型,以确保如果我对设备中的所有物品进行备份,则钥匙串将不会出现在该备份中。
So I proceed in this way: I reset the Keychain, insert a item in Keychain and dump all the content of Keychain, so I see that the item is there. 因此,我以这种方式进行操作:我重置了钥匙串,在钥匙串中插入了一个项目,然后转储了钥匙串的所有内容,因此我看到了该项目。 Then I do a backup of the iPad. 然后,我备份了iPad。 I reset the Keychain and restore the backup so no key should be in the Keychain as long as the restore procedure doesn't deal with the Keychain. 我重置了钥匙串并还原了备份,因此只要还原过程不处理钥匙串,钥匙串中就不应包含任何钥匙。 Next time I run the application, I dump the contents of the Keychain and the key is there, so it's not working as it should. 下次运行该应用程序时,我转储了钥匙串的内容,并且钥匙在那里,因此它无法正常工作。 I'm using iphone-lib (http://code.google.com/p/iphone-lib/) to dump and reset credentials in my iPad. 我正在使用iphone-lib(http://code.google.com/p/iphone-lib/)转储并重置iPad中的凭据。 My SDK version is 4.3. 我的SDK版本是4.3。
The code I use to insert the item in the Keychain is the following: 我用于在钥匙串中插入商品的代码如下:
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
NSData* identifier = [@"mypassword" dataUsingEncoding: NSASCIIStringEncoding];
[dic setObject:(id)kSecAttrAccessibleWhenUnlockedThisDeviceOnly forKey:(id)kSecAttrAccessible];
[dic setObject:identifier forKey:(id)kSecAttrGeneric];
[dic setObject:@"myaccount" forKey:(id)kSecAttrAccount];
[dic setObject:@"myservice" forKey:(id)kSecAttrService];
[dic setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[dic setObject:identifier forKey:(id)kSecValueData];
OSStatus error = SecItemAdd((CFDictionaryRef)dic, NULL);
Thank you! 谢谢!
kSecAttrAccessibleWhenUnlockedThisDeviceOnly maybe the reason. kSecAttrAccessibleWhenUnlockedThisDeviceOnly可能只是原因。
Can you try something else? 你可以尝试其他吗?
eg. 例如。 kSecAttrAccessibleWhenUnlocked kSecAttrAccessibleWhenUnlocked
There two cool examples (with working sample code) from Apple, that helped me to understand how keychain service works on iOS. 苹果公司有两个很棒的示例(带有有效的示例代码),它们帮助我了解了钥匙串服务在iOS上的工作方式。 I suggest you to look at them, and hope they will help you to resolve your issue: 我建议您研究一下它们,并希望它们能帮助您解决问题:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.