How to encrypt RoomDatabase createFromAsset

Basically I wanted to have a database with some predefined data (Room database). So I am using createFromAsset to get the predefined database and encrypting it on databaseBuilder.

But when I am trying to access database I am getting following error:

Could not access database: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;

Hi @Doli

When you use createFromAsset, are you providing a plaintext SQLite database, or a SQLCipher-encrypted database? If it’s the latter, I’m not certain Room would support that type of operation because once the builder is invoked, the file will be copied from your assets directory into the databases directory, but then it appears to use a FrameworkSQLiteOpenHelperFactory to create a SupportSQLiteOpenHelper for ultimately opening the database.

I am using plaintext sqlite database when doing createFromAsset.

code sample of what I am doing

INSTANCE = Room.databaseBuilder(context,
                            ExampleDatabase.class, DB_NAME)

Hi @Doli

You will need to use the sqlcipher_export(...) convenience function in order to migrate a plaintext database to a SQLCipher encrypted database. You might want to perform your export from assets and plaintext→encrypted prior to interfacing with Room.