打开微信加密数据库

微信 Android 数据库使用 SqlCipher 加密, 从代码来看, 是使用 sqlcipher 1 版本,

1
2
private static final SQLiteCipherSpec qDP = 
new SQLiteCipherSpec().setPageSize(1024).setSQLCipherVersion(1);

使用诸如 DB Browser for SQLite , SQLiteStudio 等数据库管理软件都无法直接打开, 主要原因是连接参数不正确.

查看 SQLCipher 的源码发现设置 CipherVersion 为 1 时 , 会关闭 hmac, kdf_iter 为 4000.

1
2
3
4
5
6
7
8
9
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 来建立链接, 还是失败 配置如下.

1
2
3
4
PRAGMA kdf_iter = '4000';
PRAGMA cipher_use_hmac = OFF;
PRAGMA cipher = 'AES-256-CBC';
PRAGMA cipher_page_size = 1024;

查阅官方文档后发现有如下介绍:

PRAGMA cipher_compatibility: Force SQLCipher to operate with default settings consistent with that major version number for the current connection.

大概是说通过 PRAGMA cipher_compatibility 配置 , 设置这个版本号后, 会自动使用该版本默认的配置链接, 这样避免我们设置那些乱七八糟的配置.

1
2
PRAGMA cipher_page_size = 1024;
PRAGMA cipher_compatibility = 1

测试发现, OK~ 如下图.

success result

作者

sadhu

发布于

2021-12-25

更新于

2021-12-25

许可协议