命令简单使用:
// 加密,将 test.db 加密后导出新的数据库 test_enc.db
user > sqlite3mc test.db
sqlite> ATTACH DATABASE 'test_enc.db' AS test_enc KEY 'xxxxxxxx'; --设置密码
sqlite> SELECT sqlcipher_export('test_enc');
sqlite> DETACH DATABASE test_enc;
sqlite> .exit// 解密,将 test_enc.db 设置为空密码后导出 test.db
user > sqlite3mc test_enc.db
sqlite> PRAGMA key = 'xxxxxxxx';
selite> select * from test_table; --sql语句
sqlite> ATTACH DATABASE 'test.db' AS test KEY ''; --空的密码不会加密数据库
sqlite> SELECT sqlcipher_export('test');
sqlite> DETACH DATABASE test;
sqlite> .exit
样例代码:
#include <cstdio>
#include <sqlite3.h>
#include <sqlite3mc.h>
#include <sqlite3mc_version.h>
#include <sqlite3mc_vfs.h>
#pragma comment(lib,"sqlite3mc_static_x64.lib")
int main() {sqlite3* db;sqlite3_open("test.db", &db);sqlite3_key(db, "111111", 6);sqlite3_exec(db, "create table person (id int, name vchar(50))", NULL, NULL, NULL);int i = sqlite3_exec(db, "insert into person (id,name) values (234,'quit')", NULL, NULL, NULL);printf("i=%d", i);sqlite3_close(db);
}