Android EncryptUtils

A set of classes to conceal credentials

License

License

GroupId

GroupId

com.github.gfx.util.encrypt
ArtifactId

ArtifactId

encrypt-utils
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

Android EncryptUtils
A set of classes to conceal credentials
Project URL

Project URL

https://github.com/gfx/Android-EncryptUtils
Source Code Management

Source Code Management

https://github.com/gfx/Android-EncryptUtils

Download encrypt-utils

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.gfx.util.encrypt/encrypt-utils/ -->
<dependency>
    <groupId>com.github.gfx.util.encrypt</groupId>
    <artifactId>encrypt-utils</artifactId>
    <version>1.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.gfx.util.encrypt/encrypt-utils/
implementation 'com.github.gfx.util.encrypt:encrypt-utils:1.1.0'
// https://jarcasting.com/artifacts/com.github.gfx.util.encrypt/encrypt-utils/
implementation ("com.github.gfx.util.encrypt:encrypt-utils:1.1.0")
'com.github.gfx.util.encrypt:encrypt-utils:aar:1.1.0'
<dependency org="com.github.gfx.util.encrypt" name="encrypt-utils" rev="1.1.0">
  <artifact name="encrypt-utils" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.github.gfx.util.encrypt', module='encrypt-utils', version='1.1.0')
)
libraryDependencies += "com.github.gfx.util.encrypt" % "encrypt-utils" % "1.1.0"
[com.github.gfx.util.encrypt/encrypt-utils "1.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.support » support-annotations jar +

Project Modules

There are no modules declared in this project.

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.

Versions

Version
1.1.0
1.0.0