-->

Android using SQLCipher - how can you decrypt?

2019-05-01 11:49发布

问题:

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