Simply i have an encrypted database, and my code should filter out the key from a text file.
i’ve done all that, but when i run my code it says “file is not a database”.
After lots of reserch i beleive the problem wil be in how the ‘key’/‘password’ generated from the text file are encoded.
beacuse passing the key manully using sqlcipher from the command line decrypt the databse and opens it, works fine!
What i’ve done:
Opening the database file :
int rc = sqlite3_open("/path/to/database.sqlite", &db);
Storing the PRAGMA statment for setting the key in a variable to use it :
snprintf(keyQ, sizeof(keyQ), "PRAGMA key=\"x'%s'\";", subbuff);
knowing that the variable
subbuff is actully the key as a char array.
rc = sqlite3_exec(db,keyQ, NULL, 0, NULL);
rc = sqlite3_exec(db, "PRAGMA cipher_plaintext_header_size = 32;", 0, 0, NULL);
rc = sqlite3_exec(db, "PRAGMA cipher_compatibility = 3;", 0, 0, NULL);
knowing that the error occurs only when i pass in an actual qurery like the following:
char *sql = "SELECT * FROM table;";
rc = sqlite3_exec(db, sql, callback , 0, &errMsg);
if i comment the last line, no error happen.
i’ve tried lots and lots of solutions without any results.