Cant get decrypted value
1mohammad7 opened this issue · comments
1mohammad7 commented
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
}
}