Problem using the SqlCipher Driver
Hi,
I need to encrypt an SQLite database, and I was glad to find out that such a functionality is avaliable through the QSQLCIPHER! :-)
I have built the driver, following these instructions:
http://www.qtcentre.org/wiki/index.p...rt_%28Linux%29
Everything seemed to work fine.
I am using Qt 4.8.6, built from source and the plugins are located in the $QTDIR/plugins/sqldrivers directory.
libqsqlcipher.so is one of the libraries present in this directory, as an output of the previously successful installation.
I wrote an application to test if everything is fine, and the output of QSqlDatabase::drivers() is:
("QSQLCIPHER", "QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC", "QPSQL7", "QPSQL")
Then I wrote another application, to open a previously encrypted database;
Code:
db.setDatabaseName("/home/joana/projects/CAS_upgrade/code/test.db");
if (!db.open())
qFatal("Could not access database.");
query.exec("PRAGMA key = 'testkey';");
if (query.
lastError().
type() != QSqlError::NoError) qDebug() << query.lastError().text();
else
qDebug() << "ok!" << endl;
query.exec("select * from pt_shop;");
if (query.
lastError().
type() != QSqlError::NoError) qDebug() << query.lastError().text();
else
qDebug() << "ok!" << endl;
There is no error in opening the database using the sqlcipher driver, and in applying the PRAGMA. However, when I try to make a select, I get an error stating that the database is "encrypted or not valid"
I re-wrote the application, and applied these queries
Code:
query.exec("ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey';");
if (query.
lastError().
type() != QSqlError::NoError) qDebug() << query.lastError().text();
else
qDebug() << "ok!" << endl;
query.exec("SELECT sqlcipher_export('encrypted');");
if (query.lastError().type() != QSqlError::NoError)
qDebug() << query.lastError().text();
else
qDebug() << "ok!" << endl;
for which I got this error:
"no such function: sqlcipher_export Unable to execute statement"
My guess, is that QT is using the normal SQLite driver, rather than the SQLCIPHER one, since this is exactly the same behaviour that I get in the command line, if I use plain sqlite3... :-/
Anybody has any idea, why this is happening?
These are my library versions:
SQLite version 3.7.13 2012-06-11 02:05:22 (from ubuntu package)
SQLCipher version 3.7.17 2013-05-20 00:56:22 (compiled from source)
SQLCipher was compiled both as a shared library, and as a Qt plugin and libsqlcipher.so
is present in /usr/local/lib/ and in $QTDIR_PLUGINS
I really appreciate any suggestions or thoughts about this, because I don't know where else to look!
Thanks in advance,
Joana
Re: Problem using the SqlCipher Driver
You can verify whether or not your driver is properly using SQLCipher by querying the current version of SQLCipher at runtime. This can be accomplished by issuing the following command:
PRAGMA cipher_version;
It may be the case that sqlcipher_export('…'); is failing because the Qt driver has not been properly built with SQLCipher and you may just be loading SQLite instead.
Re: Problem using the SqlCipher Driver
Hi,
I am try to use the sqlcipher library with qt to encrypt the database. I am install the sqlcipher library on my Ubuntu 14.04 . The database encryption & decryption is working properly using command line.
When I use this driver in Qt it gives me following error,
QSqlDatabase: QSQLCIPHER driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
I am new with Qt,Please let me know if any idea related to this.