SqlCipher 不加密
我没有收到编译错误,但我的数据库没有加密...
const char* key = [@"BIGSecret" UTF8String];
int err = sqlite3_key(database, key, strlen(key));
if (sqlite3_exec(database, (const char*) "SELECT count(*) FROM animals;", NULL, NULL, NULL) == SQLITE_OK) {
// database has been initialized
}
我指的是网站 http://sqlcipher.net/ Documentation/ios 并使用 SQLiteTutorial 示例,其中已有 AnimalDatabase.sql 数据库。
我还知道加密不适用于现有数据库,因此我尝试了以下代码:
- (void)encryptDB
{
NSLog (@"Start");
sqlite3 *DB = [self getNewDBConnection];
sqlite3_exec(DB, "ATTACH DATABASE AnimalDatabase.sql AS encrypted KEY 1234;", NULL, NULL, NULL);
sqlite3_exec(DB, "CREATE TABLE encrypted.Account(id,Name,Desc,Image);", NULL, NULL, NULL);
sqlite3_exec(DB, "INSERT INTO encrypted.Account SELECT * FROM animals;", NULL, NULL, NULL);
sqlite3_exec(DB, "DETACH DATABASE encrypted;", NULL, NULL, NULL);
NSLog (@"End");
}
- (sqlite3 *)getNewDBConnection{
if (sqlite3_open([databasePath UTF8String], &newDBconnection) == SQLITE_OK) { // opening AnimalDatabase.sql
NSLog(@"Database Successfully Opened :)");
} else {
NSLog(@"Error in opening database :(");
}
return newDBconnection;
}
但仍然没有成功。有人可以帮忙吗?
I dont get compile errors, but my database does not encrypt...
const char* key = [@"BIGSecret" UTF8String];
int err = sqlite3_key(database, key, strlen(key));
if (sqlite3_exec(database, (const char*) "SELECT count(*) FROM animals;", NULL, NULL, NULL) == SQLITE_OK) {
// database has been initialized
}
I am referring site http://sqlcipher.net/documentation/ios and using SQLiteTutorial example which has AnimalDatabase.sql database already in it.
I also came to know that encryption wont work on the existing database, so i tried the below code:
- (void)encryptDB
{
NSLog (@"Start");
sqlite3 *DB = [self getNewDBConnection];
sqlite3_exec(DB, "ATTACH DATABASE AnimalDatabase.sql AS encrypted KEY 1234;", NULL, NULL, NULL);
sqlite3_exec(DB, "CREATE TABLE encrypted.Account(id,Name,Desc,Image);", NULL, NULL, NULL);
sqlite3_exec(DB, "INSERT INTO encrypted.Account SELECT * FROM animals;", NULL, NULL, NULL);
sqlite3_exec(DB, "DETACH DATABASE encrypted;", NULL, NULL, NULL);
NSLog (@"End");
}
- (sqlite3 *)getNewDBConnection{
if (sqlite3_open([databasePath UTF8String], &newDBconnection) == SQLITE_OK) { // opening AnimalDatabase.sql
NSLog(@"Database Successfully Opened :)");
} else {
NSLog(@"Error in opening database :(");
}
return newDBconnection;
}
But still no success. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最可能的问题是您没有将项目链接到 SQLCipher 静态库。因此,您的项目正在使用默认的系统 SQLite 框架。
进入您的项目构建设置 ->构建阶段 ->链接二进制库并确保 libsqlcipher.a 和 libcrypto.a 都列在那里。如果没有,请添加它们。然后清理项目并重建。
The most likely problem is that you aren't linking your project against the SQLCipher static library. Thus, your project is using the default system SQLite framework.
Go into your Project Build settings -> Build Phases -> Link With Binary Libraries and make sure that libsqlcipher.a and libcrypto.a are both listed there. If not, add them. Then clean the project and the rebuild.