SqlCipher with room database

but my database file does not get encrypted as i can easily open that with sqlite db browser without any password

abstract class AppDatabase : RoomDatabase() {

abstract fun userRepo(): UserRepo

companion object {

    private var instance: AppDatabase? = null
    private val LOCK = Any()

    var str : CharArray = charArrayOf('a','b','c','d')
    val passphrase: ByteArray = SQLiteDatabase.getBytes(str)
    val factory: SupportFactory = SupportFactory(passphrase)

    operator fun invoke(context: Context) = instance ?: synchronized(LOCK) {
        instance ?: buildDatabase(context).also {
            instance = it

    private fun buildDatabase(context: Context) = Room.databaseBuilder(



Hi @CodeGeek

Are you creating your database from scratch, or does it already exist? If the latter, you will need to use sqlcipher_export(...) to convert your database from a plaintext SQLite database over to a SQLCipher-encrypted database. More information can be found here in our documentation.

No the database is created from scratch…
I have a few doubts…
So after mentioning the above logic now on android i am getting an error

file is not a database: , while compiling: select count(*) from sqlite_master;

  1. So does that mean that database is encrypted…
    If so how to run our queries with room database
    To perform crud operations
  2. As we have to mention the version in room… if we change the version. what we should do to avoid our app to crash
  3. How to use this sqlcipher_export(…) with room in android

Hi @CodeGeek

No, that is a general exception, however, when it occurs when you are creating your connection to the database it usually means it was unable to utilize the database key to read from the first page of the database. Commonly, if the database in question already exists and is encrypted with SQLCipher, the supplied password is incorrect.

Here is an example for executing cipher_migrate using the Support API.

How to get writable database
Does this effects the performance of queries over sqlite

Hi @CodeGeek

The example above include this here.

I’m not sure what you are referring to specifically. Can you provide more details?