sqlcipher自己編譯

2021-09-21 14:03:44 字數 2940 閱讀 5892

sqlcipher是sqlite的加密版本,提供源**,但是在編譯時,尤其是在編譯windows版本時,需要一些技巧。

fossil clone  sqlite.fossil
使用上述命令,將sqlite源**儲存到sqlite.fossil檔案。

fossil open sqlite.fossil
將當前最新版本展開到當前目錄下。

fossil update version-3.27.2
上面命令列,獲取3.27.2版本到當前目錄。

git clone
無論是sqlite還是sqlcipher,在linux上編譯都非常簡單。編譯sqlite,只需按照readme中的方法編譯即可。編譯sqlcipher,在linux(本人ubuntu)上測試,只需配置configure時,增加sqlite_has_codec和sqlite_temp_store=2,就可以正常編譯出有加密功能的sqlite3可執行檔案。

假設完成的sqlite源**儲存在./sqlite資料夾中,那麼,在當前路徑下,建立bld資料夾,cd到該資料夾中,執行如下命令。

mkdir bld

cd bld

nmake /f ..\sqlite\makefile.msc top=..\sqlite

nmake /f ..\sqlite\makefile.msc sqlite3.c top=..\sqlite

nmake /f ..\sqlite\makefile.msc sqlite3.dll top=..\sqlite

nmake /f ..\sqlite\makefile.msc sqlite3.exe top=..\sqlite

nmake /f ..\sqlite\makefile.msc test top=..\sqlite

tcc = $(tcc) -dsqlite_has_codec -dsqlite_temp_store=2

rcc = $(rcc) -dsqlite_has_codec -dsqlite_temp_store=2

tcc = $(tcc) -dsqlite_os_win=1 -i. -i$(top) -i$(top)\src -i"path to openssl include" -fp:precise

rcc = $(rc) -dsqlite_os_win=1 -i. -i$(top) -i$(top)\src -i"path to openssl include" $(rcopts) $(rccopts)

ltlibpaths = $(ltlibpaths) /libpath:'path to openssl lib'
libeay32.lib ssleay32.lib advapi32.lib user32.lib gdi32.lib

$(sqlite3dll):	$(libobj) $(libresobjs) $(core_link_dep)

$(ld) $(ldflags) $(ltlinkopts) $(ltlibpaths) /dll $(core_link_opts) /out:$@ $(libobj) $(libresobjs) $(ltlibs) $(tlibs) libeay32.lib ssleay32.lib advapi32.lib user32.lib gdi32.lib

$(sqlite3exe):	shell.c $(shell_core_dep) $(libresobjs) $(shell_core_src) $(sqlite3h)

$(ltlink) $(shell_compile_opts) $(readline_flags) shell.c $(shell_core_src) \

/link $(sqlite3exepdb) $(ldflags) $(ltlinkopts) $(shell_link_opts) $(ltlibpaths) $(libresobjs) $(libreadline) $(ltlibs) $(tlibs) libeay32.lib ssleay32.lib advapi32.lib user32.lib gdi32.lib

通過如上修改makefile.msc後,使用與sqlite相同的nmake指令,可以編譯出sqlite3.exe檔案

在命令列輸入sqlite3.exe,進入sqlite>命令列。輸入.help,顯示可以屬於的命令,都以.開頭。

c:\temp\sqlcipher-master\build>sqlite3.exe

sqlcipher version 3.27.2 2019-02-25 16:06:06

enter ".help" for usage hints.

connected to a transient in-memory database.

use ".open filename" to reopen on a persistent database.

sqlite> .open test.db

sqlite> .tables

sqlite> pragma key='hello' ;

sqlite> create table encrypted (id integer, name text);

sqlite> .tables

encrypted

sqlite> .schema

create table encrypted (id integer, name text);

sqlite> select * from encrypted;

sqlite> .q

上面是使用sqlcipher建立乙個空白表的示例。密碼為「hello」,使用二進位制檔案編輯器,開啟test.db檔案,發現檔案是加密後的無規律檔案。

使用TCC自己編譯自己

進行編譯之前需要先寫乙個bat處理檔案,儲存到tcc 0.9.26 build.bat路徑下,檔案 如下 echo 用tcc編譯tcc自己 set p version version echo config.h define tcc version version echo 設定tcc為c語言編譯器...

sqlcipher加密資料庫

個人部落格遷移,歡迎光臨 今天介紹乙個在之前公司用到的技術 發現文章一直在草稿箱裡沒發,今天發了 覺得還不錯,分享出來。在android開發中有時候需要對資料庫進行加密處理,不管這個資料庫是我們程式自己建立的還是我們自己從外部匯入的已經存在的資料庫,我們都有可能需要對它進行加密。加密方式無非兩種,一...

ios開發FMDB匯入SQLCipher加密資料庫

工程用得fmdb做資料庫的操作,後期要對資料庫做加密,這裡有兩種方法 1.對資料庫內容加密,存的時候加密,用得時候解密。2.直接對資料庫檔案加密。這裡我選擇了第二種,原因不細說,自己決定。不推薦。後來在fmdb官方發現了這個 即可以用cocoapods來安裝支援sqlcipher加密資料庫的fmdb...