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
Singletonin yourApplicationClass by adding this line to theonCreate()Method in order to provide the ApplicationContextin which this Singleton will operate.
@Override
public void onCreate() {
super.onCreate();
// Initialize the SecurePref Singleton..
SecurePref.init(this);
}
- Now you can use
SecurePrefSingleton all over the app by just CallingSecurePref.getInstance() - The
APIsof SecurePref is the same as theSharedPreferenceapis. If you want for example setaccountNumberas 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.gradleat 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
plainTextnot encrypted for APIs < 18 - Encrypt only the values not the keys.