OGeek|极客世界-中国程序员成长平台

标题: ios - 将加密 key 存储在 defaultConfiguration 中是否安全? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:17
标题: ios - 将加密 key 存储在 defaultConfiguration 中是否安全?

我的 Realm 数据库已加密。加密 key 存储在钥匙串(keychain)中。管理此 key 的更安全方法是什么?

目前我正在调用从 application(application:didFinishLaunchingWithOptions 设置 defaultConfiguration(schemaVersion、migrationBlock、fileURL 等和 encryptionKey)的方法,然后实例化任何 Realms。稍后,Realms 在整个应用程序中使用此 defaultConfiguration 实例化。 像这样:

// AppDelegate
   var config = Realm.Configuration.defaultConfiguration
   config.schemaVersion = 5
   config.migrationBlock = { migration, oldSchemaVersion in ... }
   config.encryptionKey = KeychainManager.getRealmEncryptionKey()
   Realm.Configuration.defaultConfiguration = config

// Somewhere else, later
   Realm()

将 encryptionKey 放入 defaultConfiguration 是否安全?运行时 defaultConfiguration 存储在哪里,从中提取 key 有多容易?

或者更好的方法是在每个 Realm 实例化时从 Keychain 请求加密 key 并将其放入自定义配置中,该配置仅在 Realm 实例的生命周期内出现在内存中?像这样:

// AppDelegate
   var config = Realm.Configuration.defaultConfiguration
   config.schemaVersion = 5
   config.migrationBlock = { migration, oldSchemaVersion in ... }
   Realm.Configuration.defaultConfiguration = config

// Somewhere else, later
   var configTemp = Realm.Configuration.defaultConfiguration
   configTemp.encryptionKey = KeychainManager.getRealmEncryptionKey()
   Realm(configuration: configTemp)



Best Answer-推荐答案


Is it safe to put encryptionKey into defaultConfiguration? Where is defaultConfiguration stored at runtime and how easy will it be to extrude key from it?

key 存储在 Realm 配置的内存中。如果您想知道一个单独的进程突破 iOS 沙箱的可能性有多大,请检查您的应用程序的内存并从中提取 key ……假设这将是对最高操作系统的利用学位和苹果将面临公关灾难。

所以说真的,你应该做对你最方便的事情。只要您不将加密 key 以明文形式保存在磁盘上,您就会尽可能地安全。

关于ios - 将加密 key 存储在 defaultConfiguration 中是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40991523/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4