因为想验证自己做的加密版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++]
5 个解决方案
#1
支持
#2
学习!
#3
赞!!!
#4
C:\>sqlite.exe test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
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> .e
C:\>sqlite.exe test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> select * from foods;
Error: file is encrypted or is not a database
sqlite>
//文件加密后,再次使用密码就无法打开文件了。 请楼主帮忙看看 谢谢
SQLite version 3.7.15.2 2013-01-09 11:53:05
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> .e
C:\>sqlite.exe test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> select * from foods;
Error: file is encrypted or is not a database
sqlite>
//文件加密后,再次使用密码就无法打开文件了。 请楼主帮忙看看 谢谢
#5
谢谢,正式我想要的
#1
支持
#2
学习!
#3
赞!!!
#4
C:\>sqlite.exe test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
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> .e
C:\>sqlite.exe test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> select * from foods;
Error: file is encrypted or is not a database
sqlite>
//文件加密后,再次使用密码就无法打开文件了。 请楼主帮忙看看 谢谢
SQLite version 3.7.15.2 2013-01-09 11:53:05
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> .e
C:\>sqlite.exe test.db
SQLite version 3.7.15.2 2013-01-09 11:53:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma key=123;
sqlite> select * from foods;
Error: file is encrypted or is not a database
sqlite>
//文件加密后,再次使用密码就无法打开文件了。 请楼主帮忙看看 谢谢
#5
谢谢,正式我想要的