ophio / secure-preferences

Android secure shared preferences using Android Keystore system
https://medium.com/@vashisthg/android-secure-shared-preferences-10f8356a4c2b
Apache License 2.0
348 stars 56 forks source link

How I can use this library to decrypt the saved data? #17

Closed KadamMangesh closed 8 years ago

KadamMangesh commented 8 years ago

I want to securely save some sensitive data in shared pref. Later I need to decrypt the encrypted data and use in application. How I can achieve this using secure preferences library?

vashisthg commented 8 years ago

@MangeshKadam Please check the sample application.

Create key by

String key = KeyGenerator.get(KeystoreApplication.getAppContext(),
                    KeystoreApplication.getAppContext().getPackageName())
                        .loadOrGenerateKeys();

Obtain an instance of ObscuredSharedPreferences using ObscuredPreferencesBuilder as follows:


SharedPreferences sharedPreferences = new ObscuredPreferencesBuilder()
                .setApplication(KeystoreApplication.getAppContext())
                .obfuscateValue(true)
                .obfuscateKey(true)
                .setSharePrefFileName(PREFS_NAME)
                .setSecret(key)     //secret key we generated in step 1.
                .createSharedPrefs();

now use the instance of sharedPreferences created above to save/fetch data.

vashisthg commented 8 years ago

Hey @MangeshKadam Can we close this issue?

KadamMangesh commented 8 years ago

Hi thanks. you can close this issue.