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;
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;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLCIPHER");
db.setDatabaseName("/home/joana/projects/CAS_upgrade/code/test.db");
if (!db.open())
qFatal("Could not access database.");
QSqlQuery query(db);
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;
To copy to clipboard, switch view to plain text mode
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
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');");
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');");
To copy to clipboard, switch view to plain text mode
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
Bookmarks