Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decrypt SQLCipher encrypted file in android?

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

like image 433
Developer Avatar asked Mar 13 '13 10:03

Developer


People also ask

What encryption does SQLCipher use?

SQLCipher is an open source library that provides transparent, secure 256-bit AES encryption of SQLite database files.

How do I decrypt a database file?

To decrypt a file:In the Specify Solution Options dialog box, select Remove Database Encryption. For Encryption Password, enter the current encryption password for the database files. FileMaker Pro only: For FileMaker Account, click Specify.

How SQLCipher works?

Using SQLCipher, an application uses the standard SQLite API to manipulate tables using SQL. Behind the scenes the library silently manages the security aspects, making sure that data pages are encrypted and decrypted as they are written to and read from storage.

Is Android SQLite encrypted?

The The SQLite Encryption Extension provides an easy way to create, read and write encrypted database files. It may be used with the SQLite Android bindings to add encrypted database capability to any application.


2 Answers

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.).

like image 37
CommonsWare Avatar answered Oct 23 '22 10:10

CommonsWare


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:

  • adb
  • sqlcipher

Replace in script:

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

Note: Device should be rooted

like image 141
Tobrun Avatar answered Oct 23 '22 10:10

Tobrun