微信Android 數(shù)據(jù)庫使用SqlCipher加密, 從代碼來看, 是使用sqlcipher 1 版本,
private static final SQLiteCipherSpec qDP =
new SQLiteCipherSpec().setPageSize(1024).setSQLCipherVersion(1);
使用諸如 DB Browser for SQLite , SQLiteStudio 等數(shù)據(jù)庫管理軟件都無法直接打開, 主要原因是連接參數(shù)不正確.
查看 SQLCipher 的源碼發(fā)現(xiàn)設(shè)置 CipherVersion 為 1 時(shí) , 會(huì)關(guān)閉 hmac, kdf_iter 為 4000.
public SQLiteCipherSpec setSQLCipherVersion(int version) {
switch (version) {
case 1: hmacEnabled = false; kdfIteration = 4000; break;
case 2: hmacEnabled = true; kdfIteration = 4000; break;
case 3: hmacEnabled = true; kdfIteration = 64000; break;
default: throw new IllegalArgumentException("Unsupported SQLCipher version: " + version);
}
return this;
}
在嘗試 SQLiteStudio 配合 Cipher configuration 來建立鏈接, 還是失敗 配置如下.
PRAGMA kdf_iter = '4000';
PRAGMA cipher_use_hmac = OFF;
PRAGMA cipher = 'AES-256-CBC';
PRAGMA cipher_page_size = 1024;
查閱官方文檔后發(fā)現(xiàn)有如下介紹:
PRAGMA cipher_compatibility: Force SQLCipher to operate with default settings consistent with that major version number for the current connection.
大概是說通過PRAGMA cipher_compatibility配置 , 設(shè)置這個(gè)版本號(hào)后, 會(huì)自動(dòng)使用該版本默認(rèn)的配置鏈接, 這樣避免我們?cè)O(shè)置那些亂七八糟的配置,將下列配置粘貼到工具中的加密算法配置選項(xiàng)中
PRAGMA cipher_page_size = 1024;
PRAGMA cipher_compatibility = 1;
測(cè)試發(fā)現(xiàn), OK~ 如下圖.

MacBook使用SQLiteStudio鏈接微信加密數(shù)據(jù)庫.jpg
轉(zhuǎn)自:打開微信加密數(shù)據(jù)庫