本文介绍了如何使用Windows / MinGW平台使用SQLCipher扩展为SQLite-DB构建Qt-SQL驱动程序插件“QSQLCIPHER”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这不是一个问题,在哪里可以找到分步指南,而是指导本身。 我的这个职位的目的是给别人一个提示,谁有同样的问题在最近刚刚编写的驱动程序插件。 如何使用Windows / MinGW平台,使用SQLCipher扩展为SQLite-DB构建Qt-SQL驱动程序插件QSQLCIPHER? 解决方案 如何使用Windows / MinGW使用SQLCipher扩展为SQLite-DB构建Qt-SQL驱动程序插件QSQLCIPHER -platform: Qt 5.4.0 for Windows / MinGW 下载Qt 安装包括源代码例如 C:\Qt\Qt5.4.0 Windows的OpenSSL 下载Win32 OpenSSL v1.0.2a 下载Visual C ++ 2008可重新分发 通过执行vcredist_x86.exe安装Visual C ++ 2008 Redistributable ' 通过执行'Win32OpenSSL-1_0_2.exe'安装OpenSSL v1.0.2a 目标目录 C:\OpenSSL-Win32 在安装过程中,选择将库安装到Windows系统目录( C:\Windows\SysWOW64 ) MinGW - Windows的Minimalist GNU 下载并安装mingw-get-setup.exe 启动MinGW安装程序 安装MSYS基本系统 选择:所有包 - > MSYS - > MSYS基本系统 选择要安装的msys-base(类'bin') 菜单:安装 - >应用更改 默认安装文件到目录 C:\MinGW 安装Tcl / Tk 选择:所有包 - > MinGW - > MinGW贡献 选择'mingw32-tcl'和'mingw32-tk'(类'bin')进行安装 菜单:安装 - > apply chang es 默认情况下将文件安装到目录 C:\MinGW / li> 将内容 C:\MinGW 复制到Qt-MinGW目录 C:\Qt\Qt5.4.0\Tools\mingw491_32 创建文件'fstab' code> C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\etc 插入内容如下: #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 下载zlib-dll-binaries 将文件'zlib1.dll'提取并复制到Qt-MinGW-目录 C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\bin SQLCipher 下载SQLCipher-zip文件 提取zip文件,例如到 C:\temp\sqlcipher-master 复制OpenSSL-Win32-libraries 复制 C:\OpenSSL-Win32\bin\libeay32.dll 到 C:\temp \sqlcipher-master 复制 C:\OpenSSL-Win32\lib\libeay32.lib 到 C:\temp\sqlcipher-master p>构建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-libgccLDFLAGS = - 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 。 文件'sqlcipher.exe'是相当于非crypting原始命令行界面'sqlite3.exe'的秘密。 复制 C:\\ \\temp\sqlcipher-master\sqlite3.dll 到 C:\sqlcipher 。 这个文件是SQLite-library通过加密扩展。 具有SQLCipher扩展名的SQLite数据库现在可以上班了。 b $ b 构建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//在该行末尾有一个缺失 QT_BEGIN_NAMESPACE class QSQLcipherDriverPlugin:public QSqlDriverPlugin { Q_OBJECT Q_PLUGIN_METADATA(IIDorg.qt-project.Qt.QSqlDriverFactoryInterfaceFILEsqlcipher.json) public: QSQLcipherDriverPlugin(); QSqlDriver * create(const QString&); }; QSQLcipherDriverPlugin :: QSQLcipherDriverPlugin():QSqlDriverPlugin b $ b {} QSqlDriver * QSQLcipherDriverPlugin :: create(const QString& name) { if(name == QLatin1String(QSQLCIPHER)){ QSQLiteDriver * driver = new QSQLiteDriver(); return driver; } return 0; } QT_END_NAMESPACE #includesmain.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 {键:[QSQLCIPHER] } 复制目录 C:\Qt\Qt5.4.0\\ \\5.4\Src\qtbase\src\sql\drivers\sqlite to 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)#< - 将sqlite.pri的路径更改为sqlcipher.pri这里! } else { LIBS + = $$ QT_LFLAGS_SQLITE QMAKE_CXXFLAGS * = $$ QT_CFLAGS_SQLITE } 此目录中的其余两个文件不需要更改。 在目录 C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty 包含以下内容: $ $ $ $ $ $ $ $))))))))))))))))))))))))))SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_RTREE SQLITE_HAS_CODEC !contains(CONFIG,largefile) :DEFINES + = SQLITE_DISABLE_LFS 包含(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\\ $ s code code $ c以下文件到 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 复制以下文件/ direc tory to 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驱动程序插件: 打开Qt命令行 C:\Windows\System32\cmd.exe / A / Q /KC:\Qt\Qt5.4.0\5.4\mingw491_32\bin\qtenv2.bat 执行以下命令: cd C: $ \\ $ > 这将在以下目录中构建QSQLCIPHER-driver-plugin: C:\QT\QT5.4.0\5.4\SRC\QTBASE\PLUGINS\SQLDRIVERS libqsqlcipher.a libqsqlcipherd.a qsqlcipher.dll qsqlcipherd.dll 复制'qsqlcipher.dll'和'qsqlcipherd .dll'到SQL-driver-plugin目录 C:\Qt\Qt5.4.0\5.4\mingw491_32\plugins\sqldrivers 。 创建一个新的加密SQLite / SQLCipher数据库 使用测试表和一些测试数据创建新的SQLite-Plaintext-data'plaintext.db' 将目录更改为 C:\sqlcipher ,其中包含'sqlcipher.exe'和'sqlite3.dll'(见上文)。 $ b code code code $ c $ b输入.help作为说明输入以;结尾的SQL语句 sqlite> create table testtable(id integer,name text); sqlite>插入testtable(id,name)值(1,'Bob'); sqlite>插入testtable(id,name)值(2,'Charlie'); sqlite>插入testtable(id,name)值(3,'Daphne'); sqlite> select * from testtable; 1 | Bob 2 | Charlie 3 | Daphne sqlite> .exit 打开 C:\sqlcipher\plaintext.db 使用标准文本编辑器: 数据库方案和测试数据可以用明文读取。 加密明文数据库 这将创建数据库 C:\sqlcipher\encrypted.db 使用键' testkey'。 C:\sqlcipher> sqlcipher.exe plaintext.db SQLCipher版本3.8.6 2014- 08-15 11:46:33 为说明输入.help输入以;结尾的SQL语句 sqlite> ATTACH DATABASE'encrypted.db'AS加密的KEY'testkey'; sqlite> SELECT sqlcipher_export('encrypted'); sqlite> DETACH DATABASE加密; sqlite>打开 C:\sqlcipher\encrypted.db 使用标准文本编辑器: 数据现在已加密。 有关更多实用信息,请访问: https://www.zetetic.net/sqlcipher/sqlcipher-api/ 使用SQLCipher扩展和使用Qt访问的SQLite数据库 创建一个新的Qt命令行项目,例如'qsqlcipher' 项目文件 QT + = core sql QT - = gui TARGET = qsqlcipher CONFIG + = console CONFIG - = app_bundle TEMPLATE = app SOURCES + = main.cpp 测试程序'main.cpp' #include #include< QSqlDatabase> #include< QSqlQuery> #include< QDebug> #include< QString> int main(int argc,char * argv []){ QCoreApplication a(argc,argv); qDebug()<< QSqlDatabase ::驱动程序(); 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 } db.close(); return 0; } 编译并执行 $ $ $ $ $$$ Q $$$ Q $$$ Q $$$ Q $ b id =1,name =Bob id =2,name =Charlie id =3,name =Daphne id =4 ,name =dummy 发送Qt程序时不要忘记Qt图书馆,平台库,SQL-driver-plugin'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 | + ---平台 | 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进入testtabl ... 对于如何解决这个问题的方法,请问搜索引擎你自己的选择;-) 例如搜索:在可执行文件中隐藏字符串 This is not typically a question where to find a step-by-step guide, but rather the guide itself.My intention with this post is to give others a hint, who have the same problems in compiling the driver-plugin as I just had recently.How to build the Qt-SQL-driver-plugin 'QSQLCIPHER' for SQLite-DB with SQLCipher-extension using the Windows/MinGW-platform? 解决方案 How to build the Qt-SQL-driver-plugin 'QSQLCIPHER' for SQLite-DB with SQLCipher-extension using the Windows/MinGW-platform:Qt 5.4.0 for Windows/MinGWDownload QtInstall including the sources e.g to C:\Qt\Qt5.4.0OpenSSL for WindowsDownload Win32 OpenSSL v1.0.2aDownload Visual C++ 2008 RedistributableInstall Visual C++ 2008 Redistributable by executing 'vcredist_x86.exe'Install OpenSSL v1.0.2a by executing 'Win32OpenSSL-1_0_2.exe'Target directory e.g. C:\OpenSSL-Win32During installation choose the option to install the libraries to the Windows system directory (C:\Windows\SysWOW64)MinGW - Minimalist GNU for WindowsDownload and install 'mingw-get-setup.exe'Start of MinGW InstallerInstallation of MSYS Base SystemSelection: All Packages -> MSYS -> MSYS Base SystemSelect msys-base (Class 'bin') for installationMenu: installation -> apply changesInstallation of files by default to directory C:\MinGWInstallation of Tcl/TkSelection: All Packages -> MinGW -> MinGW ContributedSelect 'mingw32-tcl' and 'mingw32-tk' (Class 'bin') for installationMenu: installation -> apply changesInstallation of files by default to directory C:\MinGWCopy content of C:\MinGW to the Qt-MinGW-directory C:\Qt\Qt5.4.0\Tools\mingw491_32Create file 'fstab' in C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\etcInsert content as follows:#Win32_Path Mount_PointC:/Qt/Qt5.4.0/Tools/mingw491_32 /mingwC:/Qt/Qt5.4.0/5.4 /qtC:/ /czlib-LibraryDownload zlib-dll-BinariesExtract and copy file 'zlib1.dll' to the Qt-MinGW-directory C:\Qt\Qt5.4.0\Tools\mingw491_32\msys\1.0\binSQLCipherDownload the SQLCipher-zip-fileExtract the zip-file e.g. to C:\temp\sqlcipher-masterCopy OpenSSL-Win32-librariesCopy C:\OpenSSL-Win32\bin\libeay32.dll to C:\temp\sqlcipher-masterCopy C:\OpenSSL-Win32\lib\libeay32.lib to C:\temp\sqlcipher-masterBuild SQLCipher.exeExecute 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 installSave the executable SQLite/SQLCipher-database e.g. to C:\sqlcipherCopy C:\temp\sqlcipher-master\dist\bin\sqlcipher.exe to C:\sqlcipher.The file 'sqlcipher.exe' is the crypting equivalent to the non-crypting original command line interface 'sqlite3.exe'.Copy C:\temp\sqlcipher-master\sqlite3.dll to C:\sqlcipher.This file is the SQLite-library extended by the encryption.The SQLite-database with SQLCipher-extension is now ready for work.Build Qt-QSQLCIPHER-driver-pluginCreate directory:C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\plugins\sqldrivers\sqlcipherCreate the following three files within the new directory:File 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 lineQT_BEGIN_NAMESPACEclass 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"File 2: sqlcipher.proTARGET = qsqlcipherSOURCES = smain.cppOTHER_FILES += sqlcipher.jsoninclude(../../../sql/drivers/sqlcipher/qsql_sqlite.pri)wince*: DEFINES += HAVE_LOCALTIME_S=0PLUGIN_CLASS_NAME = QSQLcipherDriverPlugininclude(../qsqldriverbase.pri)File 3: sqlcipher.json{ "Keys": [ "QSQLCIPHER" ]}Copy directory C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\sql\drivers\sqliteto C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\sql\drivers\sqlcipherCustomize file C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\sql\drivers\sqlcipher\qsql_sqlite.priThe content of the file shall be like:HEADERS += $$PWD/qsql_sqlite_p.hSOURCES += $$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}The remaining two files in this directory need not to be changed.Create file 'sqlcipher.pri' in directory C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty with following content:CONFIG(release, debug|release):DEFINES *= NDEBUGDEFINES += 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_LFScontains(QT_CONFIG, posix_fallocate):DEFINES += HAVE_POSIX_FALLOCATE=1winrt: DEFINES += SQLITE_OS_WINRTwinphone: DEFINES += SQLITE_WIN32_FILEMAPPING_API=1qnx: DEFINES += _QNX_SOURCEINCLUDEPATH += $$PWD/sqlcipher c:/openssl-win32/includeSOURCES += $$PWD/sqlcipher/sqlite3.cLIBS += -L$$PWD/sqlcipher/lib -lsqlcipher -leay32 -lsqlite3TR_EXCLUDE += $$PWD/*Create and fill C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipherCreate the two directories:C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipherC:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher\libCopy the following files to C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher:C:\temp\sqlcipher-master\shell.cC:\temp\sqlcipher-master\sqlite3.cC:\temp\sqlcipher-master\sqlite3.hC:\temp\sqlcipher-master\sqlite3ext.hCopy the following files/directories to C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\3rdparty\sqlcipher\lib:C:\temp\sqlcipher-master\dist\libC:\temp\sqlcipher-master\sqlite3.dllC:\OpenSSL-Win32\bin\libeay32.dllThe directory now consists of the following files and directories: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.pcCompile the QSQLCIPHER-driver-plugin for Qt:Open Qt-command line C:\Windows\System32\cmd.exe /A /Q /K C:\Qt\Qt5.4.0\5.4\mingw491_32\bin\qtenv2.batExecute the following commands:cd C:\Qt\Qt5.4.0\5.4\Src\qtbase\src\pluins\sqldrivers\sqlcipherqmakemingw32-makeThis builds the QSQLCIPHER-driver-plugin within the following directory:C:\QT\QT5.4.0\5.4\SRC\QTBASE\PLUGINS\SQLDRIVERS libqsqlcipher.a libqsqlcipherd.a qsqlcipher.dll qsqlcipherd.dllCopy 'qsqlcipher.dll' and 'qsqlcipherd.dll' to the SQL-driver-plugin-directory C:\Qt\Qt5.4.0\5.4\mingw491_32\plugins\sqldrivers.Create a new encrypted SQLite/SQLCipher-databaseCreate new SQLite-Plaintext-database 'plaintext.db' with a test table and some test dataChange directory to C:\sqlcipher, which contains 'sqlcipher.exe' and 'sqlite3.dll' (see above).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> .exitOpen C:\sqlcipher\plaintext.db using a standard text-editor:Database scheme and test data can be read in plaintext.Encrypting the plaintext-databaseThis will create the database C:\sqlcipher\encrypted.db using the key 'testkey'.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> .exitOpen C:\sqlcipher\encrypted.db using a standard text-editor:Data are now encrypted.For more useful information visit:https://www.zetetic.net/sqlcipher/sqlcipher-api/Usage of the SQLite-database with SQLCipher-extension and access via QtCreate a new Qt-command-line-project e.g. 'qsqlcipher'Project fileQT += core sqlQT -= guiTARGET = qsqlcipherCONFIG += consoleCONFIG -= app_bundleTEMPLATE = appSOURCES += main.cppTest-program '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;}Compile and execute("QSQLCIPHER", "QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")id= "1" , name= "Bob"id= "2" , name= "Charlie"id= "3" , name= "Daphne"id= "4" , name= "dummy"When delivering a Qt-program do not forget the Qt-libraries, the platforms-libraries, SQL-driver-plugin 'qsqlcipher.dll' and the OpenSSL-library 'libeay32.dll'.Example for the test program above: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.dllCaution: The test program contains the key:...q.exec("PRAGMA key = 'testkey';");...This key string in the binary file of the test program can easiliy be read using a hex-editor, which is, to my opinion, a lack in security:...00002C90 70 68 65 72 2F 65 6E 63 72 79 70 74 65 64 2E 64 pher/encrypted.d00002CA0 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';...inse00002CC0 72 74 20 69 6E 74 6F 20 74 65 73 74 74 61 62 6C rt into testtabl...For approaches how to solve this problem, ask the search engine of your own choice. ;-)E.g. search for: hide string in executable 这篇关于如何使用Windows / MinGW平台使用SQLCipher扩展为SQLite-DB构建Qt-SQL驱动程序插件“QSQLCIPHER”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 阿里云证书,YYDS! 05-22 20:38