Skip to content

Instantly share code, notes, and snippets.

@akaita
Last active January 28, 2020 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaita/d0c99c3f5f7726dd388f57e66867ef6e to your computer and use it in GitHub Desktop.
Save akaita/d0c99c3f5f7726dd388f57e66867ef6e to your computer and use it in GitHub Desktop.
encryptedsharedpreferences-12.kt
// Step 1: Create or retrieve the Master Key for encryption/decryption
val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
// Step 2: Initialize/open an instance of EncryptedSharedPreferences
val sharedPreferences = EncryptedSharedPreferences.create(
"PreferencesFilename",
masterKeyAlias,
applicationContext,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment