I created one In-memory database and I tried to encrypt and serialize the database by using sqlite3_serialize() the in-memory database, but the output of sqlite3_serialize() is a nonencrypted database.
my code:
sqlite3* db;
char* ErrMsg;
int status = sqlite3_open(":memory:", &db);
if (sqlite3_exec(db, "PRAGMA key = 'KEY';", 0, NULL, &ErrMsg) == SQLITE_OK)
{
}
if (sqlite3_exec(db, "PRAGMA cipher_hmac_algorithm = HMAC_SHA1;", 0, NULL, &ErrMsg) == SQLITE_OK)
{
}
if (sqlite3_exec(db, "PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;", 0, NULL, &ErrMsg) == SQLITE_OK)
{
}
if (status == SQLITE_OK)
{
int exit = 0;
char* messaggeError = NULL;
std::string sql = "CREATE TABLE PERSON("
"ID INT PRIMARY KEY NOT NULL, "
"NAME TEXT NOT NULL, "
"SURNAME TEXT NOT NULL, "
"AGE INT NOT NULL, "
"ADDRESS CHAR(50), "
"SALARY REAL );";
exit = sqlite3_exec(db, sql.c_str(), NULL, NULL, &messaggeError);
std::string insert_query("INSERT INTO PERSON VALUES(1, 'STEVE', 'GATES', 30, 'PALO ALTO', 1000.0);"
"INSERT INTO PERSON VALUES(2, 'BILL', 'ALLEN', 20, 'SEATTLE', 300.22);"
"INSERT INTO PERSON VALUES(3, 'PAUL', 'JOBS', 24, 'SEATTLE', 9900.0);");
exit = sqlite3_exec(db, insert_query.c_str(), NULL, NULL, &messaggeError);
sqlite3_int64 serilized_count;
unsigned char* serialized_output = sqlite3_serialize(db,0, &serilized_count,0);
The output of the sqlite3_serialize() is non encrypted db;