I found out that the default way of using EncryptedSharedPreferences is to create the key with MasterKeys for it. However, when I replace val masterKeyAlias = MasterKeys.getOrCreate() with a sample string e.g. val masterKeyAlias = "test_key" it still works and the file gets encrypted anyway. In the documentation I can't find anything about auto-creation of keys in the keystore if they don't exist. What is the advantage of using MasterKeys.getOrCreate here?
val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
// val masterKeyAlias = "test_key"
EncryptedSharedPreferences.create(
"encrypted_preferences", // fileName
masterKeyAlias, // masterKeyAlias
this, // context
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, // prefKeyEncryptionScheme
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM // prefvalueEncryptionScheme
)