Package 

Class EncryptedSharedPreferences

  • All Implemented Interfaces:
    android.content.SharedPreferences

    
    public final class EncryptedSharedPreferences
     implements SharedPreferences
                        

    An implementation of SharedPreferences that encrypts keys and values. WARNING: The preference file should not be backed up with Auto Backup. When restoring the file it is likely the key used to encrypt it will no longer be present. You should exclude all EncryptedSharedPreferences from backup using backup rules. Basic use of the class:

     MasterKey masterKey = new MasterKey.Builder(context)
         .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
         .build();
    
     SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
         context,
         "secret_shared_prefs",
         masterKey,
         EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
         EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
     );
    
     // use the shared preferences and editor as you normally would
     SharedPreferences.Editor editor = sharedPreferences.edit();
    
    Based on EncryptedSharedPreferences.java from AndroidX Crypto - v1.1.0-alpha07

    Permalink: e50caac