我是 iOS 的新手,正在开发一个应用程序,我需要在其中基于从 API 端点返回的 token 来维护 session 。我搜索了一下,发现安全数据不应存储在用户默认值中,因此我选择了钥匙串(keychain)。我的问题是:
- Keychain 是否足够安全?
- 还有其他好的选择吗?
- Keychain 是否在加密后存储值(默认行为)?
- 如果不是,那么将加密/解密与钥匙串(keychain)一起使用的正确方法是什么?
目前我用到的Keychain相关命令如下:
import SwiftKeychainWrapper //installed through Cocoapods
//Storing
let saveTokenSuccessful: Bool = KeychainWrapper.standard.set(token!, forKey: "myToken")
//Retrieving
let retrievedToken: String? = KeychainWrapper.standard.string(forKey: "myToken")
//Deleting
let removeTokenSuccessful: Bool = KeychainWrapper.standard.remove(key: "myToken")
最佳答案
Is Keychain secure enough?
我会这样说,可能取决于您数据的敏感性。
Does Keychain store values after encrypting them (default behaviour)?
来自文档:
The encryption is AES 128 in GCM(Galois/Counter Mode)
Apple 过去发布了一篇关于 iOS 安全性的论文,这可能是一个很好的起点。你可以找到它here .
有关 keychains 的更多信息.
关于ios - 在 iOS 中保护数据。钥匙串(keychain)或任何其他方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47052642/