-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 16 additions & 5 deletions
21
app/src/main/java/com/koalasat/pokey/models/EncryptedStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
package com.koalasat.pokey.models | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.security.crypto.EncryptedSharedPreferences | ||
import androidx.security.crypto.MasterKey | ||
import com.koalasat.pokey.Pokey | ||
|
||
object PrefKeys { | ||
const val NOSTR_PUBKEY = "nostr_pubkey" | ||
const val NOSTR_RELAYS = "nostr_relays" | ||
} | ||
|
||
object EncryptedStorage { | ||
private const val PREFERENCES_NAME = "secret_keeper" | ||
|
||
fun preferences(): EncryptedSharedPreferences { | ||
val context = Pokey.getInstance() | ||
private lateinit var sharedPreferences: SharedPreferences | ||
|
||
private val _pubKey = MutableLiveData<String>() | ||
val pubKey: LiveData<String> get() = _pubKey | ||
|
||
fun init(context: Context) { | ||
val masterKey: MasterKey = | ||
MasterKey.Builder(context, MasterKey.DEFAULT_MASTER_KEY_ALIAS) | ||
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM) | ||
.build() | ||
|
||
return EncryptedSharedPreferences.create( | ||
sharedPreferences = EncryptedSharedPreferences.create( | ||
context, | ||
PREFERENCES_NAME, | ||
masterKey, | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM, | ||
) as EncryptedSharedPreferences | ||
} | ||
|
||
fun updatePubKey(newValue: String) { | ||
sharedPreferences.edit().putString(PrefKeys.NOSTR_PUBKEY, newValue).apply() | ||
_pubKey.value = newValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters