5

I have developed application using SQLCipher in android. It is secure way to protect your Database file into application. It is working fine for encryption, but i want decrypt the encrypted DB file and want to look into SQLite Browser.

Actually I have lots of table and its data available. Now if i want to look into the encrypted DB data, there is no way to look into it (Only Logs available to view data).But Using SQLite Browser i can't see it.

I am using "info.guardianproject.database.sqlcipher.SQLiteDatabase"

I have tried many ways to decrypt it and look into SQLite Browser but it is giving error "An Error Occured : file is not a sqlite3 database".

can any one help me out for decryption of the encrypted DB file.

OR should i copy the encrypt the DB file and decrypt it using "info.guardianproject.database.sqlcipher.SQLiteDatabase" and use it to view all of the tables.

Thanks,

Mishal Shah

Developer
  • 1,009
  • 8
  • 25
  • 56

5 Answers5

5

I resolved this by using pulling the database from the device and decrypting it. The script below will generata a decrypted database file. This file can be opened with a SQLite-viewer.

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;'

Should be in your PATH:

Replace in script:

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

Note: Device should be rooted

Community
  • 1
  • 1
Tobrun
  • 18,291
  • 10
  • 66
  • 81
  • this still saying **Error: file is encrypted or is not a database** .in above statement I just replace database.db to my file name.,,anything I'm missing ? – CoDe Feb 04 '16 at 06:57
  • @Shubh you need to replace package name, database.db file name and encryption key. If I have time I will update this script to take in arguments from the command line. – Tobrun Feb 04 '16 at 08:55
  • yes I did the same..following I tried **sqlcipher -line database.sqlite 'PRAGMA key = "pass123";ATTACH DATABASE "decrypted_database.db" AS decrypted_database KEY "";SELECT sqlcipher_export("decrypted_database");DETACH DATABASE decrypted_database;'** Anything I'm missing ? – CoDe Feb 04 '16 at 08:58
2

You need to use a SQLite utility that has the SQLCipher extensions as part of it. You can download and build the SQLCipher code on Linux, which should give you a sqlite3 utility that you can use to access the database (with the appropriate PRAGMA statements for specifying the passphrase, etc.).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for sharing it .I have used it before into the application and gone through the example but how should i decrypt it and open it into SQLite Browser.? can you please share example or android code which should decrypt the file and open it into the SQLite browser. – Developer Mar 13 '13 at 12:30
  • @Mishal: I do not know what you consider "the SQLite browser" to be. If it is not the `sqlite3` command line utility, you will have to contact the author of "the SQLite browser" and ask them if they support SQLCipher. – CommonsWare Mar 13 '13 at 12:34
  • I am using "info.guardianproject.database.sqlcipher.SQLiteDatabase" for SQLCipher to encrypt the DB and want to decrypt it using the same way and want to open it, so i can view all of the tables in one view. – Developer Mar 13 '13 at 12:36
  • 1
    Another option: you can use the command line tool with sqlcipher_export() to export an encrypted database to a standard sqlite database, which you can then open with any tool. Note that this will expose all of the confidential information in the SQLCipher database, so it's only appropriate for test data. Also, you should upgrade to the latest version of SQLCipher for Android, as the versions using the info.guardianproject.database.sqlcipher are very outdated. – Stephen Lombardo Mar 13 '13 at 12:52
  • I want to do it using the code itself.I am using "info.guardianproject.database.sqlcipher" package for encryption of Database. Now i want some help to decrypt the Database File using "info.guardianproject.database.sqlcipher" package only which will help to create the whole new copy which is decrypted and can open in "SQLite Database Browser". Please share if anyone having source code for decryting the Database using "info.guardianproject.database.sqlcipher" package. Or i will create the different DB copy for the decrypted DB from the Encrypted DB. let me know whether it is possible or not. – Developer Mar 14 '13 at 07:16
0

The decrypt.sh script helped me for a while. But after sometime, I found that SQLiteManager started supporting SQLCipher encrypted databases. It has a pretty user interface. Even though it's not free and you still need to pull the database file from device, I think it's good to try.

neokim
  • 80
  • 10
0

In your android application code after

dbHelper.getReadableDatabase(dbKey); database file will be decrypted.. by writing file copy code copy database file to some external sd card file path and open it with any sqllite tool

prashanth yet
  • 249
  • 3
  • 5
-1

Gnome's GDA can do this. Download here.

Charles Munger
  • 1,417
  • 12
  • 11
  • I have downloaded and install the application but when i am trying to use encrypted DB to open it is not allowing. It is giving error as " The DB file is encrypyted" can you please help me out why it is not openning the SQLCipher encrypted DB file where i have given password to open it. – Developer Mar 13 '13 at 11:09