mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 01:02:33 +02:00
Merge remote-tracking branch 'origin/HEAD'
This commit is contained in:
@@ -2,18 +2,20 @@ package com.vitorpamplona.amethyst
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.security.crypto.EncryptedSharedPreferences
|
import androidx.security.crypto.EncryptedSharedPreferences
|
||||||
import androidx.security.crypto.MasterKeys
|
import androidx.security.crypto.MasterKey
|
||||||
|
|
||||||
class EncryptedStorage {
|
object EncryptedStorage {
|
||||||
|
private const val PREFERENCES_NAME = "secret_keeper"
|
||||||
|
|
||||||
fun preferences(context: Context): EncryptedSharedPreferences {
|
fun preferences(context: Context): EncryptedSharedPreferences {
|
||||||
val secretKey: String = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
|
val masterKey: MasterKey = MasterKey.Builder(context, MasterKey.DEFAULT_MASTER_KEY_ALIAS)
|
||||||
val preferencesName = "secret_keeper"
|
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
||||||
|
.build()
|
||||||
|
|
||||||
return EncryptedSharedPreferences.create(
|
return EncryptedSharedPreferences.create(
|
||||||
preferencesName,
|
|
||||||
secretKey,
|
|
||||||
context,
|
context,
|
||||||
|
PREFERENCES_NAME,
|
||||||
|
masterKey,
|
||||||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
||||||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
|
||||||
) as EncryptedSharedPreferences
|
) as EncryptedSharedPreferences
|
||||||
|
@@ -29,7 +29,7 @@ class LocalPreferences(context: Context) {
|
|||||||
val LAST_READ: (String) -> String = { route -> "last_read_route_$route" }
|
val LAST_READ: (String) -> String = { route -> "last_read_route_$route" }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val encryptedPreferences = EncryptedStorage().preferences(context)
|
private val encryptedPreferences = EncryptedStorage.preferences(context)
|
||||||
private val gson = GsonBuilder().create()
|
private val gson = GsonBuilder().create()
|
||||||
|
|
||||||
fun clearEncryptedStorage() {
|
fun clearEncryptedStorage() {
|
||||||
|
Reference in New Issue
Block a user