
Encrypted SharedPreferences: Secure Data Storage in Android
Protecting sensitive user data is critical. EncryptedSharedPreferences from Jetpack Security provides transparent encryption for SharedPreferences. Setting Up EncryptedSharedPreferences import androidx.security.crypto.EncryptedSharedPreferences import androidx.security.crypto.MasterKey fun getEncryptedPreferences ( context : Context ): SharedPreferences { val masterKey = MasterKey . Builder ( context ) . setKeyScheme ( MasterKey . KeyScheme . AES256_GCM ) . build () return EncryptedSharedPreferences . create ( context , "secret_prefs" , masterKey , EncryptedSharedPreferences . PrefKeyEncryptionScheme . AES256_SIV , EncryptedSharedPreferences . PrefValueEncryptionScheme . AES256_GCM ) } Storing and Retrieving Encrypted Data @Composable fun SecureDataScreen ( context : Context ) { val prefs = remember { getEncryptedPreferences ( context ) } Button ( onClick = { prefs . edit (). putString ( "api_token" , "secret_token_123" ). apply () } ) { Text ( "Save Token" ) } Button ( onClick = { val
Continue reading on Dev.to Tutorial
Opens in a new tab



