iOS 8,9 上的 NSUserDefaults 有多安全?

How secure is NSUserDefaults on iOS 8,9?

In-App Purchase Programming Guide 建议您可以在 NSUserDefaults here. However I found this article 中坚持 In-App purchase 说它不安全并且其中的数据很容易访问和修改:

NSUserDefaults are stored in plist in binary format, with no encryption, and is stored in your app’s directory. This means that any user, even the “noobiest” one, can tinker with your NSUserDefaults with 5 minutes of their time.

如果这是真的,用户可以轻松免费获得使用 NSUserDefaults.

持续提供的任何作为应用内购买提供的内容

这篇文章对于 iOS 8,9 是否仍然正确? 如果是这样,您如何坚持您的应用内购买?我更喜欢一些简单的解决方案。我不(也不想)验证收据等

强烈建议不要在 UserDefaults 中保存敏感数据,例如应用内购买或密码等明显的数据。即使像高分这样的数据也最好保存在钥匙串中,这样人们就不会作弊。

我认为部分 Apple 文档已经过时并且应该更改,因为 UserDefaults 不是存储敏感数据的方式,在应用程序购买中肯定是 IMO。

只需在 UserDefaults 中保存基本数据,如语言设置、音频设置等

如果您想保存敏感数据,您应该使用钥匙串。我认为钥匙串 API 使用起来相当棘手,但是 GitHub 上有一个很好的帮助你可以使用,它支持 CocoaPods 和 SwiftPackageManager 并且由其作者积极维护。

https://github.com/kishikawakatsumi/KeychainAccess

还有 2 个我曾经使用过的项目,不幸的是它们似乎不再受支持

https://github.com/jrendel/SwiftKeychainWrapper

https://github.com/matthewpalmer/Locksmith

使用钥匙串要记住的一件事是,即使您删除了您的应用程序,数据仍然存在,我认为这是一件好事。

所有功劳归功于各自包装的作者。

希望对您有所帮助