Android using SQLCipher - how can you decrypt?

北城余情 提交于 2019-12-10 05:05:37

问题


I think this question has been asked, however I have tried several of the examples to no avail. My issue is this ... I have an Android app setup to use the SQLCipher DB encryption, which works fine, on the device.

In testing on an emulator, if I download the Database file using the DDMS, how do I read that file to check tables and data? I have tried using the command shell for SQLite3, and the ATTACH examples, however each time I do so, I just get the following message 'Error: file is encrypted or not a database'. This certainly shows that the ENCRYPT is working, but how I do I properly DECRYPT outside the emulator/eclipse?

Do I need a different SQLite client? Anyone else get stuck on this?

I a using: SQLCipher for Android 2.0.8 06/14/2012

Any help? Thanks


回答1:


The "normal" SQLite tools do not include SQLCipher.

You have to download the souce and compile it yourself to get a command shell with SQLCipher support.




回答2:


I resolved this by using this small script.

decrypt.sh

#!/bin/bash
# Bashscript to decrypt databases

echo "pull db from device.."
adb pull /data/data/com.example/databases/database.db

echo "removing previous decrypted db, if existent.."
rm -r decrypted_database.db

echo "decrypting database.db into decrypted_database.db"
sqlcipher -line database.db 'PRAGMA key = "encryption_key";ATTACH DATABASE "decrypted_database.db" AS decrypted_database KEY "";SELECT sqlcipher_export("decrypted_database");DETACH DATABASE decrypted_database;'

These programs should be added to your PATH:

  • adb
  • sqlcipher

Replace in script:

  • com.example with your packagename
  • database.db with name databasefile
  • encryption_key with encryption password


来源:https://stackoverflow.com/questions/12822104/android-using-sqlcipher-how-can-you-decrypt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!