I want to introduce SQLCipher to Room

71 Views Asked by At

I want to introduce SQLCipher to Room. I can run it without any error, but I can't open the created DB. I tried to open a DB created with some external tool, but when I enter the password I set, it says "not a DB".

I want to solve the cause of DB corruption. I am new to Android. Thank you.

By the way, Android is API30.

dependencies {
    def room_version = "2.4.3"
    implementation "androidx.room:room-runtime:$room_version"
    implementation "androidx.room:room-ktx:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    implementation "net.zetetic:android-database-sqlcipher:4.4.2@aar"
}
@Database(
    entities = [
        Config::class,
        User::class
    ],
    version = 2,
    exportSchema = false
)
abstract class TestDatabase : RoomDatabase() {
    abstract fun ConfigDao(): ConfigDao
    abstract fun UserDao(): UserDao

    companion object {
        fun getDatabase(context: Context): TestDatabase {

            return Room.databaseBuilder(
                context.applicationContext,
                TestDatabase::class.java,
                "db_name"
            ).openHelperFactory(SupportFactory(SQLiteDatabase.getBytes("1234".toCharArray())))
                .fallbackToDestructiveMigration()
                .build()

        }
    }
}
0

There are 0 best solutions below