1

I integrated sqlite to my project with help library #include <sqlite3.h>... Open and Connect work correct... next example my code:

#include <sqlite3.h>

int callback(void *notUsed, int colCount, char **columns, char **colNames) {
    ///........
}

int main {
    sqlite3 *db;
    int res = sqlite3_open("test.db", &db);
    if (res != SQLITE_OK) {
        printf("Cannot open database\n");
        exit(1);
    }
    sqlite3_exec(db, "SELECT * FROM test_tables;", callback, NULL, NULL);
    if (db != NULL) {
        sqlite3_close(db);
    }
    return 0;
}

After encrypting the database (see screenshot, key type = 'passphrase' page size = '1024') I have connected sqlcipher to the project -lsqlcipher -lsqlite3 -lssl -lcrypto -lcrypt32 -lwsock32 -lws2_32. enter image description here Set SQLITE_HAS_CODEC 1 and use sqlite_key() after sqlite_open()... example my code:

#include <sqlite3.h>
#define SQLITE_HAS_CODEC 1

int callback(void *notUsed, int colCount, char **columns, char **colNames) {
    ///........
}

int main {
    sqlite3 *db;
    int res = sqlite3_open("test.db", &db);
    res = sqlite3_key(db, "abc", 3); // i trying to write 3 and 4...
    if (res != SQLITE_OK) {
        printf("Cannot open database\n");
        exit(1);
    }
    sqlite3_exec(db, "SELECT * FROM test_tables;", callback, NULL, NULL);
    if (db != NULL) {
        sqlite3_close(db);
    }
    return 0;
}

I trying use pragma key='%password%' and pragma page_size=%page size% but i always get next error:

2025-06-29 22:53:57.796: sqlcipher_page_cipher: hmac check failed for pgno=1
2025-06-29 22:53:57.797: sqlite3Codec: error decrypting page 1 data: 1
2025-06-29 22:53:57.797: sqlcipher_codec_ctx_set_error 1

ALWAYS! No matter what I write, nothing changes. Has anyone come across this? Does anyone know what's going on? Thank all in advance

I was trying to connect to an encrypted database and expected to succeed.

1
  • Defining SQLITE_HAS_CODEC after including the header is probably not a good idea. Commented Jun 30 at 8:42

1 Answer 1

0

I just updated sqlite on my computer to the latest version (now 3.13.1), and it fixed this error!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.