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.

Jesper Juhl
32.2k4 gold badges55 silver badges81 bronze badges
asked Jun 30, 2025 at 6:46
1
  • Defining SQLITE_HAS_CODEC after including the header is probably not a good idea. Commented Jun 30, 2025 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!

tdy
42.1k43 gold badges126 silver badges125 bronze badges
answered Jun 30, 2025 at 10:00
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.