Use MasterKey.Builder instead of deprecated MasterKeys

This commit is contained in:
Chemaclass 2023-03-09 20:56:56 +00:00
parent c511ad6f73
commit 7c94af2fb2

View File

@ -2,18 +2,20 @@ package com.vitorpamplona.amethyst
import android.content.Context
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
import androidx.security.crypto.MasterKey
class EncryptedStorage {
private val preferencesName = "secret_keeper"
fun preferences(context: Context): EncryptedSharedPreferences {
val secretKey: String = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
val preferencesName = "secret_keeper"
val masterKey: MasterKey = MasterKey.Builder(context, MasterKey.DEFAULT_MASTER_KEY_ALIAS)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
return EncryptedSharedPreferences.create(
preferencesName,
secretKey,
context,
preferencesName,
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
) as EncryptedSharedPreferences