androidx.security.crypto


Classes

EncryptedFile

This class is deprecated.

Use java.io.File instead.

EncryptedFile.Builder

This class is deprecated.

Use java.io.File instead.

EncryptedSharedPreferences

This class is deprecated.

Use android.content.SharedPreferences instead.

MasterKey

This class is deprecated.

Use javax.crypto.KeyGenerator with AndroidKeyStore instance instead.

MasterKey.Builder

This class is deprecated.

Use javax.crypto.KeyGenerator with AndroidKeyStore instance instead.

MasterKeys

This class is deprecated.

Use javax.crypto.KeyGenerator with AndroidKeyStore instance instead.

Enums

EncryptedFile.FileEncryptionScheme

This enum is deprecated.

Use java.io.File instead.

EncryptedSharedPreferences.PrefKeyEncryptionScheme

This enum is deprecated.

Use android.content.SharedPreferences instead.

EncryptedSharedPreferences.PrefValueEncryptionScheme

This enum is deprecated.

Use android.content.SharedPreferences instead.

MasterKey.KeyScheme

This enum is deprecated.

Use javax.crypto.KeyGenerator with AndroidKeyStore instance instead.

Top-level functions summary

EncryptedFile
EncryptedFile(
    context: Context,
    file: File,
    masterKey: MasterKey,
    fileEncryptionScheme: EncryptedFile.FileEncryptionScheme,
    keysetPrefName: String?,
    keysetAlias: String?
)

This function is deprecated. Use java.io.File instead

SharedPreferences
EncryptedSharedPreferences(
    context: Context,
    fileName: String,
    masterKey: MasterKey,
    prefKeyEncryptionScheme: EncryptedSharedPreferences.PrefKeyEncryptionScheme,
    prefValueEncryptionScheme: EncryptedSharedPreferences.PrefValueEncryptionScheme
)

This function is deprecated. Use android.content.SharedPreferences instead

MasterKey
MasterKey(
    context: Context,
    keyAlias: String,
    keyScheme: MasterKey.KeyScheme,
    authenticationRequired: Boolean,
    userAuthenticationValidityDurationSeconds: Int,
    requestStrongBoxBacked: Boolean
)

This function is deprecated. Use Android Keystore directly instead

Top-level functions

EncryptedFile

fun EncryptedFile(
    context: Context,
    file: File,
    masterKey: MasterKey,
    fileEncryptionScheme: EncryptedFile.FileEncryptionScheme = FileEncryptionScheme.AES256_GCM_HKDF_4KB,
    keysetPrefName: String? = null,
    keysetAlias: String? = null
): EncryptedFile

Creates an EncryptedFile

Parameters
context: Context

The context to work with.

file: File

The backing File.

masterKey: MasterKey

The MasterKey that should be used.

fileEncryptionScheme: EncryptedFile.FileEncryptionScheme = FileEncryptionScheme.AES256_GCM_HKDF_4KB

The FileEncryptionScheme to use, defaulting to FileEncryptionScheme.AES256_GCM_HKDF_4KB.

keysetPrefName: String? = null

The SharedPreferences file to store the keyset for this EncryptedFile.

keysetAlias: String? = null

The alias in the SharedPreferences file to store the keyset for this EncryptedFile.

EncryptedSharedPreferences

fun EncryptedSharedPreferences(
    context: Context,
    fileName: String,
    masterKey: MasterKey,
    prefKeyEncryptionScheme: EncryptedSharedPreferences.PrefKeyEncryptionScheme = PrefKeyEncryptionScheme.AES256_SIV,
    prefValueEncryptionScheme: EncryptedSharedPreferences.PrefValueEncryptionScheme = PrefValueEncryptionScheme.AES256_GCM
): SharedPreferences

Opens an instance of encrypted SharedPreferences

Parameters
fileName: String

The name of the file to open; can not contain path separators.

masterKey: MasterKey

The master key to use.

prefKeyEncryptionScheme: EncryptedSharedPreferences.PrefKeyEncryptionScheme = PrefKeyEncryptionScheme.AES256_SIV

The scheme to use for encrypting keys.

prefValueEncryptionScheme: EncryptedSharedPreferences.PrefValueEncryptionScheme = PrefValueEncryptionScheme.AES256_GCM

The scheme to use for encrypting values.

Returns
SharedPreferences

The SharedPreferences instance that encrypts all data.

fun MasterKey(
    context: Context,
    keyAlias: String = MasterKey.DEFAULT_MASTER_KEY_ALIAS,
    keyScheme: MasterKey.KeyScheme = MasterKey.KeyScheme.AES256_GCM,
    authenticationRequired: Boolean = false,
    userAuthenticationValidityDurationSeconds: Int = MasterKey.getDefaultAuthenticationValidityDurationSeconds(),
    requestStrongBoxBacked: Boolean = false
): MasterKey

Creates a MasterKey with the provided parameters.

Parameters
context: Context

The context to work with.

keyAlias: String = MasterKey.DEFAULT_MASTER_KEY_ALIAS

The alias to use for the MasterKey.

keyScheme: MasterKey.KeyScheme = MasterKey.KeyScheme.AES256_GCM

The MasterKey.KeyScheme to have the MasterKey use.

authenticationRequired: Boolean = false

true if the user must authenticate for the MasterKey to be used.

userAuthenticationValidityDurationSeconds: Int = MasterKey.getDefaultAuthenticationValidityDurationSeconds()

Duration in seconds that the MasterKey is valid for after the user has authenticated. Must be a value 0.

requestStrongBoxBacked: Boolean = false

true if the key should be stored in Strong Box, if possible.