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.
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.
SQLITE_HAS_CODECafter including the header is probably not a good idea.