gpt4 book ai didi

encryption - 有没有办法从现有的 Realm 数据库中删除加密?

转载 作者:行者123 更新时间:2023-12-05 06:41:39 26 4
gpt4 key购买 nike

我们使用的是 Objective-C 版本的 Realm,版本 2.0.2。该数据库当前已加密并在现场。

Realm 启动时出现间歇性崩溃,并显示错误消息“无法在路径打开 Realm ... Realm 文件解密失败”。我们使用的是 Realm 的最新版本,但未能找到解决方案。

我们真的不需要在设备上加密数据库,所以我们想考虑取消加密。这是一个选项吗?如果是,我们将如何迁移现有的加密数据库?

最佳答案

您可以使用 writeCopyToURL:encryptionKey:error:nil 加密 key 来编写未加密的副本,然后将其移动到原始文件上:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RLMRealmConfiguration *confg = [[RLMRealmConfiguration alloc] init];
config.encryptionKey = ...;
NSURL *tempUrl = [NSURL URLWithString:[NSTemporaryDirectory() stringByAppendingPathComponent:"temp.realm"]];

// Open the Realm within an autoreleasepool so that it's closed before we try
// to overwrite the original file
@autoreleasepool {
RLMRealm *realm = [RLMRealm realmWithConfiguration:config error:nil];
[realm writeCopyToURL:tempUrl encryptionKey:nil error:nil];
}

[[NSFileManager defaultManager] moveItemAtURL:tempUrl toURL:config.fileUrl error:nil];

// ... other didFinishLaunchingWithOptions things ...

return YES;
}

关于encryption - 有没有办法从现有的 Realm 数据库中删除加密?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39959320/

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