Comments (7)
The newest version (v1.1) of this plugin QtCipherSqlitePlugin does support SQLCipher. But I believe you need try the following connection options:
dbconn.setConnectOptions("QSQLITE_USE_CIPHER=sqlcipher; SQLCIPHER_LEGACY=1");
That's because current version of SQLCipher only supports legacy mode so you need set SQLCIPHER_LEGACY
to 1.
I have opened the database encrypted by SQLiteStudio SQLCipher. Please let me know if this helps you.
from qtciphersqliteplugin.
SQLCipher != QCipherSqlite
You are getting confused as these are different encryption tools for SQLite Databases.
DB Browser will not work with this plugin, but it will for SQLCipher, which is different, developed by zetetic I believe and costs money for a compiled PC version of the driver (the Android version is available on their Community Edition).
But fear not, you CAN use this plugin with a database browser AND keep it encrypted. You have, the following options:
- Create your own DB Browser App with Qt. There is a example project to get you started in QtCreator.
- Make an app to decrypt the Db before you edit it in DB Browser.
- Don’t encrypt with a password. Instead, use QtAESEncryption, or QuaZip, or both, to encrypt the file you will need to decrypt the file and unzip before loading it into your App.
I use both 1 and 3, QuaZip enables me to store multiple files in an archive. Rather than just pass wording the zip file (can do this too if you want) I put it into a QtAESEncrypted QByteArray and write this to a QFile output of my choosing.
I also have written a function to decrypt my dbs if I need to use a more powerful DB Editing program than the one I wrote myself (ie. SQLite Browser).
SQLite Browser is Open Source and you can add a QtCipherSqlite plugin for that, but you’d need to write it. Something I’d like to look into at some point time depending.
from qtciphersqliteplugin.
By using your suggestion, I am now able to open a database encrypted with DB browser, so thanks for that.
However, the inverse process does not work: if I encrypt a database with the following command
db.setConnectOptions("QSQLITE_USE_CIPHER=sqlcipher; SQLCIPHER_LEGACY=1; QSQLITE_CREATE_KEY");
DB browser opens the database without asking for password first. It seems that the above command does not encrypt the database.
Which settings do I need to use for encrypting a database with your plugin, so that when the user tries to open it with DB browser or similar programs, he must insert the correct password first?
from qtciphersqliteplugin.
I have tested as you said. First created key using plugin then close Qt application. When I opened the database generated by the plugin with SQLiteDatabaseBrowser, DBBrowser required password. So could you please submit your code for testing? Thank you.
from qtciphersqliteplugin.
This is the code I have written for encrypting an already existing unencrypted database named localDB.db with your plugin:
#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("F:/Project_alpha/Data/localDB.db"); //localDB.db is already existing before running the application
db.setPassword("pass");
db.setConnectOptions("QSQLITE_USE_CIPHER=sqlcipher; SQLCIPHER_LEGACY=1; QSQLITE_CREATE_KEY");
db.open();
if (!db.isOpen())
{
qDebug() << "Connection failed: " << db.lastError().driverText();
exit(CONNECTION_FAILED);
}
return 0;
}
After running the application, localDB.db is opened by DB Browser without asking for any password!
What you say works only if the database does not already exist, but if I want to encrypt a plaintext database, created before running the application, it does not work.
from qtciphersqliteplugin.
Thank you for your reply. I could comfirm this problem. Here is some solution.
First, you have some incorrect code:
db.open();
if (!db.isOpen())
{
qDebug() << "Connection failed: " << db.lastError().driverText();
exit(CONNECTION_FAILED);
}
db.open()
will return false
but db.isOpen()
will return true
. I'll explain why this happen.
In QtCipherSqlitePlugin, open()
function's implementation as following (some pseudo-code):
bool SQLiteCipherDriver::open()
{
...
if (sqlite3_open_v2(db, &d->access, openMode, nullptr) == SQLITE_OK) {
setOpen(true);
wxsqlite3_config(d->access, "cipher", CODEC_TYPE_SQLCIPHER);
const int result = sqlite3_rekey(d->access, "pass", 4);
if (SQLITE_OK != result) {
return false;
}
} else {
setOpen(false);
}
...
}
As you can see, first the plugin need open SQLite then rekey (create password). In Qt SQL plugin, QSqlDriver::open()
is used for opening a database. If we open database successfully, we should set isOpen()
to true
but because rekey is only an action after open and it fails so open()
returns false
. (But I'm not sure if this is correct for open()
. Maybe this should be recode. Not sure for now. Please leave your suggestion if you wish. Thank you) So you need use open()
instead of isOpen()
:
if (!db.open()) {
qDebug() << "Can not open connection: " << db.lastError().driverText();
exit(CONNECTION_FAILED);
}
Second, why rekey
failed? I have tested sqlite3_rekey()
result code is SQLITE_CORRUPT
. After communicating with wxSQLite3 (which QtCipherSqlitePlugin based on) author, the reason seems to be that the default page size (of the plain database) is 4096 bytes, while the SQLCipher requested page size is 1024. All non-legacy test cases using the default page size worked flawlessly.
A workaround is to change the page size of the plain database first. To do this you can issue the following SQL commands:
PRAGMA page_size=1024;
VACUUM;
Thereafter rekeying in legacy SQLCipher mode works.
You could find out our communication at here.
from qtciphersqliteplugin.
Here are some instructions on cryptographic algorithms that may be helpful
Encryption Algorithm Description
from qtciphersqliteplugin.
Related Issues (20)
- not build with qt 5.5.1 HOT 1
- best crypt options HOT 1
- SQL queries are not working when called from another thread
- Qt android 5.14.2 many unknow type name ... HOT 1
- Qt 6.0 error: no member named 'midRef' in 'QString' HOT 5
- wxsqlite3 RC4 encryption is not supported!!! HOT 3
- linker error while building with Qt 5.6.2 msvc 2013 32bit
- The problem of compilation failure under qt5.6
- Do not build with Qt 5.15 and Qt 6.2.1/6.2.4 HOT 13
- QT5.5无法编译
- Why people dont like mingw
- error: inlining failed in call to always_inline '_mm_aesimc_si128': target specific option mismatch HOT 3
- CRASH when when using SQLITECIPHER
- Db file encrypted by QtCipherSqlitePlugin v1.2 can't be opened by QtCipherSqlitePlugin v1.3 HOT 1
- can’t Compile in the linux platform
- Can't compile on MacOS/iOS with Qt 6.5.1 HOT 5
- Call undeclared function vaeseq_u8 on ARM arch HOT 6
- Invalid password between databases on different platforms HOT 2
- 偶尔会异常闪退 HOT 1
- use CMake Construct Project
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtciphersqliteplugin.