security: swap alpha crypto 1.1.0-alpha06 for stable 1.0.0, update MasterKey→MasterKeys API

This commit is contained in:
null 2026-06-16 22:05:37 -05:00
parent 95ea9ffed5
commit e82207c9d0
2 changed files with 8 additions and 8 deletions

View File

@ -95,7 +95,7 @@ dependencies {
implementation("androidx.datastore:datastore-preferences:1.1.2")
// Encrypted storage
implementation("androidx.security:security-crypto:1.1.0-alpha06")
implementation("androidx.security:security-crypto:1.0.0")
// RevenueCat
implementation("com.revenuecat.purchases:purchases-hybrid-common:13.5.0")

View File

@ -3,7 +3,7 @@ package app.closer.data.repository
import android.content.Context
import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
import androidx.security.crypto.MasterKeys
import app.closer.domain.model.LocalAnswer
import app.closer.domain.repository.LocalAnswerRepository
import dagger.hilt.android.qualifiers.ApplicationContext
@ -23,18 +23,18 @@ class SharedPreferencesLocalAnswerRepository @Inject constructor(
private val prefs: SharedPreferences = run {
// Remove legacy plaintext file on first migration
context.deleteSharedPreferences("local_answers")
val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
try {
// In 1.0.0, EncryptedSharedPreferences.create takes (alias, name, context, ...)
val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
EncryptedSharedPreferences.create(
context,
"local_answers_secure",
masterKey,
masterKeyAlias, // alias (first param)
"local_answers_secure", // name (second param)
context, // context (third param)
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
} catch (_: Exception) {
// Fallback to unencrypted SharedPreferences if encryption fails
context.getSharedPreferences("local_answers_secure", Context.MODE_PRIVATE)
}
}