gfx / Android-EncryptUtils

[obosolete] Encypted SharedPreferences

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This library is obsolete. Use androidx.security.crypto.EncryptedSharedPreferences instead.


Android-EncryptUtils Build Status Coverage Status

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.

Gradle Dependencies

dependencies {
    compile 'com.github.gfx.util.encrypt:android-encrypt-utils:2.0.0'
}

Encryption

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);

EncryptedSharedPreferences

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();

HOW DATA ARE STORED

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>

AUTHOR

FUJI Goro (gfx) gfuji@cpan.org

LICENSE

This is a free software licensed in Apache License 2.0. See LICENSE for details.

About

[obosolete] Encypted SharedPreferences

License:Apache License 2.0


Languages

Language:Java 100.0%