Android Security SharedPreference (Android Security SharedPreference storage) Welcome Star, my blog: blog.csdn.net/voidmain_12…

preface

The security problem has been a big drawback of Android system for a long time, and many people choose Apple instead of Android. As an Android Developer, we need to be responsible for user privacy and do our best to ensure user data security. When I think of this, MY blood boils. As if I were an angel of justice (I can’t go on…) .

[email protected]
    147258369

Copy the code

Secondly, let’s look at the usage of SecuritySharedPreference:

Private void saveInSecurityPreference(){SecuritySharedPreference securitySharedPreference = new SecuritySharedPreference(getApplicationContext(), "security_prefs", Context.MODE_PRIVATE); SecuritySharedPreference.SecurityEditor securityEditor = securitySharedPreference.edit(); securityEditor.putString("username", mEmailView.getText().toString()); securityEditor.putString("password", mPasswordView.getText().toString()); securityEditor.apply(); }Copy the code

Let’s see what the difference is in local saving



    Rnfpxffj9rNl29dsoQxlUzpSaR9m5K6myIYtqQOiIRU=
    HoHo+CFJrXK3CPMUpcTTow==


Copy the code

The effect is great! We implement the encryption of Share Preference through two simple classes. Although it is a very simple small function, but provides a shield for data security, some students may say, MY project already use SharedPreference, how to migrate to SecuritySharedPreference? How do you transition from unencrypted data to encrypted data? In fact, I’ve already done this for you. The next time we upgrade our application, we call handleTransition() to encrypt the data the first time we use Share Preference.