阅读加密数据库不适用于iOS 10

编程入门 行业动态 更新时间:2024-10-25 20:19:14
本文介绍了阅读加密数据库不适用于iOS 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个 iOS 应用程序。 加密& 解密读取&写入正在工作,直到 iOS 9 。但是,升级到 iOS 10 后,它开始提供以下消息,即文件被加密或不是数据库。

I'm working on an iOS application. Encryption & Decryption to read & write was working till iOS 9. But after upgrade to iOS 10 it started to giving issue with following message that "file is encrypted or is not a database".

对于 DB加密我使用以下代码:

sqlite3 *db1; if (sqlite3_open([[self.databaseURL path] UTF8String], &db1) == SQLITE_OK) { const char* key = [@"strong" UTF8String]; sqlite3_key(db1, key, (int)strlen(key)); if (sqlite3_exec(db1, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) { NSLog(@"Password is correct, or a new database has been initialized"); } else { NSLog(@"Incorrect password!"); } sqlite3_close(db1); }

&它的工作完全正常。

& it's working perfectly fine.

对于开放阅读操作,我使用以下代码:

For opening and reading operation I'm using following code:

-(void)openDB { NSString *docsDir; docsDir = [self getDirectoryPath]; aPath = [docsDir stringByAppendingPathComponent: @"SQLITE_DEMO.sqlite"]; dbpath = [aPath UTF8String]; }

阅读:

if (sqlite3_open(dbpath, &contactDBNew) == SQLITE_OK) { NSString querySQL = [NSString stringWithFormat:@"SELECT FROM USER"]; const char *query_stmt = [querySQL UTF8String]; char *err; int check = sqlite3_exec(contactDBNew, query_stmt, NULL, NULL, &err); if (sqlite3_prepare_v2(contactDBNew, query_stmt, -1, &statement, NULL) == SQLITE_OK) { // Successfully executed. } else { // Error in execution. } }

在阅读准备声明时,

Here it get failed while reading prepared statement with following error message: "file is encrypted or is not a database".

请指出我错过了什么!

推荐答案

每个数据库打开后,您需要运行PRAGMA key =或使用sqlite3_key。事实上,最好在应用程序开始时打开数据库一次,然后将其关闭。由于关键推导,反复打开和关闭数据库是非常昂贵的。

You need to run PRAGMA key= or use sqlite3_key after every database open. In fact, it is best to open the database once at the start of your application, then close it at the end. It is very expensive to repeatedly open and close the database due to key derivation.

更多推荐

阅读加密数据库不适用于iOS 10

本文发布于:2023-10-27 00:19:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   数据库   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!