secure-preferences icon indicating copy to clipboard operation
secure-preferences copied to clipboard

Hashing the keys broke the getAll() and onSharedPreferenceChanged(SharedPreferences, String) methods

Open awasisto opened this issue 6 years ago • 1 comments

The keys returned by the SecurePreferences#getAll() method or passed through the OnSharedPreferenceChangeListener#onSharedPreferenceChanged(SharedPreferences, String) method are the hashed keys instead of the real keys.

Example:

SharedPreferences preferences = new SecurePreferences(getContext());
    
preferences.edit().putString("userBirthPlace", "Mars").apply();
preferences.edit().putString("userFavouriteAnimal", "Unicorn").apply();
    
System.out.println(preferences.getAll());

/*
 * Output: {/ntTe3/atqHnZpVLXZFdZCh1kXCeMNI4ZxZakEmn46M==Unicorn, EKfKV82MWU69SaHA6DzF5LIJ2m6EhElrylXmoC4qFkY==Mars}
 */

I think the keys shouldn't be hashed since they shouldn't contain any user data.

awasisto avatar Oct 25 '18 10:10 awasisto

@awasisto I think this is the intended behaviour. The library does not store the keys & uses a hash of the keys for storing the values.

With the current implementation, it is not possible to get the actual keys.

samratshaw avatar Jul 22 '19 08:07 samratshaw