Reputation: 32665
I want to use an encrypted SQLite database in Qt. Is it possible to connect to database by QSqlDatabase
and use SQLCipher to encrypt or decrypt the database? for instance regularly i connect to SQLite database file like this:
QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE","Main_Connection" );
db.setDatabaseName( "Main.sqlite" );
db.open();
I want to know is it possible to use the SQLCipher API to decrypt the database and use the Qt database module to connect and manipulate the database?
Upvotes: 2
Views: 1178
Reputation: 1779
Since the API is the same, you should be able to build Qt's SQLITE driver with SQLCipher without modifications. The only caveats are,
http://sqlcipher.net/sqlcipher-api/
If you are on Linux and cannot (or do not want to) modify system, then modify configure script under sqlite) case, such that it finds sqlcipher headers and link with correct libsqlcipher library. For example, this change allows me to build SQLite plugin with SQLCipher instead,
--- a/configure
+++ b/configure
@@ -4736,12 +4736,12 @@ for _SQLDR in $CFG_SQL_AVAILABLE; do
if [ "$CFG_SQL_sqlite" != "no" ]; then
SQLITE_AUTODETECT_FAILED="no"
if [ "$CFG_SQLITE" = "system" ]; then
- if [ -n "$PKG_CONFIG" ] && $PKG_CONFIG --exists sqlite3 2>/dev/null; then
+ if [ -n "$PKG_CONFIG" ] && $PKG_CONFIG --exists sqlite3override 2>/dev/null; then
QT_CFLAGS_SQLITE=`$PKG_CONFIG --cflags sqlite3 2>/dev/null`
QT_LFLAGS_SQLITE=`$PKG_CONFIG --libs sqlite3 2>/dev/null`
else
- QT_CFLAGS_SQLITE=
- QT_LFLAGS_SQLITE="-lsqlite3 -lz"
+ QT_CFLAGS_SQLITE="-I/usr/include/sqlcipher"
+ QT_LFLAGS_SQLITE="-lsqlcipher -lz"
fi
if compileTest unix/sqlite "SQLite" $QT_LFLAGS_SQLITE $QT_CFLAGS_SQLITE; then
if [ "$CFG_SQL_sqlite" = "auto" ]; then
Then you need to configure with -system-sqlite
Upvotes: 1