diff --git a/build.gradle b/build.gradle index be65aec7..f32663b0 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,8 @@ ext { roomVersion = "2.2.5" + sqlCipherVersion = "4.4.0" + /* JavaFX */ diff --git a/persistence/database/RoomBankingPersistence/build.gradle b/persistence/database/RoomBankingPersistence/build.gradle index 7e904f27..a4c9db2b 100644 --- a/persistence/database/RoomBankingPersistence/build.gradle +++ b/persistence/database/RoomBankingPersistence/build.gradle @@ -34,4 +34,6 @@ dependencies { kapt "androidx.room:room-compiler:$roomVersion" implementation "androidx.room:room-ktx:$roomVersion" + implementation "net.zetetic:android-database-sqlcipher:$sqlCipherVersion" + } \ No newline at end of file diff --git a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt index 87acc0b8..2a24eb48 100644 --- a/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt +++ b/persistence/database/RoomBankingPersistence/src/main/java/net/dankito/banking/persistence/RoomBankingPersistence.kt @@ -14,14 +14,22 @@ import net.dankito.banking.ui.model.tan.MobilePhoneTanMedium import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium import net.dankito.banking.util.persistence.doSaveUrlToFile import net.dankito.utils.multiplatform.File +import net.sqlcipher.database.SQLiteDatabase +import net.sqlcipher.database.SupportFactory -open class RoomBankingPersistence(applicationContext: Context) : IBankingPersistence, IRemitteeSearcher { +open class RoomBankingPersistence(applicationContext: Context, password: String? = null) : IBankingPersistence, IRemitteeSearcher { - protected val db = Room.databaseBuilder( - applicationContext, - BankingDatabase::class.java, "banking-database" - ).build() + protected val db: BankingDatabase + + init { + val passphrase = password?.let { SQLiteDatabase.getBytes(password.toCharArray()) } ?: ByteArray(0) + val factory = SupportFactory(passphrase) + + db = Room.databaseBuilder(applicationContext, BankingDatabase::class.java, "banking-database") + .openHelperFactory(factory) + .build() + } override fun saveOrUpdateAccount(customer: TypedCustomer, allCustomers: List) {