Skip to content

HussainDerry/secure-preferences

Repository files navigation

Secure Preferences Maven Central Android Arsenal Codacy Badge

A simple library that provides an encrypted version of the Android shared preferences. Current supported algorithms (AES, TripleDES).

Setup

Gradle

compile 'com.github.hussainderry:secure-preferences:4.0.0'

Sample Usage

Configuring Encryption Parameters

// Minimum Configurations
SecurityConfig minimumConfig = new SecurityConfig.Builder(PASSWORD)
        .build();

// Full Configurations
SecurityConfig fullConfig = new SecurityConfig.Builder(PASSWORD)
        .setKeySize(256) // key size in bits
        .setPbkdf2SaltSize(32) // salt size in bytes
        .setPbkdf2Iterations(24000)
        .setEncryptionAlgorithm(EncryptionAlgorithm.AES)
        .setDigestType(DigestType.SHA256)
        .build();

SecurePreferences mPreferences = SecurePreferences.getInstance(MainActivity.this, FILENAME, minimumConfig);
SecurePreferences.Editor mEditor = mPreferences.edit();

Getting Data Asynchronously

Using Future<T>

AsyncDataLoader mAsyncLoader = mPreferences.getAsyncDataLoader();
Future<String> mFuture = mAsyncLoader.getString("name", "default");

/* Do something while the data is being fetched */

if(mFuture.isDone()){
    String data = mFuture.get();
}

Using DataCallback<T>

mPreferences.getAsyncDataLoader().getString("key", "default", new DataCallback<String>(){
	@Override
	public void onDataLoaded(String data){
		System.out.println(data);
	}
});

Developed By

  • Hussain Al-Derry

   Email - hussain.derry@gmail.com

License

Copyright 2017 Hussain Al-Derry

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.