【问题标题】:Sqlite database encryption with wxsqlite3 run time error使用 wxsqlite3 运行时错误的 Sqlite 数据库加密
【发布时间】:2018-09-16 21:27:20
【问题描述】:

我从here(wxSQLite3 3.5.9) 下载了预构建的二进制文件,还下载了sqlite3.h 文件版本3.21.0,我将头文件和.dll.lib 文件添加到我的项目中。

我复制了 32 位版本的 dll 和 lib 文件,并将它们复制到我的解决方案中,并将 .lib 文件添加到项目属性中 Linker->Input 中的 Additional Dependencies

我用 C++ 创建了这个示例应用程序:

#define SQLITE_HAS_CODEC
#include "sqlite3.h"
#include <string>
#include <iostream>

using namespace std;

int main()
{
    sqlite3* db;
    sqlite3_open("test1.db", &db);

    sqlite3_key(
        db, /* Database to be rekeyed */
        "test", sizeof("test") /* The key, and the length of the key in bytes */
    );

    std::string createQuery =
        "CREATE TABLE IF NOT EXISTS items (userid INTEGER PRIMARY KEY, ipaddr       TEXT, username TEXT, useradd TEXT, userphone INTEGER, age INTEGER, "
        "time TEXT NOT NULL DEFAULT (NOW()));";

    sqlite3_stmt* createStmt;
    std::cout << "Creating Table Statement" << endl;
    sqlite3_prepare(db, createQuery.c_str(), createQuery.size(), &createStmt, NULL);
    cout << "Stepping Table Statement" << endl;
    if (sqlite3_step(createStmt) != SQLITE_DONE) cout << "Didn't Create Table!" << endl;

    string insertQuery =
        "INSERT INTO items (time, ipaddr,username,useradd,userphone,age) VALUES('7:30', '192.187.27.55', 'vivekanand', 'kolkatta', '04456823948', 74);";
    // WORKS!
    sqlite3_stmt* insertStmt;
    cout << "Creating Insert Statement" << endl;
    sqlite3_prepare(db, insertQuery.c_str(), insertQuery.size(), &insertStmt, NULL);
    cout << "Stepping Insert Statement" << endl;
    if (sqlite3_step(insertStmt) != SQLITE_DONE) cout << "Didn't Insert Item!" << endl;

    return 0;
}

当我运行这个程序时,我在运行时收到这个错误:

但是如果我评论这部分代码

sqlite3_key(
            db, /* Database to be rekeyed */
            "test", sizeof("test") /* The key, and the length of the key in bytes */
        );

它工作得很好,我做错了什么?

【问题讨论】:

  • 您购买了 SQLite 的加密扩展吗?它不是免费产品,也不是主要 SQLite API 的一部分。
  • 这里有一个开源实现github.com/utelle/wxsqlite3
  • 我认为这只是 SQLite 扩展的包装器。这意味着您仍然应该为扩展本身付费。只需在 github 项目上询问 Ulrich 即可。就像 wxSQLite3 是 SQLite API 的包装器一样。
  • @Igor 这个存储库如何声称是开源的 sqlite 加密库? github.com/rindeal/SQLite3-Encryption 它使用了 wxSqlite 的一部分(基本上使编译更容易)
  • @Igor 在回购的描述中说wxSQLite3 - SQLite3 database wrapper for wxWidgets (including SQLite3 encryption extension)

标签: c++ encryption sqlite wxwidgets dynamic-linking


【解决方案1】:

C/C++ 代码似乎没问题。如果可以正确编译测试应用程序,则显然使用了有效的链接库。但是,运行时错误消息表明未加载正确的 DLL。

这表示预编译的 SQLite DLL 没有复制到测试应用程序的可执行文件所在的同一目录中,或者它不在应用程序的搜索路径中。但是,在搜索路径中找到了一些 SQLite DLL,但很可能是不包含加密扩展的“官方”SQLite DLL。

确保测试应用程序可以访问包含加密扩展的 SQLite DLL。

wxSQLite3 版本的预编译二进制文件肯定包括入口点 sqlite3_key 和 sqlite3_rekey。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 2011-06-25
    相关资源
    最近更新 更多