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;
Qt Code:
  1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLCIPHER");
  2.  
  3.  
  4. db.setDatabaseName("/home/joana/projects/CAS_upgrade/code/test.db");
  5. if (!db.open())
  6. qFatal("Could not access database.");
  7.  
  8. QSqlQuery query(db);
  9.  
  10. query.exec("PRAGMA key = 'testkey';");
  11.  
  12. if (query.lastError().type() != QSqlError::NoError)
  13. qDebug() << query.lastError().text();
  14. else
  15. qDebug() << "ok!" << endl;
  16.  
  17.  
  18. query.exec("select * from pt_shop;");
  19.  
  20. if (query.lastError().type() != QSqlError::NoError)
  21. qDebug() << query.lastError().text();
  22. else
  23. 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

Qt Code:
  1. query.exec("ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey';");
  2.  
  3. if (query.lastError().type() != QSqlError::NoError)
  4. qDebug() << query.lastError().text();
  5. else
  6. qDebug() << "ok!" << endl;
  7.  
  8. 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