sqlite orm is really greate. but i am trying to Encrypt database...try to integrated with wxsqlite. but i dont know how to do that....is there any way to use sqlite orm and create an Encrypted database?
storage class has public on_open field which is std::function<void(sqlite3 *)> and it is called right after every sqlite3_open call so you can call inside it any encryption routine.
Yes, Thank you....I got that...and i wanna share this demo code for example, maybe it will be helpful to other guys:
using std::cout;
using std::endl;
// std::function<void(sqlite3 *)>
void data_base_key_callback(sqlite3* db_hanlde)
{
DBGOUT("call sqlite3_rekey_v2");
sqlite3_key_v2(db_hanlde, "blob.sqlite", "MyKey123", sizeof("MyKey123"));
// sqlite3_rekey_v2(db_hanlde, "blob.sqlite", "MyKey123", sizeof("MyKey123"));
}
struct User {
int id;
std::string name;
std::vector<char> hash; // binary format
};
int main(int, char**) {
using namespace sqlite_orm;
auto storage = make_storage("blob.sqlite",
make_table("users",
make_column("id", &User::id, primary_key()),
make_column("name", &User::name),
make_column("hash", &User::hash)));
storage.on_open = data_base_key_callback;
storage.sync_schema(); // this party will call on_open and create the datebase filed:)
storage.remove_all<User>();
User alex{
0,
"Alex",
{0x10, 0x20, 0x30, 0x40},
};
alex.id = storage.insert(alex);
cout << "users count = " << storage.count<User>() << endl;
cout << "alex = " << storage.dump(storage.get<User>(alex.id)) << endl;
auto hash = storage.get<User>(alex.id).hash;
assert(hash.size() == 4);
assert(hash[0] == 0x10);
assert(hash[1] == 0x20);
assert(hash[2] == 0x30);
assert(hash[3] == 0x40);
system("pause");
return 0;
}
I use wxsqlite for encrption...the way we integrate wxsqlite and sqlite orm together is very easy...we dont need to include all wxsqlite code, just Compile the code in directory:sqlite3secure. and include these files and you can open the datebase file in Binary. Then you will fund it has been encrpted successfully....
@MovRIP is the issue actual?
yes...thanks, the solution you give me is actually works....on_open callback is the interface that we can encrpt
Most helpful comment
Yes, Thank you....I got that...and i wanna share this demo code for example, maybe it will be helpful to other guys:
I use wxsqlite for encrption...the way we integrate wxsqlite and sqlite orm together is very easy...we dont need to include all wxsqlite code, just Compile the code in directory:sqlite3secure. and include these files and you can open the datebase file in Binary. Then you will fund it has been encrpted successfully....