Android using SQLCipher - how can you decrypt?
Asked Answered
N

2

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

Nose answered 10/10, 2012 at 14:41 Comment(6)
And what are you using on your development machine?Triolet
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.Nose
And do any of those advertise that they have SQLCipher support?Triolet
Yes, The SQLite command shell specifically shows examples for ATTACHing to SQLCipher encrypted DBs: sqlcipher.net/sqlcipher-api#attachNose
possible duplicate of file is encrypted or is not a database (Exception net.sqlcipher.database.SQLiteException)Republicanism
see this - #25132977Paillasse
R
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.

Rompers answered 10/10, 2012 at 15:2 Comment(2)
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?Nose
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!!!Nose
T
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
Torre answered 11/9, 2014 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.