Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Unable to open manually-encrypted SQLite database with QtCipherSqlitePlugin and vice versa



  • I have manually created a SQLite database (named "localDB.db") and protected it with a password, by using DB browser. If I am not mistaken, DB browser uses SQLCipher (with a default page size of 1024), for encrypting a database.
    However, if I try to open the database with the QT plugin called QtCipherSqlitePlugin (see following code), I always get the error that "the password is invalid or cipher does not match", although I obviously provide the correct password and have set the cipher as "sqlcipher".

    #include <QCoreApplication>
    #include <QDebug>
    #include <QDir>
    #include <QSqlError>
    #include <QtSql/QSqlDatabase>
    
    #ifdef Q_OS_IOS
    
    #include <QtPlugin>
    
    Q_IMPORT_PLUGIN(SqliteCipherDriverPlugin)
    
    #endif
    
    #define CONNECTION_FAILED -1
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        qDebug() << QSqlDatabase::drivers();
    
        QString dir = QCoreApplication::applicationDirPath();
        QString db_file_path = dir + "/Data/localDB.db";
        qDebug() << "DB file path is:" << db_file_path;
    
        QSqlDatabase db = QSqlDatabase::addDatabase("SQLITECIPHER");
        db.setDatabaseName(db_file_path);
        db.setPassword("test");
        db.setConnectOptions("QSQLITE_USE_CIPHER=sqlcipher");
        db.open();
    
        if (!db.isOpen())
        {
            qDebug() << "Connection failed: " << db.lastError().driverText();
            exit(CONNECTION_FAILED);
        }
    
        return 0;
    }
    

    The same happens for the inverse process: if I encrypt a database by using this plugin, then I am unable to manually open the database with DB Browser or other similar programs, because it does not accept the password.

    How can I solve this problem? I need to access an encrypted SQLite database through both my software and a third-party application like DB browser. Thanks in advance.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should rather contact the authors of both project. They'll likely have better knowledge about that part.


Log in to reply