I am able to decrypt the database using the raw key with the DB Browser (SQLite) with the SQLChiper 3 default settings. But when I set the same settings through PRAGMA using sqlite3_exec, I am not able to decrypt it.
In DB Browser (SQLite), I am passing a raw key in ‘0x7Ab…’ format and I am passing same key to PRAGMA KEY.
Can someone guide what I may be doing wrong?
snprintf(keyPragma, sizeof(keyPragma), "PRAGMA key = \"x'%s'\"", key);
result = sqlite3_exec(connection, keyPragma, NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA key'");
}
result = sqlite3_exec(connection, "PRAGMA cipher_default_compatibility = 3;", NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA cipher_default_compatibility'");
}
result = sqlite3_exec(connection, "PRAGMA cipher_page_size = 1024;", NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA cipher_page_size'");
}
result = sqlite3_exec(connection, "PRAGMA kdf_iter = 64000;", NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA kdf_iter'");
}
result = sqlite3_exec(connection, "PRAGMA cipher_hmac_algorithm = HMAC_SHA1;", NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA cipher_hmac_algorithm'");
}
result = sqlite3_exec(connection, "PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;", NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA cipher_kdf_algorithm'");
}
result = sqlite3_exec(connection, "PRAGMA cipher_plaintext_header_size = 0;", NULL, NULL, &err_msg);
if (result != SQLITE_OK) {
handle_error("Failed to execute 'PRAGMA cipher_plaintext_header_size'");
}