sqlite命令行工具操作加密的数据库的步骤!(经验分享)

sqlite命令行工具操作加密的数据库的方法!(经验分享)
提供一些经验给搜索到这儿的同仁参考:

因为想验证自己做的加密版sqlite是否可用,所以准备用sqlite官方提供的shell命令行工具验证,但搜索网络没找到用这个命令行工具操作加密的数据库的方法,看了一篇文章,提供的方法是这样的

sqlite3 -key 123 foods.db

但是我发现-Key这个选项是不支持的,以为是公共区的源码中没有提供这个,所以自己动手修改了shell源码,添加了-key选项,可以使用了,但随后分析sqlite3.c源码就发现原来不是这样玩的,用pragma key=123;这个命令就可以了

[code=C/C++]
创建加密数据库:
D:\Projects\\Release>sqlite3 food.db
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> create table foods(id,name);
sqlite> insert into foods values(1,"apple");
sqlite> insert into foods values(1,"apple");
sqlite> .e

打开被加密的数据库:
D:\Projects\Release>sqlite3 food.db
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> select * from foods;
1|apple
1|apple
sqlite> .e

修改数据库密码:
D:\Projects\Release>sqlite3 food.db
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> pragma rekey=321;
sqlite> select * from foods;
1|apple
1|apple
sqlite> .e
[code=C/C++]

------解决方案--------------------
支持
------解决方案--------------------
学习!