Android - possible to use both android.database.sqlite.SQLiteDatabase and net.sqlcipher.database.SQLiteDatabase in tandem?

52 views
Skip to first unread message

Mark Carter

unread,
Aug 21, 2014, 2:13:04 PM8/21/14
to sqlc...@googlegroups.com
I have some Android Library projects using android.database.sqlite.SQLiteDatabase and related classes. These library projects may be used by some apps which use SQLCipher and some apps that do not. If an app uses SQLCipher it will want to attach an SQLCipher encrypted database to a (non-encrypted) database opened in the library project.

I am reluctant to switch all android.database.sqlite.SQLiteDatabase references to net.sqlcipher.database.SQLiteDatabase because not all my apps will require encrypted databases.

Is it possible to attach an SQLCipher database to an android.database.sqlite.SQLiteDatabase instance?

I suspect the answer is no, in which case, there are two options:

1. Update the Library project to use net.sqlcipher.database.SQLiteDatabase instead of android.database.sqlite.SQLiteDatabase. However, this new dependency is not an option because the size of SQLCipher is too large especially considering not all apps will need it.

2. Write an SQLiteDatabase wrapper that imitates android.database.sqlite.SQLiteDatabase. One implementation wrapping android.database.sqlite.SQLiteDatabase and one wrapping net.sqlcipher.database.SQLiteDatabase. This way, the app can choose the appropriate implementation. The library project would use this wrapper instead of android.database.sqlite.SQLiteDatabase. How does this sound? Does such a wrapper already exist somewhere?

Thanks for any help!

Nick Parker

unread,
Aug 21, 2014, 4:26:35 PM8/21/14
to sqlc...@googlegroups.com
Hello Mark,

On 8/21/14 1:13 PM, Mark Carter wrote:
> Is it possible to attach an SQLCipher database to an
> android.database.sqlite.SQLiteDatabase instance?

If you are referring to point a class reference that refers to a
SQLCipher instance to an android.database.sqlite.SQLiteDatabase
variable, the answer is no. Keep in mind that a SQLCipher for Android
can operate on both plain text SQLite databases, as well as encrypted
SQLCipher databases, however this would need to be handled entirely
through the SQLCipher for Android client library.


--
Nick Parker

signature.asc

Mark Carter

unread,
Aug 21, 2014, 11:32:57 PM8/21/14
to sqlc...@googlegroups.com
Hi Nick, thanks.

If I switch my library projects to use net.sqlcipher.database.SQLiteDatabase then there will be a dependency on all the SQLCipher libs (at least 4MB worth). What would be really good, would be to have a higher level SQLiteDatabase class that uses net.sqlcipher.database.SQLiteDatabase (when available) and android.database.sqlite.SQLiteDatabase (when SQLCipher unavailable). Of course, in the latter case, encrypted databases would not be supported (as expected, so not a problem).
Reply all
Reply to author
Forward
0 new messages