gpt4 book ai didi

ios - iOS 上的 Realm 是否默认加密

转载 作者:可可西里 更新时间:2023-11-01 06:24:08 24 4
gpt4 key购买 nike

我无法确定 Realm 在 iOS 上是否默认加密。谁能帮我理解一下?

最佳答案

来自关于 的 Realm 文档部分 Using Realm with Background App Refresh :

On iOS 8 and above, files inside apps are automatically encrypted using NSFileProtection whenever the device is locked. If your app attempts to do any work involving Realm while the device is locked and the NSFileProtection attributes of your Realm files are set to encrypt them (which is the case by default), an open() failed: Operation not permitted exception will be thrown.

超越那个 Realm 带来了自己的本地文件Encryption支持。

Realm supports encrypting the database file on disk with AES-256+SHA2 by supplying a 64-byte encryption key when creating a Realm.

// Generate a random encryption key
let key = NSMutableData(length: 64)!
SecRandomCopyBytes(kSecRandomDefault, key.length,
UnsafeMutablePointer<UInt8>(key.mutableBytes))

// Open the encrypted Realm file
let config = Realm.Configuration(encryptionKey: key)
do {
let realm = try Realm(configuration: config)
// Use the Realm as normal
let dogs = realm.objects(Dog).filter("name contains 'Fido'")
} catch let error as NSError {
// If the encryption key is wrong, `error` will say that it's an invalid database
fatalError("Error opening realm: \(error)")
}

This makes it so that all of the data stored on disk is transparently encrypted and decrypted with AES-256 as needed, and verified with a SHA-2 HMAC. The same encryption key must be supplied every time you obtain a Realm instance.

关于ios - iOS 上的 Realm 是否默认加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37343339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com