Giter Club home page Giter Club logo

securesharedpreferences's Introduction

SecureSharedPreferences

build status

Because sometimes we would like to encrypt SharedPreferences' data.

Usage

From SharedPreferences documented example:

public class Calc extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile";
    
    @Override
    protected void onCreate(Bundle state){
       super.onCreate(state);
       . . .

       // Restore preferences
       SecureSharedPreferences settings = new SecureSharedPreferences(this);
       boolean silent = settings.getBoolean("silentMode", false);
       setSilent(silent);
    }

    @Override
    protected void onStop(){
       super.onStop();

      // We need an Editor object to make preference changes.
      // All objects are from android.context.Context
      SecureSharedPreferences settings = new SecureSharedPreferences(this);
      SecureSharedPreferences.Editor editor = settings.edit();
      editor.putBoolean("silentMode", mSilentMode);

      // Commit the edits!
      // editor.commit(); // Autocommit is on by default ;)
    }
}

API

All SharedPreferences methods were implemented except for SharedPreferences.getAll(). I'm still working on it.

And new constructors:

    public SecureSharedPreferences(Context context);
    public SecureSharedPreferences(Context context, String key);
    public SecureSharedPreferences(Context context, String key, String secureName);

And now, supports:

putSerializable(String key, Serializable object)
getSerializable(String key)

You can save an Object (implements Serializable) and retrieve it later. As it uses an bytearray version of the Serialized object, you have to pay attention when you update the object's Class because getSerializable method can return 'null' if you change some Class field.

Gradle

compile 'com.github.rtoshiro.securesharedpreferences:securesharedpreferences:1.2.0'
    repositories {
        mavenCentral()
    }

Encryption

For encryption process, it uses Facebook Conceal

It's very simple and functional.

securesharedpreferences's People

Contributors

rtoshiro avatar kanetik avatar

Watchers

James Cloos avatar B avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.