scottyab / secure-preferences

Android Shared preference wrapper than encrypts the values of Shared Preferences. It's not bullet proof security but rather a quick win for incrementally making your android app more secure.
1.53k stars 235 forks source link

Cant get decrypted value #76

Open 1mohammad7 opened 6 years ago

1mohammad7 commented 6 years ago

I'm sorry but your explanation and sample project are very vague and can't figure it out. Could you please explain how to get data from encrypted sharedPrefs?! What is wrong with this code? it's like your sample project but the value won't be decrypted! :

//Set data
   SecurePreferences sharedPrefs = new SecurePreferences(context, password, "vault");
  SecurePreferences.Editor editor = sharedPrefs.edit();
  editor.putString(KEY_USERNAME, username);
 editor.commit();

//Get decrypted data (WONT WORK)
 SharedPreferences securePreferences = context.getSharedPreferences("vault", Context.MODE_PRIVATE);
        for (Map.Entry<String, ?> entry : securePreferences.getAll().entrySet()) {
            String key = entry.getKey();
            if (key.equals(SecurePreferences.hashPrefKey(KEY_USERNAME))) {
                MY_USERNAME = securePreferences.getString(key,""); //Returns encrypted value
            }
        }