linux使用sqlcipher解密sqlite

微信数据库便是使用这种加密方式,因此可以用来解密微信数据库

安装sqlicipher

直接安装

1
apt-get install sqlcipher

使用源码编译

下载源代码

1
git clone https://github.com/sqlcipher/sqlcipher.git

定义 SQLITE_HAS_CODEC和SQLITE_TEMP_STORE=2

1
2
export SQLITE_HAS_CODEC
export SQLITE_TEMP_STORE=2

安装openssl和tcl

1
2
sudo yum install openssl
sudo yum install tcl

进入sqlcipher源码目录进行编译

1
2
3
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto"
make
make install

编译成功

1
2
[root@localhost sqlcipher]# sqlcipher --version
3.11.0 2016-02-15 17:29:24 3d862f207e3adc00f78066799ac5a8c282430a5f

解密sqlite文件

1
sqlcipher EnMicroMsg.db 'PRAGMA key = "key"; PRAGMA cipher_use_hmac = off; PRAGMA kdf_iter = 4000; ATTACH DATABASE "decrypted_database.db" AS decrypted_database KEY "";SELECT sqlcipher_export("decrypted_database");DETACH DATABASE decrypted_database;'

或者

1
sqlcipher EnMicroMsg.db 'PRAGMA key = "key"; PRAGMA cipher_migrate; ATTACH DATABASE "decrypted_database.db" AS decrypted_database KEY "";SELECT sqlcipher_export("decrypted_database");DETACH DATABASE decrypted_database;'

解密得到可用sqlite3打开的decrypted_database.db。

蔡小木 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!