简体   繁体   English

不还原在iOS钥匙串问题中插入的密码

[英]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: 我建议您研究一下它们,并希望它们能帮助您解决问题:

  1. Generic Keychain : This sample shows how to add, query for, remove, and update a keychain item of generic class type. 通用钥匙串此示例演示如何添加,查询,删除和更新通用类类型的钥匙串项。 Also demonstrates the use of shared keychain items. 还演示了共享钥匙串项的使用。 All classes exhibit very similar behavior so the included examples will scale to the other classes of Keychain Item: Internet Password, Certificate, Key, and Identity. 所有类都表现出非常相似的行为,因此所包含的示例将扩展到“钥匙串项目”的其他类:Internet密码,证书,密钥和身份。
  2. AdvancedURLConnections : This sample demonstrates various advanced networking techniques with NSURLConnection. AdvancedURLConnections此样本演示了NSURLConnection的各种高级联网技术。 Specifically, it demonstrates how to respond to authentication challenges, how to modify the default server trust evaluation (for example, to support a server with a self-signed certificate), and how to provide client identities. 具体来说,它演示了如何响应身份验证挑战,如何修改默认服务器信任评估(例如,使用自签名证书支持服务器)以及如何提供客户端身份。

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

相关问题 钥匙串访问 iOS 问题 - Keychain Access iOS Issue iOS从钥匙串中恢复登录框中的密码 - iOS restore password in login box from keychain 我可以在iOS钥匙串中为一个用户存储/检索多个密码吗? - Can I store/ retrieve multiple passwords in the iOS keychain for a single user? 如何使用iOS钥匙串存储多个用户名和密码? - How can I store multiple usernames and passwords with the iOS keychain? iOS 恢复 state 问题 - iOS restore state issue ios钥匙串适合我的IAP问题吗? - Is ios Keychain suitable for my IAP issue? 当应用程序被沙盒化时,为什么 Apple 建议将密码、机密和密钥存储在 iOS Keychain 中? - Why does Apple recommend to store passwords, secrets, and keys in iOS Keychain when apps are sandboxed? ios10的钥匙串访问中的“找不到商品”问题 - “Item not found” issue in keychain Access in ios10 ios swift parse:保存到钥匙串并从钥匙串打印出数据并进行登录 - ios swift parse: Saving to keychain and print out data from keychain and do a login 原始和升级iOS应用程序具有相同的钥匙串和应用程序身份,但升级应用程序无法解密由原始应用程序加密的密码 - Original and upgrade iOS apps have same keychain and application identities, but upgrade app cannot decrypt passwords encrypted by original app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM