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