用Sqlcipher給現有的SQLite資料庫加密
阿新 • • 發佈:2019-02-05
android專案資原始檔的破譯非常簡單,出於安全的考慮,要對sqlite檔案進行加密處理,用到了SQLCipher,他有收費版和開源版,這裡選擇開源版。
PS:網上的Sqlcipher版本大多是需要編譯的版本,使用起來非常不方便,這裡推薦一款windows下直接使用的版本,下載連結:
http://download.csdn.net/detail/cx118118/9676383
E:\sqlciper\bin>sqlcipher-shell64.exe info.db
SQLCipher version 3.8.0.2 2013-09-03 17:11:13
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .table
info
這裡通過Sqlcipher開啟info.db資料庫可以正常開啟,也能夠檢視資料。
加密這個資料庫:
第一步,匯出資料庫內容到sql檔案中
sqlite> .output my.sql ##備份原始資料
sqlite> .dump
sqlite> .exit
第二步,建立帶密碼的加密資料庫
E:\sqlciper\bin>sqlcipher-shell64.exe e_info.db
SQLCipher version 3.8.0.2 2013-09-03 17:11:13
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key='xxxx'; ##設定密碼
第三步,將sql檔案匯入到加密資料庫中
sqlite> .read my.sql ##匯入原始資料
sqlite> .exit
此時,資料庫e_info.db已經被加密,通過SQLite3無法開啟,只有通過Sqlcipher輸入密碼方可開啟。