sqlcipher 命令列使用及工具下載
sqlcipher 加密資料庫後想要檢視資料庫 ,需使用使用sqlcipher windows 命令工具
注意 使用的工具也分版本,要與加密資料庫的版本對應起來,否則檢視不到表
下載地址:
對應2.x
http://download.csdn.net/detail/zhanghw0917/7931759
3.01版本
http://download.csdn.net/detail/zhanghw0917/7931909
轉載 http://www.cnblogs.com/treecat-roboto/p/3873707.html
加密後使用命令列還是可以檢視滴
1. 建立加密資料庫
$ sqlcipher encrypted.db
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key = 'thisiskey';
sqlite> create table encrypted (id integer, name text);
sqlite> .schema
CREATE TABLE encrypted (id integer, name text);
sqlite> .q
2. 開啟加密資料庫
$ sqlcipher encrypted.db
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key = 'thisiskey';
sqlite> .schema
CREATE TABLE encrypted (id integer, name text);
3. 修改資料庫密碼
sqlite> PRAGMA rekey = 'newkey';
4. 加密已有的資料庫
$ sqlcipher banklist.sqlite3
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> ATTACH DATABASE 'encrypted.db' AS encrypted KEY 'thisiskey';
sqlite> SELECT sqlcipher_export('encrypted');
sqlite> DETACH DATABASE encrypted;
5. 解密資料庫
$ sqlcipher encrypted.db
SQLCipher version 3.8.4.3 2014-04-03 16:53:12
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA key = 'thisiskey';
sqlite> ATTACH DATABASE 'plaintext.db' AS plaintext KEY '';
sqlite> SELECT sqlcipher_export('plaintext');
sqlite> DETACH DATABASE plaintext;
轉自 : http://my.oschina.net/kjpioo/blog/149290
satckoverflow.com上有人提到過在
sqlite> sqlcipher-shell32.exe test.db
sqlite> PRAGMA KEY = '12345';
給剛開啟的資料庫設定密碼後,馬上接著往資料庫執行create table和 insert操作。最後用
sqlite> .e
退出該資料庫。但是下次再用
sqlite> sqlcipher-shell32.exe test.db
登入,在輸入密碼前執行了.schema等其他操作
sqlite>.schema
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資料庫,是一樣的道理
參考:
https://www.zetetic.net/sqlcipher/sqlcipher-api/#key
PRAGMA key
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.
Example 1: Passphrase with Key Derivation
The key itself can be a passphrase, which is converted to a key using PBKDF2 key derivation. The result is used as the encryption key for the database.
sqlite> PRAGMA key = 'passphrase';
Example 2: Raw Key Data (Without Key Derivation)
Alternatively, it is possible to specify an exact byte sequence using a blob literal. With this method, it is the calling application's responsibility to ensure that the data provided is a 64 character hex string, which will be converted directly to 32 bytes (256 bits) of key data.
sqlite> PRAGMA key = "x'2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99'";
Testing the Key
When opening an existing database, PRAGMA key
will not immediately throw an error if
the key provided is incorrect. To test that the database can be successfully opened with the provided key, it is necessary to perform some operation on the database (i.e. read from it) and confirm it is success.
The easiest way to do this is select off the sqlite_master table, which will attempt to read the first page of the database and will parse the schema.
sqlite> PRAGMA key = 'passphrase';
sqlite> SELECT count(*) FROM sqlite_master; -- if this throws an error, the key was incorrect. If it succeeds and returns a numeric value, the key is correct;
The same check can be implemented in C code
sqlite3_key(database, "test123", 7);
if (sqlite3_exec(database, "SELECT count(*) FROM sqlite_master;", NULL, NULL, NULL) == SQLITE_OK) {
// key is correct.
} else {
// key is incorrect
}
Implementation Notes
PRAGMA key
should generally be called as the first operation on a database.
相關文章
- modelscope 命令列工具下載模型命令列模型
- Linux 下十大命令列下載工具Linux命令列
- 如何在命令列下使用 BitTorrent 下載 ISO 映象命令列
- 使用SVN命令列工具命令列
- Windows下SVN命令列工具使用詳解(附加TortoiseSVN)Windows命令列
- Linux 命令列工具使用小貼士及技巧(1)Linux命令列
- Linux 命令列工具使用小貼士及技巧(4)Linux命令列
- Linux 命令列工具使用小貼士及技巧(3)Linux命令列
- Linux 命令列工具使用小貼士及技巧(四)Linux命令列
- Linux 命令列工具使用小貼士及技巧(2)Linux命令列
- 如何在命令列中使用 ftp 命令上傳和下載檔案命令列FTP
- windows下強大的wmic命令列工具Windows命令列
- linux下命令列json工具:jqLinux命令列JSON
- git在windows命令列下使用GitWindows命令列
- svn命令列工具安裝使用(windows)命令列Windows
- ftp下載工具,ftp下載工具哪個好用,如何使用?FTP
- 有趣的命令列工具-一行命令搜尋、下載圖片並設定成桌布命令列
- 下載工具使用總結
- mac下使用mysql控制檯命令列MacMySql命令列
- 使用node.js構建命令列工具Node.js命令列
- rtorrent ubuntu端命令列種子下載器Ubuntu命令列
- ROS命令列工具ROS命令列
- JDK的下載及安裝與Eclipse的下載及使用JDKEclipse
- ASM管理命令列三工具:KFOD、KFED和AMDU(下)ASM命令列
- Linux基礎命令---wget下載工具Linuxwget
- TortoiseSVN 命令 (命令列執行工具)命令列
- 在 Linux 命令列下使用“原力”Linux命令列
- MongoDB GridFS命令列工具mongofiles使用舉例MongoDB命令列
- 為什麼建議使用命令列工具?命令列
- 如何使用curl命令下載檔案
- 使用 openssl 命令列構建 CA 及證書命令列
- Click: 命令列工具神器命令列
- EFCore之命令列工具命令列
- windows命令列工具(轉)Windows命令列
- 5 個基於Linux命令列的檔案下載和網站瀏覽工具Linux命令列網站
- Linux 命令列下嗅探 HTTP 流量的工具:httpryLinux命令列HTTP
- [轉載]監控 Linux 效能的 18 個命令列工具Linux命令列
- 用 PHP 寫一個命令列音樂下載器PHP命令列