sqlcipher的移植,sqlcipher移植
一、下載代碼
sqlcipher依賴openssl庫,首先下載openssl:
[fulinux@ubuntu ~]$ git clone https://github.com/openssl/openssl.git
下載sqlcipher:
網站:http://git.oschina.net/fulinux/sqlcipher.git或者https://github.com/sqlcipher/sqlcipher.git
[fulinux@ubuntu ~]$ git clone http://git.oschina.net/fulinux/sqlcipher.git
或者
[fulinux@ubuntu ~]$ git clone https://github.com/sqlcipher/sqlcipher.git
二、編譯
編譯openssl:
[fulinux@ubuntu openssl]$ ./config
[fulinux@ubuntu openssl]$ sudo make install
編譯sqlcipher:
[fulinux@ubuntu sqlcipher]$mkdir install
[fulinux@ubuntu sqlcipher]$./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" --prefix=$PWD/install && make install
如果遇到編譯問題,請checkout到發行版本
[fulinux@ubuntu sqlcipher]$git checkout v3.1.0
編譯成功後,工程根目錄的下install/bin/中有一個sqlcipher執行檔案,為了方便拷貝到工程根目錄下:
[fulinux@ubuntu sqlcipher]$ ls install/bin/sqlcipher
[fulinux@ubuntu sqlcipher]$ cp install/bin/sqlcipher .
三、測試
建立一個資料庫:
[fulinux@ubuntu sqlcipher]$ ./sqlcipher test.dbSQLCipher version 3.8.4.3 2014-04-03 16:53:12Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> PRAGMA KEY = '12345';sqlite> create table film (number,name);sqlite> insert into film values (1,'aaa');sqlite> insert into film values (2,'bbb');sqlite> select * from film;1|aaa2|bbbsqlite> .quit
開啟上面建立的資料庫:
[fulinux@ubuntu sqlcipher]$ ./sqlcipher test.dbSQLCipher version 3.8.4.3 2014-04-03 16:53:12Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> PRAGMA KEY = '12345';sqlite> .schemaCREATE TABLE film (number,name);sqlite> select * from film;1|aaa2|bbbsqlite>
錯誤測試:
[fulinux@ubuntu sqlcipher]$ ./sqlcipher test.dbSQLCipher version 3.8.4.3 2014-04-03 16:53:12Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> select * from film;Error: file is encrypted or is not a databasesqlite>
四、加密前後測試
用sqlite3查看資料:
[fulinux@ubuntu sqlite]$ sqlite3 test.db SQLite version 3.8.5 2014-06-04 14:06:34Enter ".help" for usage hints.sqlite> select * from test;1|hxl2|sqlite3|test4|for5|linuxsqlite>
用vim -b test.db,然後用xxd把檔案轉換成十六進位格式
:%!xxd
可以看到資料是沒有加密的,顯而易見:
00007d0: 0000 0805 0300 176c 696e 7578 0604 0300 .......linux....00007e0: 1366 6f72 0703 0300 1574 6573 7409 0203 .for.....test...00007f0: 0019 7371 6c69 7465 0601 0300 1368 786c ..sqlite.....hxl
再把這個沒有加密的test.db資料庫檔案通過sqlcipher轉換為加密格式的。
1、用sqlcipher或者sqlite開啟未加密的test.db檔案:
[fulinux@ubuntu sqlcipher]$ ./sqlcipher test.dbSQLCipher version 3.8.4.3 2014-04-03 16:53:12Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> select * from test;1|hxl2|sqlite3|test4|for5|linuxsqlite>
2、把資料導成sql格式檔案:
sqlite> .output test.sqlsqlite> .dumpsqlite> .exit
3、結合test.sql檔案產生一個加密的資料庫檔案test1.db:
[fulinux@ubuntu sqlcipher]$ ./sqlcipher test1.dbSQLCipher version 3.8.4.3 2014-04-03 16:53:12Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> PRAGMA key = 'test';sqlite> .read test.sqlsqlite> sqlite> select * from test;1|hxl2|sqlite3|test4|for5|linuxsqlite> .exit
4、匯入成功後,我們在用vim -b開啟test1.db資料庫檔案,可以認為你看到的基本上都是亂碼:
00001b0: 913c 52e4 5809 83b9 153a 8d5d 4b84 9715 .<R.X....:.]K...00001c0: a552 f8fb 9e3f 9637 4c9a 4b00 2259 a95b .R...?.7L.K."Y.[00001d0: 91d6 95da ce34 f9f2 5b05 2bea 439b 7cae .....4..[.+.C.|.00001e0: 1e60 333f 5323 21a9 989b a08a ad4f ea78 .`3?S#!......O.x
五、C代碼測試
編輯一個C代碼檔案test.c,代碼可以:
/********************************************************************************* * Copyright: (C) 2014 EAST * All rights reserved. * * Filename: test.c * Description: This file * * Version: 1.0.0(07/25/2014) * Author: fulinux <fulinux@sina.com> * ChangeLog: 1, Release initial version on "07/25/2014 05:15:05 PM" * ********************************************************************************/#include <stdio.h>#include <stdlib.h>#include <sqlite3.h>static int callback(void *notused, int argc, char **argv, char **azcolname){ int i; for(i = 0; i < argc; i++){ printf ("%s = %s\n", azcolname[i], argv[i]?argv[i]:"NULL"); } printf ("\n"); return 0;}/******************************************************************************** * Description: * Input Args: * Output Args: * Return Value: ********************************************************************************/int main (int argc, char **argv){ sqlite3 *db; char *zerrmsg = 0; int rc; if(argc != 3){ fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT\n", argv[0]); exit(0); } rc = sqlite3_open(argv[1], &db); if(rc){ fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); return 1; } sqlite3_key(db, "test", 4); rc = sqlite3_exec(db, argv[2], callback, 0, &zerrmsg); if(rc != SQLITE_OK){ fprintf(stderr, "SQL error: %s\n", zerrmsg); sqlite3_free(zerrmsg); } sqlite3_close(db); return 0;} /* ----- End of main() ----- */
代碼上面的代碼可以在這裡下載:
[fulinux@ubuntu ~]$ git clone http://git.oschina.net/fulinux/jupiter.git[fulinux@ubuntu jupiter]$ git checkout sqlcipher
編譯test.c檔案,因為庫和標頭檔都在/home/fulinux/sqlcipher/install目錄下,所以下面參數如下:
[fulinux@ubuntu jupiter]$ gcc -g test.c -o test -lsqlcipher -L /home/fulinux/sqlcipher/install/lib/ -I /home/fulinux/sqlcipher/install/include/sqlcipher/
執行測試程式:
[fulinux@ubuntu jupiter]$./test test1.db "select * from test;"id = 1value = hxlid = 2value = sqliteid = 3value = testid = 4value = forid = 5value = linux
相關網址:http://sqlcipher.net/sqlcipher-api/
author: fulinux
e-mail:fulinux@sina.com
blog: blog.csdn.net/fulinus
sql server 2000怎匯出可移植的資料庫
一般直接匯出就可以了,sql server 2000匯出的一般是.sql檔案。
mfc + sql server 2008 移植
不行,你可以將SQL Sever的資料來源那個host地址改成區域網路的地址可以,access是輕量級資料庫,可以直接移動mdb檔案完成資料庫的移植,SQL要移植有兩個辦法 建立區域網路,安裝SQL Sever重新在移植機上建立對應資料來源