Laid at least groundworks to encrypt Room database

This commit is contained in:
dankito 2020-09-17 11:58:41 +02:00
parent 497b82ce09
commit d360ff1def
3 changed files with 17 additions and 5 deletions

View File

@ -70,6 +70,8 @@ ext {
roomVersion = "2.2.5" roomVersion = "2.2.5"
sqlCipherVersion = "4.4.0"
/* JavaFX */ /* JavaFX */

View File

@ -34,4 +34,6 @@ dependencies {
kapt "androidx.room:room-compiler:$roomVersion" kapt "androidx.room:room-compiler:$roomVersion"
implementation "androidx.room:room-ktx:$roomVersion" implementation "androidx.room:room-ktx:$roomVersion"
implementation "net.zetetic:android-database-sqlcipher:$sqlCipherVersion"
} }

View File

@ -14,14 +14,22 @@ import net.dankito.banking.ui.model.tan.MobilePhoneTanMedium
import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium import net.dankito.banking.ui.model.tan.TanGeneratorTanMedium
import net.dankito.banking.util.persistence.doSaveUrlToFile import net.dankito.banking.util.persistence.doSaveUrlToFile
import net.dankito.utils.multiplatform.File 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( protected val db: BankingDatabase
applicationContext,
BankingDatabase::class.java, "banking-database" init {
).build() 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<TypedCustomer>) { override fun saveOrUpdateAccount(customer: TypedCustomer, allCustomers: List<TypedCustomer>) {