sqlite3开源加密方案-wxsqlite3

sqlite3免费版本是不提供加密功能的,但是预留了加密的接口。

截至2020年8月,wxsqlite3最新版本是4.6.0,支持的最新sqlite3版本是3.31.1。

github地址:https://github.com/utelle/wxsqlite3

 

用visual studio 2019打开  .\wxsqlite3\sqlite3secure\build\SQLite3Secure_vc16_lib.vcxproj

编译生成sqlite3.lib,位置.\wxsqlite3\sqlite3secure\bin-vc16\lib\debug\sqlite3.lib

 

修改sqlite3.h,第一行添加

#define SQLITE_HAS_CODEC

 

用visual studio 2019新建一个空的c++工程,把把sqlite3.lib、sqlite3.h放置于和源代码同一目录,main.cpp内容如下:

 

#include "sqlite3.h"

#pragma comment(lib,"sqlite3.lib")

int main() {
	sqlite3* db;
	sqlite3_open("test.db", &db);
	sqlite3_key(db, "123456", 6);
	sqlite3_exec(db, "create table person (id int, name vchar(50))", NULL, NULL, NULL);
	sqlite3_close(db);
} 

运行该exe,就会生成一个加密的sqlite3数据库文件。

如果需要删除db文件的密码,用sqlite3_rekey这个函数。执行这个函数前需要先用sqlite3_key验证密码。

 

#include "sqlite3.h"

#pragma comment(lib,"sqlite3.lib")

int main() {
	sqlite3* db;
	sqlite3_open("test.db", &db);
	sqlite3_key(db, "123456", 6);
	sqlite3_rekey(db, NULL, 0);
	sqlite3_close(db);
}
posted @ 2020-08-15 14:46  sherlock-merlin  阅读(1715)  评论(0编辑  收藏  举报