Skip to content

How can i known is passphrase correct before creating database? #529

@TarasOryshhij

Description

@TarasOryshhij

Expected Behavior

It is Android application and Room.
I wan't create database when user set his password. And i use this password to encrypt my database. This is my DI module:
single {
val passPhrase = getKoin().getProperty(PROPERTY_USER_PASSWORD, "")
val passPhraseBytes: ByteArray = SQLiteDatabase.getBytes(passPhrase.toCharArray())
val factory = SupportFactory(passPhraseBytes)

    Room.databaseBuilder(androidContext(), MyDatabase::class.java, DB_NAME)
        .openHelperFactory(factory)
        .build()
}
factory { get<MyDatabase>().accountsDao() }

}

Actual Behavior

So now if user change login (or password), i wan't clear database. Because now i have runtime exception in case when user change password:
E/AndroidRuntime: FATAL EXCEPTION: arch_disk_io_0
Process: com.test.test, PID: 28984
java.lang.RuntimeException: Exception while computing database live data.
at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:92)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Caused by: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;

Steps to Reproduce

Create database with one passwrod. Close application. Open application, and try create database with another password.

SQLCipher for Android version:
implementation "net.zetetic:android-database-sqlcipher:4.4.1"
implementation "androidx.sqlite:sqlite-ktx:2.1.0"

Note: If you are not posting a specific issue for the SQLCipher library, please consider posting your question to the SQLCipher discuss site. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-detailsNeeds additional details to proceed.staleThis issue lacks recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions