帮助在iPhone应用程序上实现钥匙串的有用实现 [英] help with a useful implementation of keychain on an iphone app

查看:96
本文介绍了帮助在iPhone应用程序上实现钥匙串的有用实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户已请求在我的iphone应用程序上进行锁定",因为它包含私人信息,因此很有意义.我认为数据加密超出了人们在手机上的预期,因此我的目标仅仅是防止意外访问该应用程序.我的计划是使用钥匙串将我的应用程序名称用作ServiceName来存储密码.

Users have requested a "lock" on my iphone app, which makes good sense as it contains private information. I believe encryption of the data goes above and beyond what people expect on a phone, so my goal is simply to prevent unintended access to the app. My plan is to use keychain to store the password using my app name as the ServiceName.

我担心的是,如果用户丢失/忘记了输入的密码,将会对用户产生什么影响?我可以通过编程方式做一些事情来允许用户重置吗?删除应用程序会删除该应用程序的钥匙串吗?

My concern is what happens for users if they lose/forget the password they typed in. Is there something I can do programatically to allow a user reset? Would deleting the app delete the keychain for the app?

我不想收集用户电子邮件. (我愿意,但是我不希望这成为正当理由.)而且,如果用户丢失了密码,也不要将其永久锁定在应用程序之外.

I don't want to collect user emails. (Well I do, but I don't want this to be the justification.) And don't want the user to be permanently locked out of the app if they've lost the passsword.

推荐答案

在iPhone上,只有一个钥匙串数据库,无法添加自定义的,特定于应用程序的钥匙串(就像在Mac上一样)反而).默认情况下,添加到应用程序钥匙串中的钥匙串项仅对您的应用程序可用.据我所知,没有文档说明用户删除您的应用程序时发生的行为:可能是iOS 4.1删除了应用程序的钥匙串项目,可能是确实将它们留在了钥匙串中.

On the iPhone there is just a single keychain database, and there is no possibility to add a custom, application specific, keychain (as you can do on a Mac instead). By default, the keychain items you add to the keychain in your app are only available to your app. There is no documentation (to the best of my knowledge) stating the behavior occurring when the user deletes your app: may be iOS 4.1 deletes the app keychain items, may be it does leave them in the keychain.

取决于您存储用户密码的方式,您也许可以检索它.例如,如果您在kSecAttrApplicationTag中存储了与应用程序相关的标签以及用户密码,则可以使用

Depending on how you stored the user's password, you may be able to retrieve it. For instance, if you stored a tag related to your application along with the user's password in a kSecAttrApplicationTag, then you may search for your exact tag in the keychain using the

OSStatus SecItemCopyMatching (
   CFDictionaryRef query,
   CFTypeRef *result
);

功能.如果搜索成功,则可以使用kSecValueData键从返回的字典中检索密码,或者,如果愿意,甚至可以使用

function. If the search is successful, then you may retrieve the password from the returned dictionary using the kSecValueData key or, if you prefer, you can even change it using

OSStatus SecItemUpdate (
   CFDictionaryRef query,
   CFDictionaryRef attributesToUpdate
);

有关其他信息,请参见钥匙串参考

For additional information, see the keychain reference and the Keychain Services Tasks for iOS documentation.

这篇关于帮助在iPhone应用程序上实现钥匙串的有用实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆