This library is obsolete. Use androidx.security.crypto.EncryptedSharedPreferences instead.
This is a set of class libraries that provides a way to save credentials in Android devices.
Note that this is not perfectly secure because private keys could not be concealed so the attacker are able to decrypt data if they have the device and enough time. However, this library should prevent data from 10-minutes cracking.
dependencies {
compile 'com.github.gfx.util.encrypt:android-encrypt-utils:2.0.0'
}
This is a utility to encrypt and decrypt credentials.
Encryption
creates a private key from context
's
packag name and ANDROID_ID
by default.
Encryption encryption = new Encryption(Encryption.getDefaultCipher() ,context);
String plainText = ...;
String encrypted = encryption.encrypt(plainText);
String decrypted = encryption.decrypt(encrypted);
assert plainText.equals(decrypted);
You can also specify a private key instead of a context.
byte[] privateKey = ...;
assert privateKey.length == 16; // you must ensure!
Encryption encryption = new Encryption(Encryption.getDefaultCipher(), privateKey);
This is an implementation of SharedPreferences that encrypts data.
SharedPreferences prefs = new EncryptedSharedPreferences(Encryption.getDefaultCipher(), context);
prefs.editor()
.putString("email", email)
.putString("password", password)
.apply();
As SharedPreferences
does, EncryptedSHaredPreferences
saves data in XML and its values
are encrypted in AES while
its keys are just encoded in Base64 format.
The following content is an example of shared preferences file:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="Zm9v">WvfCT5pyTP9srHQxf5nKXxH7Cw==</string>
<string name="YmFy">RpLGPJ736a9vctawIz9IbCBYeA==</string>
</map>
FUJI Goro (gfx) gfuji@cpan.org
This is a free software licensed in Apache License 2.0. See LICENSE for details.