Open UKMIITB opened 4 months ago
Hello @UKMIITB In this case something is causing the key mismatch. There is not enough information to determine what, but that error is thrown when the incorrect key is used. You should check all the various edge cases, e.g. the implementations for your secured preferences, and any ways that a database could be used without a corresponding preference (e.g. restore from backup, transfer onto a different device, generation of passphrase, etc).
I was able to reproduce this issue with a 100% "success" rate, @sjlombardo. I'm testing this on a Pixel 7A with Android API 34 and version 4.5.7
of the library. I'm using Room with a hardcoded password, so the issue isn't related to password mismatches.
Essentially, in my case, the application always crashes if I try to insert an item and I have never performed any SELECT statement before.
Hi @GrenderG,
Can you post a public repo with a small test reproduction of the behavior you are seeing? We would be happy to investigate this further with a test case. Thanks!
Hello, I can try to do that this week. However, it should be very simple to test; basically you just need to open the app for the first time, then try to insert data without having performed any SELECT query before.
For the record, this is how I get the instance:
public static synchronized DummyDatabase getInstance(Context context) {
System.loadLibrary("sqlcipher");
return Room.databaseBuilder(context.getApplicationContext(),
DummyDatabase.class, Constants.DATABASE_NAME)
.fallbackToDestructiveMigration()
.setAutoCloseTimeout(60, TimeUnit.SECONDS)
.openHelperFactory(new SupportOpenHelperFactory(
Constants.DB_DEFAULT_PASSWORD.getBytes(StandardCharsets.UTF_8)))
.build();
}
To note:
AsyncTasks
, in case it matters.@GrenderG - in the scenario you are describing, does does the database already exist, or is the application creating a new database?
@GrenderG - in the scenario you are describing, does does the database already exist, or is the application creating a new database?
The application is creating a new database.
Hi @GrenderG,
Can you take a look at this small demo application and compare with what you are seeing locally?
Hello, I tried it and the crash wasn't happening (my app is made with Java, not Kotlin, probably not relevant though). However, I found a way to avoid the crash in my scenario: if I use ExecutorService
instead of a normal AsyncTask
, it will work fine.
Hi @GrenderG,
Thanks for the update, glad to hear you were able to resolve the issue.
I am getting this crash in production. Its not happening for all users & not reproducible. But in production this is happening.
This is the code for initialisation.
So here once passphrase is generated same passphrase is getting used. And we donot clear that passphrase from shared preference, so the case of trying to open from another passphrase would not happen.