5

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

Hunter23
  • 195
  • 4
  • 11
  • And what are you using on your development machine? – CommonsWare Oct 10 '12 at 14:44
  • As in to try and read the encrypted file or for the Android development? I have tried SQLiteStudio v2.0.28 / SQLite command shell 3.7.14.1 / and SQLite Manager for Firefox. Dev. environment is Eclipse Juno, targeting Android min. API 8 for Android 2.2. – Hunter23 Oct 10 '12 at 14:58
  • And do any of those advertise that they have SQLCipher support? – CommonsWare Oct 10 '12 at 15:00
  • Yes, The SQLite command shell specifically shows examples for ATTACHing to SQLCipher encrypted DBs: http://sqlcipher.net/sqlcipher-api#attach – Hunter23 Oct 10 '12 at 15:05
  • possible duplicate of [file is encrypted or is not a database (Exception net.sqlcipher.database.SQLiteException)](http://stackoverflow.com/questions/22062277/file-is-encrypted-or-is-not-a-database-exception-net-sqlcipher-database-sqlitee) – Maveňツ Aug 05 '14 at 06:28
  • see this - http://stackoverflow.com/questions/25132477/how-to-decrypt-an-encrypted-sqlcipher-database-file-on-command-line/ – Vinay W Aug 05 '14 at 06:33

2 Answers2

4

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.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • Ah, so to be clear - the 'Community' version can be added into an Android project and work just fine within the project; however to integrate into a SQLite client you would need to purchase the 'Commercial' version for those binaries to compile? Or can the 'Community' version be compiled into the existing shell? – Hunter23 Oct 10 '12 at 15:28
  • Addition: thanks for the compile link, I'll work through that to see if I can get this working. So far that looks like what I need. So much for having a quick/easy solution available. I'll add comment if I get stuck. Thanks!!! – Hunter23 Oct 10 '12 at 15:31
3

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:

Replace in script:

  • com.example with your packagename
  • database.db with name databasefile
  • encryption_key with encryption password
Community
  • 1
  • 1
Tobrun
  • 18,291
  • 10
  • 66
  • 81