israteneda
israteneda

Reputation: 775

Checking if Shared Preferences is encrypted

I am encrypting the shared preferences with this code:

String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);

   SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
       "secret_shared_prefs",
       masterKeyAlias,
       context,
       EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
       EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
   );

   // use the shared preferences and editor as you normally would
   SharedPreferences.Editor editor = sharedPreferences.edit();

Taken from this answer. I would like to know a programmatically method to check if the data is success encrypted. I try the above code to encrypt the shared preferences and don't show me any error.

Upvotes: 2

Views: 926

Answers (2)

Rulogarcillan
Rulogarcillan

Reputation: 1232

You can implement the stetho library to view sharepreferences and many more things, such as databases or http calls, from the web browser.

Too easy

http://facebook.github.io/stetho/

Upvotes: 2

majid ghafouri
majid ghafouri

Reputation: 869

From Android Studio, start Android Device Monitor, go to File Explorer,

and browse "/data/data/< name of your package >/shared_prefs/".

You will find the preferences XML there... and also you can copy it for inspection. you can see the xml contents (encrypted or decrypted)

Upvotes: 3

Related Questions