Posts /

Secure-Pref-Manager

Twitter Facebook Google+
15 Jan 2016

Android Arsenal

Travis CI

Secure Preference Manager is a simple Library to help you protect your Shared Preferences.

Secure Preference Manager for android. It uses various encryption techniques to protect your application’s Shared Preferences.

Setup

Add jitpack to your project’s repositories.

repositories {
        // ...
        maven { url "https://jitpack.io" }
    }

Then add Secure-Pref-Manager to your Module’s dependencies

dependencies {
          compile 'com.github.prashantsolanki3:Secure-Pref-Manager:0.25'
  }

Usage

Initialize SecurePrefManager anywhere before using it.

       new SecurePrefManagerInit.Initializer(getApplicationContext())
               .initialize();
       new SecurePrefManagerInit.Initializer(getApplicationContext())
               .useEncryption(true)
               .initialize();
       new SecurePrefManagerInit.Initializer(getApplicationContext())
               .useEncryption(true)
               .setCustomEncryption(new Encryptor(getApplicationContext()) {
                   @Override
                   public String encrypt(String s) throws Exception {
                       // Your Encryption Algorithm
                       return encryptedString;
                   }

                   @Override
                   public String decrypt(String s) throws Exception {
                       // Your Decryption Algorithm
                       return decryptedString;
                   }
               })
               .initialize();

Adding and Retrieving Preferences

        String userName = SecurePrefManager.with(this)
                .get("user_name")
                .defaultValue("unknown")
                .go();

Hide Preferences from 3rd Party applications (EXPERIMENTAL)

@Override
    protected void onPause() {
        SecurePrefManager.with(getApplicationContext())
                .hide(new HidePreferences.PreferenceUpdateListener() {
                    @Override
                    public void onFailure() {

                    }

                    @Override
                    public void onProgress(int p, int max) {

                    }

                    @Override
                    public void onSuccess() {

                    }
                });
    }

Have Fun!


Twitter Facebook Google+