无法使用 SQLCipher 加密
我目前正在为 iPhone 开发一个简单的帐户管理应用程序。我正在使用 sqlcipher 来加密和解密数据库。
目前,我的应用程序包中有一个未加密的数据库,我想将其复制到 iPhone 文档目录然后对其进行加密,或者在将其复制到文档目录之前对其进行加密。
我面临的问题是,无论我做什么,我似乎都会得到一个未加密的数据库,无论我尝试使用哪种加密方法,无论是“ATTACH”数据库方法还是“key()/rekey” ()“ 方法。
我尝试在终端中使用“ATTACH”数据库方法,但结果是一个未加密的数据库。我尝试以编程方式使用“key()/rekey()”方法,如下所示:
sqlite3 *db;
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"KeyCrypt.sqlite"];
if (sqlite3_open([defaultDBPath UTF8String],&db)==SQLITE_OK) {
NSLog (@"Running keying.");
sqlite3_key(db, "1234", 4);
if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// password is correct, or, database has been initialized
NSLog (@"This has occured correctly?");
}
else
{
// incorrect password!
NSLog (@"This has occured incorrectly?");
}
}
我在某处做错了什么吗? 我已经尝试在线研究一整天,但无法找到解决方案来解释为什么我的数据库在运行之前或运行期间没有加密:(
如果您需要任何额外的信息,我愿意提供给您,请帮助学生
!
编辑:
用于键入我的数据库的方法摘录。
//Initializing the sqlite3_key function.
int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);
sqlite3_key(db, "1234", 4);
显然我没有初始化 sqlite3_key -_-”。 此外,即使文件已加密,检查仍然表明发生了错误并且数据库未成功打开。
关于打开数据库,我打开数据库的每个实例都必须运行 sqlite3_key,对吧?在这种情况下,我可以正常访问数据库,对吗?
感谢您的所有帮助。
I'm currently working on a simple account management app for the iPhone. I'm using sqlcipher to encrypt and decrypt the database.
Currently i have an unencrypted database in the application bundle, which i want to either copy to the iPhone document directory and then get it encrypted, or get it encrypted before i copy it over to the document directory.
The problem that i'm facing is that no matter what i do, i seem to get an unencrypted database, no matter what method of encryption i try to use, be it the "ATTACH" database method or the "key()/rekey()" method.
I tried using the "ATTACH" database method in terminal but the result was an unencrypted database. I tried using the "key()/rekey()" method programmatically as seen here:
sqlite3 *db;
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"KeyCrypt.sqlite"];
if (sqlite3_open([defaultDBPath UTF8String],&db)==SQLITE_OK) {
NSLog (@"Running keying.");
sqlite3_key(db, "1234", 4);
if (sqlite3_exec(db, (const char*) "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// password is correct, or, database has been initialized
NSLog (@"This has occured correctly?");
}
else
{
// incorrect password!
NSLog (@"This has occured incorrectly?");
}
}
Am i doing something wrong, somewhere?
I've tried researching online for one whole day and couldn't come close to finding a solution for why my database isn't encrypted before or during runtime :(
If you require any extra information i am willing to provide it to you, please help a student out!
THANK YOU!
EDIT:
Excerpt of method used to key my db.
//Initializing the sqlite3_key function.
int sqlite3_key(sqlite3 *db, const void *pKey, int nKey);
sqlite3_key(db, "1234", 4);
Apparently i didn't initialize the sqlite3_key -_-".
Also eventhough the file is encrypted the check still says something occurred incorrectly and database wasn't successfully opened.
Regarding the opening of databases, every instance i open my database i have to run the sqlite3_key right? And during that instance I can access the database as per normal right?
Thank you for all the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQLCipher 不再支持使用重新生成密钥将未加密的数据库转换为加密的数据库,因为更改页面大小和每页初始化向量所需的保留字节涉及多种复杂性。因此,您提供的代码将无法在任何最新版本的 SQLCipher 上运行。根据您想要执行的操作,有两种选择:
Using rekey to convert an unencrypted database to an encrypted database is no longer supported by SQLCipher due to several complexities involved with changing the page size and reserved bytes required for per-page initialization vectors. Thus, the code you provided will not operate on any recent version of SQLCipher. Based on what you want to do, there are two options: