phamquyhai/secure-preferences


Android secure shared preferences using Conceal (Facebook)

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.kakavip:secure-preferences:1.1.1'
	}
	dependencies {
		implementation("com.github.kakavip:secure-preferences:1.1.1")
	}
	<dependency>
	    <groupId>com.github.kakavip</groupId>
	    <artifactId>secure-preferences</artifactId>
	    <version>1.1.1</version>
	</dependency>

                            
    libraryDependencies += "com.github.kakavip" % "secure-preferences" % "1.1.1"
        
        

                            
    :dependencies [[com.github.kakavip/secure-preferences "1.1.1"]]
        
        

Readme


Android secure shared preferences using Conceal (Facebook)

  • Conceal -> https://github.com/facebook/conceal

Why use ?
  • Most of security for data ( as user token, some api key ...)
  • Less SharedPreferences file size
  • Base on SharedPreferences default, to easy use
  • Faster encrypt with the Conceal
  • 256-bit encryption

We're supported Conceal 2.x (faster than old version)

Download

#####Gradle:

Step 1. Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
        compile 'com.github.KaKaVip:secure-preferences:1.1.0'
        compile 'com.facebook.conceal:conceal:2.0.1@aa'
}

How to use

In Application: Data return empty if you don't setting this

Since v2.0.+ (2017-06-27) you will need to initialize the native library loader. This step is needed because the library loader uses the context. The highly suggested way to do it is in the application class onCreate method like this:

    @Override
    public void onCreate() {
        super.onCreate();
        SecurePreferences.init(this); 
    }

When used:

SharedPreferences prefs = new SecurePreferences.Builder(MainActivity.this)
                .password("password")
                .filename("settings")
                .build();
// Save token
prefs.edit().putString("token","f93ce38ab841fad01bc5e571ea861e9e").apply();

// Get Token
String token = prefs.getString("token","if_not_found");

See settings.xml file:


// SharedPreferences default
<string name="token">f93ce38ab841fad01bc5e571ea861e9e</string>

// Via SecurePreferences
<string name="94a08da1fecbb6e8b46990538c7b50b2">AQI80a7LVHPIW8l00ecIag95oKcaje6U2fgREyvUPTnn3OCBK5rq/xACPjI9</string>

License

Copyright 2016 Pham Quy Hai, Inc.

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.