Password protection of Database
Good Day, How can be database protected using password? Is there way to do that?
Regards
Hi. Nice question. Never used encrypted sqlite db, just heard about. Let me read about it and then implement. If you have custom wishes feel free to write. Thanks
Looks like there is no encryption shipped in the basic version of libsqlite3. It means one has to use extensions to make db encrypted. There are several encryption extensions for sqlite3. Examples:
- https://github.com/OlivierJG/botansqlite3/blob/master/test_sqlite.cpp,
- https://github.com/rindeal/SQLite3-Encryption
It would be silly and impossible to try to add all of them. Better way is to add extension API to sqlite_orm. Details: assume we don't use sqlite_orm but use sqlite3 straight with it's C-lib. If we want db to be encrypted we have to call sqlite3_key function with sqlite3* pointer of database connection right after sqlite3_open. So we can add a member to a storage like
std::function<void(sqlite3*)> on_open;
which will be called right after storage's inner sqlite3_open call (if on_open isn't null of course). So first outer example https://github.com/OlivierJG/botansqlite3/blob/master/test_sqlite.cpp can be implemented like this:
auto storage = ...;
storage.on_open = [&](sqlite3* db){
auto key = "qwerty";
sqlite3_key(db, key, strlen(key));
};
//..
but extension with sqlite3_key or whatever function must be added manually.
What do you think? If it's ok I shall add this in the next commit
Thank you very much about the reply. I need to do impact analysis to find out best way. Once it is complete, I shall revert back to you.
It will do . It will be great if you provide an example. This is not urgent issue for me. Thanks
Hey. I've added on_open public member to the latest d2a4f1bdc6bade4b2880b45dba562447f6c770d3 commit. Please check it out. It is called right after sqlite3_open call (and PRAGMA foreign_key 1 if there are foreign keys exist in a storage). I don't know what kind of example do you expect cause there are a lot of encryption solutions for sqlite and they depend from platform. Which one do you want to use?
Thanks. I shall check it later.