【问题标题】:Is Realm secure like SQLite & Core Data? [closed]Realm 是否像 SQLite 和 Core Data 一样安全? [关闭]
【发布时间】:2016-04-11 06:11:01
【问题描述】:

Realm 是 SQLite 和 Core Data 的替代品吗,它有多安全以及如何使用 Realm

【问题讨论】:

标签: ios iphone realm


【解决方案1】:

SqliteCoreData 都在 store 中存储纯文本,如果您不告诉它加密,您可以对它们都使用加密以使其安全。 Realm 默认情况下也是如此,它以纯文本形式存储数据,但您可以通过下面的代码加密数据(取自 Realm 站点)

// Generate a random encryption key
NSMutableData *key = [NSMutableData dataWithLength:64];
SecRandomCopyBytes(kSecRandomDefault, key.length, (uint8_t *)key.mutableBytes);

// Open the encrypted Realm file
RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.encryptionKey = key;
NSError *error = nil;
RLMRealm *realm = [RLMRealm realmWithConfiguration:config error:&error];
if (!realm) {
    // If the encryption key is wrong, `error` will say that it's an invalid database
    NSLog(@"Error opening realm: %@", error);
}

// Use the Realm as normal
RLMResults<Dog *> *dogs = [Dog objectsInRealm:realm where:@"name contains 'Fido'"];

请访问此link 以获取有关 Realm 加密的更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多