使用 NSUserDefault 保存用户名密码,如何以及安全程度如何?
我会用 NSUserDefault 保存几个值(用户名-密码)。
第一:有没有办法将它们保存在一起(例如在数组中)? 第二:安全吗?或者我是否以某种方式加密了密码?
I would save a couple of values (username-password) with NSUserDefault.
First: is there a way to save them together (like in an array for example)?
Second: is it safe? or do I have encrypt the password in a some way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
加密将为您提供一定的安全性。问题是你的程序还必须解密密码,这意味着它必须将密钥存储在某个地方。这将使其容易受到逆向工程的影响。更好的方法是对密码使用单向函数(例如哈希)存储该哈希值。当用户输入密码时,您可以对密码应用单向函数,并将结果与存储的值进行比较。通过这种方式,密码不会被泄露(好吧,总是存在字典攻击,但这是密码强度的问题)。
不要使用 NSUserDefaults,您最好使用 iOS 钥匙串服务。它的主要目的是安全地存储用户凭据。 Apple 已经为您完成了所有艰苦的工作。利用它。
Encryption will give you some security. The problem is your program would also have to decrypt the password, which means it must have the key stored in it somewhere. This will make it vulnerable to reverse-engineering. A better approach is to use an one-way function (such as a hash) on the password and store that hash value. When a user enters a password, you then apply the one-way function to the password and compare the result to the stored value. In this manner, the password cannot be compromised (well, there's always a dictionary attack, but that's a matter of password strength).
Instead of using NSUserDefaults, you would be better off using iOS Keychain Services. It's main purpose is to securely store user credentials. Apple has already done all the hard work for you. Take advantage of it.
不,这不安全。
如果您需要安全地存储数据,请使用 钥匙扣。
No. It's not safe.
If you need to store data securely, use the keychain.
你可以使用 NSDictionary 或 NSarray 来保存你的值,你还应该加密你的数据,因为 NSUserDefaults 的工作方式就像一个任何人都可以访问的 plist
you can use an NSDictionary or NSarray to save your values, and you should also encrypt your data because NSUserDefaults works like a plist which can be accessed by anyone
这个易于使用,可与 ARC 配合使用
This one is easy to use, works with ARC