SqlCipher 不加密

发布于 2024-11-04 05:43:32 字数 1391 浏览 1 评论 0原文

我没有收到编译错误,但我的数据库没有加密...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清眉祭 2024-11-11 05:43:32

最可能的问题是您没有将项目链接到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文