Integrate SQLite code
- There is no encryption function in the open source SQLite, so if you need encryption, you need to implement Sqlite3_keySqlite3_rekey and other related functions.
- However, the open source Wxsqlite3 has been implemented in the encryption, so as long as the code here to integrate into QT , the main is to implement the Sqlite3_key sqlite3_rekey and other functions to add to In the sqlite3.c of qt
- Here is a code that has been integrated qt_sqlite_driver.zip
- Just unzip it to the qtbase\src\3rdparty .
- The main changes to the consolidation are as follows:
- Modified the sqlite.pri compilation configuration file
- Modified the sqlite\sqlite3.c file
- Added sqlite\codec.c (. h ) sqlite\rijndael.c ( . h) sqlite\sha2.c ( . h)
Modify QT Source code
-
Open Qtbase\src\sql\kernel\qsqldriver.h, declaring two new interfaces
|
/ **
* @brief Set database password
* @param key-password
* /
virtual bool setKey (const QString & key);
/ **
* @brief reset database password
* @param key-password
* /
virtual bool resetKey (const QString & key);
|
-
Open qtbase\src\sql\kernel\qsqldriver.cpp to add a default implementation to the two new interfaces
bool QSqlDriver::setKey(const QString&)
{
return false;
}
bool QSqlDriver::resetKey(const QString&)
{
return false;
}
-
Open Qtbase\src\sql\drivers\sqlite\qsql_sqlite_p.h, inherit those two new interfaces
/ **
* @brief Set database password
* @param key-password
* /
bool setKey (const QString & key);
/ **
* @brief reset database password
* @param key-password
* /
bool resetKey (const QString & key);
-
Open Qtbase\src\sql\drivers\sqlite\qsql_sqlite_p.cpp, inherit those two new interfaces
|
bool QSQLiteDriver::setKey(const QString& key)
{
Q_D(QSQLiteDriver);
if (d->access)
{
return (SQLITE_OK == sqlite3_key(d->access, key.toStdString().c_str(), key.toStdString().size()));
}
return false;
}
bool QSQLiteDriver::resetKey(const QString& key)
{
Q_D(QSQLiteDriver);
if (d->access)
{
return (SQLITE_OK == sqlite3_rekey(d->access, key.toStdString().c_str(), key.toStdString().size()));
}
return false;
}
|
Compiling QT
Dynamically compiling Qt 5.6
Statically compiling Qt 5.6
http://wangjie.rocks/2016/05/10/qt-sqlite-cipher/
Add encryption to Qt SQLite