Skip to content

Instantly share code, notes, and snippets.

@wajahatkarim3
Created July 20, 2022 12:03
Show Gist options
  • Save wajahatkarim3/0cef79632ef2f84a8c9d7e2baf86f811 to your computer and use it in GitHub Desktop.
Save wajahatkarim3/0cef79632ef2f84a8c9d7e2baf86f811 to your computer and use it in GitHub Desktop.
val securePreferences = EncryptedSharedPreferences.create(
"secure_prefs",
mainKeyAlias,
applicationContext,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
// Storing Data in Preferences
with(securePreferences.edit()) {
putBoolean("Bool", true)
putString("String", "Some normal string value")
putInt("Integer", 10)
commit()
}
// Reading data from Preferences
val boolValue = securePreferences.getBoolean("Bool", false)
val strValue = securePreferences.getString("String", "")
val intValue = securePreferences.getInt("Integer", 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment