StorageHelper Class

  • java.lang.Object
    • com.microsoft.aad.adal.StorageHelper

public class StorageHelper

Shared preferences store clear text. This class helps to encrypt/decrypt text to store. API SDK>= 18 has more security with AndroidKeyStore. Note: StorageHelper is designed for the ADAL internal encryption/decryption. Don't take dependency on it for external use.

Field Summary

Modifier and Type Field and Description
final int DATA_KEY_LENGTH

IV Key length for AES-128.

final int HMAC_LENGTH

256 bits output for signing message.

final String VERSION_ANDROID_KEY_STORE

Indicate that token item is encrypted with the key persisted in AndroidKeyStore.

final String VERSION_USER_DEFINED

Indicate that the token item is encrypted with the user provided key.

Constructor Summary

Constructor Description
StorageHelper(Context context)

Constructor for StorageHelper.

Method Summary

Modifier and Type Method and Description
String decrypt(final String encryptedBlob)

Decrypt encrypted blob with either user provided key or key persisted in AndroidKeyStore.

String encrypt(final String clearText)

Encrypt text with current key based on API level.

Field Details

DATA_KEY_LENGTH

public static final int DATA_KEY_LENGTH= 16

IV Key length for AES-128.

HMAC_LENGTH

public static final int HMAC_LENGTH= 32

256 bits output for signing message.

VERSION_ANDROID_KEY_STORE

public static final String VERSION_ANDROID_KEY_STORE= "A001"

Indicate that token item is encrypted with the key persisted in AndroidKeyStore.

VERSION_USER_DEFINED

public static final String VERSION_USER_DEFINED= "U001"

Indicate that the token item is encrypted with the user provided key.

Constructor Details

StorageHelper

public StorageHelper(Context context)

Constructor for StorageHelper.

Parameters:

context - The Context to create StorageHelper.

Method Details

decrypt

public String decrypt(final String encryptedBlob)

Decrypt encrypted blob with either user provided key or key persisted in AndroidKeyStore.

Parameters:

encryptedBlob - The blob to decrypt

Returns:

Decrypted clear text.

Throws:

GeneralSecurityException - for key related exceptions.
IOException - For general IO related exceptions.

encrypt

public String encrypt(final String clearText)

Encrypt text with current key based on API level.

Parameters:

clearText - Clear text to encrypt.

Returns:

Encrypted blob.

Throws:

GeneralSecurityException - for key related exceptions.
IOException - For general IO related exceptions.

Applies to