The process of creating a new, encrypted database is called “keying” the database. SQLCipher uses just-in-time key derivation at the point it is first needed for an operation. This means that the key (and any options) must be set before the first operation on the database. As soon as the database is touched (e.g. SELECT, CREATE TABLE, UPDATE, etc.) and pages need to be read or written, the key is prepared for use. web
satckoverflow.com上有人提到过在 sql
sqlite> sqlcipher-shell32.exe test.db shell
sqlite> PRAGMA KEY = '12345'; 数据库
给刚打开的数据库设置密码后,立刻接着往数据库执行create table和 insert操做。最后用 api
sqlite> .e 加密
退出该数据库。可是下次再用 spa
sqlite> sqlcipher-shell32.exe test.db .net
登陆,在输入密码前执行了.schema等其余操做 命令行
sqlite>.schema sqlite
Error: file is encrypted or is not a database
sqlite> PRAGMA KEY = '12345';
Error: file is encrypted or is not a database
遭到提示:Error: file is encrypted or is not a database
根据官方以上英文描述,这个问题就是由于操做上没有遵循just-in-time key derivation的要求,没有首先输密码解密再进行其余操做。
有图为证:
----------------如下为正确操做过程:
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 = '12345';
sqlite> .schema
CREATE TABLE t(name text);
sqlite> select * from t;
n1
sqlite>
----------------如下为错误操做过程:
Enter SQL statements terminated with a ";"
sqlite> .schema
Error: file is encrypted or is not a database
sqlite> PRAGMA KEY = '12345';
sqlite> .schema
Error: file is encrypted or is not a database
sqlite>
确实如此。
以上过程你能够本身亲自验证如下。
注意:经过命令行( sqlcipher-shell32.exe) 执行命令,与经过sqlite3 api调用操做sqlite3数据库,是同样的道理
本人文章除注明转载外,均为本人原创或编译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动共创开源社区
转载请注明:文章转载自:开源中国社区 [http://www.oschina.net]
本文标题:sqlite3 用SQLCipher 加密后 命令行下如何从新打开和读取
本文地址:http://my.oschina.net/kjpioo/blog/149290