samedi 20 février 2016

Access SQLite DB in memory that was read from disk

Is it possible to get the SQLite library to open a handle to a SQLite DB that was read from disk and stored in memory?

Say if I read the entire database like so:

FILE *f = fopen("my.db", "rb");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);

char *db = malloc(fsize + 1);
fread(string, fsize, 1, f);
fclose(f);

Is it then possible to pass the *db pointer to the SQLite library to read/write from?

The concept behind this is that I want to have an AES encrypted SQLite database on disk where the decrypted contents never leave memory. So I had a plan that if I read the encrypted DB to memory, apply the decryption algo to it, then pass the pointer to SQLite some how I could then use SQLite like normal from memory. Then when it is time to clean up I can apply the encryption algo and overwrite the on disk encrypted DB.

Of course I haven't found a way to do this and so far my only real option is to apply the encryption algo on the data before giving it to the SQLite library to store. This means the database itself as a whole isn't encrypted but the data actually stored is.

Although I'd prefer the first approach.

Anyone have any thoughts or solutions?

Thanks

Aucun commentaire:

Enregistrer un commentaire