Hi,
I have a plain room db in my application, i used “net.zetetic:android-database-sqlcipher:4.4.0” to encrypt the database it working fine in development phase, but after application released into the market getting random crashes as saying “Fatal Exception: net.sqlcipher.database.SQLiteException file is not a database: , while compiling: select count(*) from sqlite_master;”, and we are not able reproduce the same in our end. i checked that Passphrase also correct, no where it is getting changed. Any help you can give would be greatly appreciated.
I used the below code to encrypt the data base
@Throws(IOException::class)
private fun encrypt(context: Context, databaseName: String, passphrase: ByteArray) {
val originalFile = getCurrentDBPath(context, databaseName)
if (originalFile.exists()) {
val newFile = File.createTempFile(“xyz_room_db”, “tmp”,
context.cacheDir)
var db = SQLiteDatabase.openDatabase(originalFile.absolutePath,
“”, null, SQLiteDatabase.OPEN_READWRITE)
val version = db.version
SlLog.i(“SL_DATABASE”, “DB version ${version}”)
db.close()
db = SQLiteDatabase.openDatabase(newFile.absolutePath, passphrase, null, SQLiteDatabase.OPEN_READWRITE, null, null)
val st: SQLiteStatement = db.compileStatement(“ATTACH DATABASE ? AS plaintext KEY ‘’”)
st.bindString(1, originalFile.absolutePath)
st.execute()
db.rawExecSQL(“SELECT sqlcipher_export(‘main’, ‘plaintext’)”)
db.rawExecSQL(“DETACH DATABASE plaintext”)
db.version = version
st.close()
db.close()
originalFile.delete()
newFile.renameTo(originalFile)
SlLog.i(“SL_DATABASE”, “DB encrypted successfully”)
} else {
throw FileNotFoundException(originalFile.absolutePath + " not found")
}
}
Fatal Exception: net.sqlcipher.database.SQLiteException
file is not a database: , while compiling: select count(*) from sqlite_master;
net.sqlcipher.database.SQLiteCompiledSql.native_compile (SQLiteCompiledSql.java)
net.sqlcipher.database.SQLiteCompiledSql.compile (SQLiteCompiledSql.java:89)
net.sqlcipher.database.SQLiteCompiledSql. (SQLiteCompiledSql.java:62)
net.sqlcipher.database.SQLiteProgram. (SQLiteProgram.java:91)
net.sqlcipher.database.SQLiteQuery. (SQLiteQuery.java:48)
net.sqlcipher.database.SQLiteDirectCursorDriver.query (SQLiteDirectCursorDriver.java:60)
net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory (SQLiteDatabase.java:2016)
net.sqlcipher.database.SQLiteDatabase.rawQuery (SQLiteDatabase.java:1902)
net.sqlcipher.database.SQLiteDatabase.keyDatabase (SQLiteDatabase.java:2669)
net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal (SQLiteDatabase.java:2612)
net.sqlcipher.database.SQLiteDatabase.openDatabase (SQLiteDatabase.java:1247)
net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase (SQLiteDatabase.java:1322)
net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase (SQLiteOpenHelper.java:166)
net.sqlcipher.database.SupportHelper.getWritableDatabase (SupportHelper.java:83)
androidx.room.RoomDatabase.inTransaction (RoomDatabase.java:476)
arrow_drop_down
androidx.room.RoomDatabase.assertNotSuspendingTransaction (RoomDatabase.java:281)
com.mobile.newArch.room.dao.NotificationListDao_Impl.insert (NotificationListDao_Impl.java:189)
com.mobile.newArch.room.dao.NotificationListDao_Impl.insert (NotificationListDao_Impl.java:24)
com.mobile.newArch.utils.NotificationDbOperationsUtil.saveNotificationData (NotificationDbOperationsUtil.java:38)
com.mobile.newArch.utils.PushNotifications.onPushNotificationShown (PushNotifications.java:29)
com.webengage.sdk.android.i$5.run (i.java:10)