sqlcipher的移植

sqlcipher的移植,第1张

概述一、下载代码 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依赖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 .

三、测试

新建一个@R_301_6948@:

[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
打开上面创建的@R_301_6948@:
[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@R_301_6948@文件通过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文件生成一个加密的@R_301_6948@文件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@R_301_6948@文件,可以认为你看到的基本上都是乱码:
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,&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

总结

以上是内存溢出为你收集整理的sqlcipher的移植全部内容,希望文章能够帮你解决sqlcipher的移植所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/sjk/1172024.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存