Android Library for saving any Sensitive Data (e.g user credentials, access token, credit cards ,... etc) in cryptographic format
It is useful espically in case of rooted device, as the hacker can access your SharedPreferences
and reach sensitive data easily. So this is a solution to keep your Data Safe.
- Init the
Singleton
in yourApplication
Class by adding this line to theonCreate()
Method in order to provide the ApplicationContext
in which this Singleton will operate.
@Override
public void onCreate() {
super.onCreate();
// Initialize the SecurePref Singleton..
SecurePref.init(this);
}
- Now you can use
SecurePref
Singleton all over the app by just CallingSecurePref.getInstance()
- The
APIs
of SecurePref is the same as theSharedPreference
apis. If you want for example setaccountNumber
as a secure data you can do this:
SecurePref.getInstance().edit()
.putLong("accountNumber", 123254589921L)
.commit();
and you can retreive the accountNumber later using this line:
SecurePref.getInstance().getLong("accountNumber", 0L);
- Add the JitPack repository to your build file
Add it in your root
build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
compile 'com.github.Mohamed-Fadel:PrefSecure:0.1.1'
}
- Supports +14 APIs but only encrypt the data for +18 APIs while save it as a
plainText
not encrypted for APIs < 18 - Encrypt only the values not the keys.