Eventually to be repalced by EncryptedSharedPreferences from AndroidX (which is in alpha currently): https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences
KotlinMIT
EncryptedSharedPreferences
Purpose
this library gives you an out of the box solution for encrypting values in a Shared Preferences file via the Android Keystore
no need to worry about managing/generating keys in your app, just plug'n'play
the encryption under the hood relies on the Keystore (so your keys are mostly managed by the OS keystore process1)
Examples
Initialize
val prefs =EncryptedSharedPreferences.create(filename ="default", context)
Store a String
val editor = prefs.edit()
editor.putString("KEY", "value")
editor.apply()
Get a String
prefs.getString("KEY", "default value")
Plans for the Future
replace support libs with androidx
introduce a mechanism for migrating from current shared prefs, to androidx shared prefs
perhaps some instrumentation tests?
Caveats
for below API 23 (Android Marshmallow), Symmetric Encryption is not supported out of the box. A key is generated, and stored in shared preferences (asymmetrically encrypted)