The following possible solutions were found for encryption in SQLite:
- SEE - official implementation.
- wxSQLite - c ++ wxWidgets SQLite encryption wrapper.
- SQLCipher - uses in the openSSL implementation.
- SQLiteCrypt is a modified implementation of the API.
- botansqlite3 is a SQLite3 encryption codec using the botan library.
- SQLiteCrypto - java API for Android, uses AES-256 and SHA-256.
- QtCipherSqlitePlugin - SQL plugin for Qt with encryption support.
From the reviewed SEE, SQLiteCrypt and SQLiteCrypto solutions require a license purchase. SQLCipher is available in Community Edition, but requires libcrypto.
The most interesting solution from the presented list, in my opinion, is
QtCipherSqlitePlugin .
The plugin encrypts on the fly and is fully integrated into the Qt API.
The plugin is based on SQLite sources as well as wxSQLite3 from wxWidgets and released under the LGPL 2.1 license.
The
Advanced Encryption Standard (AES) is used as the encryption algorithm.
')
Build and install the plugin
1. Download the sources QtCipherSqlitePlugin
git clone github.com/devbean/QtCipherSqlitePlugin.git
2. Download the Qt sources of the required version (in the example - 4.8.6)
wget download.qt.io/archive/qt/4.8/4.8.6/qt-everywhere-opensource-src-4.8.6.tar.gz
3. Unpack the archive
tar zxvf qt-everywhere-opensource-src-4.8.6.tar.gz
4. Open a project in QtCreator
QtCipherSqlitePlugin \ sqlitecipher \ sqlitecipher.pro
5. Specify the Qt source directories
In the QtCipherSqlitePlugin \ sqlitecipher \ qt_p.pri file in the lines
# Qt4
! greaterThan (QT_MAJOR_VERSION, 4): INCLUDEPATH + = <Qt4_Path> / src / sql / kernel
# Qt5
greaterThan (QT_MAJOR_VERSION, 4): INCLUDEPATH + = <Qt5_Path> / Src / qtbase / src / sql / kernel
Set the appropriate paths to the Qt source. In my case, Qt4 has a string
/home/developer/Sources/qt-everywhere-opensource-src-4.8.6/src/sql/kernel
6. We collect the project
7. Copy the plugin library to the Qt plugin directory
In my case in the directory / usr / lib / x86_64-linux-gnu / qt4 / plugins / sqldrivers
Using the plugin
1. We check the performance
By running the application from the QtCipherSqlitePlugin / test / test.pro project, we are convinced that the SQLITECIPHER database driver has appeared in the list of available drivers.
("QSQLITE", "SQLITECIPHER")
1: "AAA"
2: "BBB"
3: "CCC"
3: "DDD"
4: "EEE"
5: "FFF"
6: "GGG"
2. Create an encrypted database
Delete the test_c.db file created during the execution of the test application.
In the main.cpp code of the test.pro project, before connecting to the database, set a password.
dbconn.setPassword("password");
We start the application, a test database will be created. We close it, change the password, re-launch, we see that there is no access to the database with the wrong password.
Unsolved question
It remains unclear how to change the password for the database already created and encrypted with this password.