Results 1 to 3 of 3

Thread: Problem using the SqlCipher Driver

  1. #1

    Default Problem using the SqlCipher Driver

    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:

    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. 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:


    Then I wrote another application, to open a previously encrypted database;
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLCIPHER");
    4. db.setDatabaseName("/home/joana/projects/CAS_upgrade/code/test.db");
    5. if (!
    6. qFatal("Could not access database.");
    8. QSqlQuery query(db);
    10. query.exec("PRAGMA key = 'testkey';");
    12. if (query.lastError().type() != QSqlError::NoError)
    13. qDebug() << query.lastError().text();
    14. else
    15. qDebug() << "ok!" << endl;
    18. query.exec("select * from pt_shop;");
    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';");
    3. if (query.lastError().type() != QSqlError::NoError)
    4. qDebug() << query.lastError().text();
    5. else
    6. qDebug() << "ok!" << endl;
    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();
    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
    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,

  2. #2
    Join Date
    Sep 2014
    Qt products
    Qt5 Qt/Embedded
    MacOS X Unix/X11 Windows Android

    Default 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.

  3. #3
    Join Date
    Feb 2016
    Qt products
    Qt4 Qt5 Qt/Embedded

    Default Re: Problem using the SqlCipher Driver

    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.

Similar Threads

  1. SQLCipher, Windows and Mac OS
    By mtnbiker66 in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2012, 18:55
  2. Using NCReport with SQLCipher
    By SIFE in forum Qt Programming
    Replies: 2
    Last Post: 12th March 2012, 18:02
  3. Replies: 2
    Last Post: 16th November 2011, 23:19
  4. Encrypting an existing sqlite database in sqlcipher
    By thefatladysingsopera in forum Newbie
    Replies: 5
    Last Post: 21st October 2011, 19:47
  5. AES-256 encrypted SQLite databases with SQLCipher
    By Lykurg in forum Installation and Deployment
    Replies: 10
    Last Post: 29th July 2011, 04:22

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.