这通常不是一个寻找一步一步指南的问题,而是指南本身。
我写这篇文章的目的是为了给其他人提供一些提示,他们在编译驱动程序插件时遇到与我类似的问题。
这通常不是一个寻找一步一步指南的问题,而是指南本身。
我写这篇文章的目的是为了给其他人提供一些提示,他们在编译驱动程序插件时遇到与我类似的问题。
下载Qt 5.4.0 for Windows/MinGW,并安装包括源代码,例如到 C:\Qt\Qt5.4.0
下载OpenSSL for Windows,并安装Visual C++ 2008 Redistributable, 执行 'vcredist_x86.exe' 安装
C:\OpenSSL-Win32
C:\Windows\SysWOW64
)下载并安装Minimalist GNU for Windows(MinGW)的'mingw-get-setup.exe'
C:\MinGW
C:\MinGW
C:\MinGW
的内容复制到Qt-MinGW目录 C:\Qt\Qt5.4.0\Tools\mingw491_32
在C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\etc
中创建'fstab'文件
插入以下内容:
#Win32_Path Mount_Point
C:/Qt/Qt5.4.0/Tools/mingw491_32 /mingw
C:/Qt/Qt5.4.0/5.4 /qt
C:/ /c
zlib-Library
C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\bin
SQLCipher
C:\temp\sqlcipher-master
C:\OpenSSL-Win32\bin\libeay32.dll
复制到 C:\temp\sqlcipher-master
C:\OpenSSL-Win32\lib\libeay32.lib
复制到 C:\temp\sqlcipher-master
构建 SQLCipher.exe
执行 MSYS:C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\msys.bat
$ cd /c/temp/sqlcipher-master
$ ./configure --prefix=$(pwd)/dist --with-crypto-lib=none --disable-tcl CFLAGS="-DSQLITE_HAS_CODEC -DSQLCIPHER_CRYPTO_OPENSSL -I/c/openssl-win32/include /c/temp/sqlcipher-master/libeay32.dll -L/c/temp/sqlcipher-master/ -static-libgcc" LDFLAGS="-leay32"
$ make clean
$ make sqlite3.c
$ make
$ make dll
$ make install
将可执行的SQLite/SQLCipher数据库保存到例如C:\sqlcipher
C:\temp\sqlcipher-master\dist\bin\sqlcipher.exe
复制到C:\sqlcipher
。C:\temp\sqlcipher-master\sqlite3.dll
复制到C:\sqlcipher
。构建Qt-QSQLCIPHER-driver-plugin
C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\plugins\sqldrivers\sqlcipher
在新目录中创建以下三个文件:
文件 1: smain.cpp:
#include <qsqldriverplugin.h>
#include <qstringlist.h>
#include "../../../../src/sql/drivers/sqlite/qsql_sqlite_p.h" // There was a missing " at the end of this line
QT_BEGIN_NAMESPACE
class QSQLcipherDriverPlugin : public QSqlDriverPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "sqlcipher.json")
public:
QSQLcipherDriverPlugin();
QSqlDriver* create(const QString &);
};
QSQLcipherDriverPlugin::QSQLcipherDriverPlugin()
: QSqlDriverPlugin()
{
}
QSqlDriver* QSQLcipherDriverPlugin::create(const QString &name)
{
if (name == QLatin1String("QSQLCIPHER")) {
QSQLiteDriver* driver = new QSQLiteDriver();
return driver;
}
return 0;
}
QT_END_NAMESPACE
#include "smain.moc"
文件2:sqlcipher.pro
TARGET = qsqlcipher
SOURCES = smain.cpp
OTHER_FILES += sqlcipher.json
include(../../../sql/drivers/sqlcipher/qsql_sqlite.pri)
wince*: DEFINES += HAVE_LOCALTIME_S=0
PLUGIN_CLASS_NAME = QSQLcipherDriverPlugin
include(../qsqldriverbase.pri)
文件 3:sqlcipher.json
{
"Keys": [ "QSQLCIPHER" ]
}
C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\sql\drivers\sqlite
复制到C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\sql\drivers\sqlcipher
自定义文件 C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\sql\drivers\sqlcipher\qsql_sqlite.pri
文件的内容应为:
HEADERS += $$PWD/qsql_sqlite_p.h
SOURCES += $$PWD/qsql_sqlite.cpp
!system-sqlite:!contains(LIBS, .*sqlite3.*) {
include($$PWD/../../../3rdparty/sqlcipher.pri) #<-- change path of sqlite.pri to sqlcipher.pri here !
} else {
LIBS += $$QT_LFLAGS_SQLITE
QMAKE_CXXFLAGS *= $$QT_CFLAGS_SQLITE
}
在目录C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty
中创建文件 'sqlcipher.pri',并添加以下内容:
CONFIG(release, debug|release):DEFINES *= NDEBUG
DEFINES += SQLITE_OMIT_LOAD_EXTENSION SQLITE_OMIT_COMPLETE SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_RTREE SQLITE_HAS_CODEC
!contains(CONFIG, largefile):DEFINES += SQLITE_DISABLE_LFS
contains(QT_CONFIG, posix_fallocate):DEFINES += HAVE_POSIX_FALLOCATE=1
winrt: DEFINES += SQLITE_OS_WINRT
winphone: DEFINES += SQLITE_WIN32_FILEMAPPING_API=1
qnx: DEFINES += _QNX_SOURCE
INCLUDEPATH += $$PWD/sqlcipher c:/openssl-win32/include
SOURCES += $$PWD/sqlcipher/sqlite3.c
LIBS += -L$$PWD/sqlcipher/lib -lsqlcipher -leay32 -lsqlite3
TR_EXCLUDE += $$PWD/*
创建并填充C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher
创建以下两个目录:
C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher
C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher\lib
将以下文件复制到C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher
目录下:C:\temp\sqlcipher-master\shell.c
C:\temp\sqlcipher-master\sqlite3.c
C:\temp\sqlcipher-master\sqlite3.h
C:\temp\sqlcipher-master\sqlite3ext.h
将以下文件/目录复制到C:\ Qt \ Qt5.4.0 \ 5.4 \ Src \ qtbase \ src \ 3rdparty \ sqlcipher \ lib
中: C:\temp\sqlcipher-master\dist\lib
C:\temp\sqlcipher-master\sqlite3.dll
C:\OpenSSL-Win32\bin\libeay32.dll
目录现在包括以下文件和目录:
C:\QT\QT5.4.0\5.4\SRC\QTBASE\SRC\3RDPARTY\SQLCIPHER
| shell.c
| sqlite3.c
| sqlite3.h
| sqlite3ext.h
|
\---lib
| libeay32.dll
| libsqlcipher.a
| libsqlcipher.la
| sqlite3.dll
|
\---pkgconfig
sqlcipher.pc
编译适用于Qt的QSQLCIPHER驱动程序插件:
C:\Windows\System32\cmd.exe /A /Q /K C:\Qt\Qt5.4.0\5.4\mingw491_32\bin\qtenv2.bat
执行以下命令:
cd C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\pluins\sqldrivers\sqlcipher
qmake
mingw32-make
这将在以下目录中构建QSQLCIPHER驱动程序插件:C:\QT\QT5.4.0\5.4\SRC\QTBASE\PLUGINS\SQLDRIVERS
libqsqlcipher.a
libqsqlcipherd.a
qsqlcipher.dll
qsqlcipherd.dll
C:\Qt\Qt5.4.0\5.4\mingw491_32\plugins\sqldrivers
。创建一个新的加密 SQLite/SQLCipher 数据库
创建新的 SQLite 明文数据库 'plaintext.db' 并添加测试表和测试数据
更改目录为包含 'sqlcipher.exe' 和 'sqlite3.dll' 的目录 C:\sqlcipher
(参见上文)。
C:\sqlcipher>sqlcpher.exe plaintext.db
SQLCipher version 3.8.6 2014-08-15 11:46:33
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table testtable (id integer, name text);
sqlite> insert into testtable (id,name) values(1,'Bob');
sqlite> insert into testtable (id,name) values(2,'Charlie');
sqlite> insert into testtable (id,name) values(3,'Daphne');
sqlite> select * from testtable;
1|Bob
2|Charlie
3|Daphne
sqlite> .exit
C:\sqlcipher\plaintext.db
:加密明文数据库
这将使用密钥'testkey'创建数据库C:\sqlcipher\encrypted.db
。
C:\sqlcipher>sqlcipher.exe plaintext.db
SQLCipher version 3.8.6 2014-08-15 11:46:33
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'testkey';
sqlite> SELECT sqlcipher_export('encrypted');
sqlite> DETACH DATABASE encrypted;
sqlite> .exit
C:\sqlcipher\encrypted.db
:使用带有SQLCipher扩展和通过Qt访问的SQLite数据库
项目文件
QT += core sql
QT -= gui
TARGET = qsqlcipher
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
测试程序 'main.cpp'
#include <QCoreApplication>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>
#include <QString>
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLCIPHER");
db.setDatabaseName("C:/sqlcipher/encrypted.db");
db.open();
QSqlQuery q;
q.exec("PRAGMA key = 'testkey';");
q.exec("insert into testtable (id,name) values(4,'dummy')");
q.exec("SELECT id,name anz FROM testtable");
while (q.next()) {
QString id = q.value(0).toString();
QString name = q.value(1).toString();
qDebug() << "id=" << id << ", name=" << name;
}
db.close();
return 0;
}
编译和执行
("QSQLCIPHER", "QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
id= "1" , name= "Bob"
id= "2" , name= "Charlie"
id= "3" , name= "Daphne"
id= "4" , name= "dummy"
当发布一个 Qt 程序时,不要忘记 Qt 库、平台库、SQL 驱动插件 'qsqlcipher.dll' 和 OpenSSL 库 'libeay32.dll'。以上是测试程序的示例。C:\TEMP\QSQLCIPHER-TEST
| icudt53.dll
| icuin53.dll
| icuuc53.dll
| libeay32.dll
| libgcc_s_dw2-1.dll
| libstdc++-6.dll
| libwinpthread-1.dll
| qsqlcipher.exe
| Qt5Core.dll
| Qt5Sql.dll
|
+---platforms
| qminimal.dll
| qoffscreen.dll
| qwindows.dll
|
\---sqldrivers
qsqlcipher.dll
注意:测试程序包含密钥:...
q.exec("PRAGMA key = 'testkey';");
...
测试程序的二进制文件中的这个关键字符串可以使用十六进制编辑器轻松读取,我认为这是安全上的缺陷:
...
00002C90 70 68 65 72 2F 65 6E 63 72 79 70 74 65 64 2E 64 pher/encrypted.d
00002CA0 62 00 50 52 41 47 4D 41 20 6B 65 79 20 3D 20 27 b.PRAGMA key = '
00002CB0 74 65 73 74 6B 65 79 27 3B 00 00 00 69 6E 73 65 testkey';...inse
00002CC0 72 74 20 69 6E 74 6F 20 74 65 73 74 74 61 62 6C rt into testtabl
...
要解决这个问题,可以询问你自己选择的搜索引擎的方法。;-)
例如,搜索以下内容:在可执行文件中隐藏字符串
D:\Qt\5.5.1\5.5\src\qtbase\src\plugins\sqldrivers\sqlcipher>mingw32-make mingw32-make -f Makefile.Release all mingw32-make[1]: 进入目录 'D:/Qt/5.5.1/5.5/src/qtbase/src/plugins/sqldrivers/sqlcipher' mingw32-make[1]: *** 没有指定规则来制作目标“release/smain.moc”,需要“release/smain.o”。 停止。 mingw32-make[1]: 离开目录 'D:/Qt/5.5.1/5.5/src/qtbase/src/plugins/sqldrivers/sqlcipher' makefile:38: 目标“release-all”的规则失败 mingw32-make: *** [release-all] 错误 2
- H Aßdøµ