# androidx.security.crypto

*** ** * ** ***

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile` | **This class is deprecated.** Use `https://developer.android.com/reference/java/io/File.html` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile.Builder` | **This class is deprecated.** Use `https://developer.android.com/reference/java/io/File.html` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences` | **This class is deprecated.** Use `https://developer.android.com/reference/android/content/SharedPreferences.html` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey` | **This class is deprecated.** Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey.Builder` | **This class is deprecated.** Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKeys` | **This class is deprecated.** Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead. <br /> |

## Enums

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile.FileEncryptionScheme` | **This enum is deprecated.** Use `https://developer.android.com/reference/java/io/File.html` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.PrefKeyEncryptionScheme` | **This enum is deprecated.** Use `https://developer.android.com/reference/android/content/SharedPreferences.html` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.PrefValueEncryptionScheme` | **This enum is deprecated.** Use `https://developer.android.com/reference/android/content/SharedPreferences.html` instead. <br /> |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey.KeyScheme` | **This enum is deprecated.** Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead. <br /> |

## Top-level functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile` | `[EncryptedFile](https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedFile(android.content.Context,java.io.File,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedFile.FileEncryptionScheme,kotlin.String,kotlin.String))( context: https://developer.android.com/reference/android/content/Context.html, file: https://developer.android.com/reference/java/io/File.html, masterKey: https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey, fileEncryptionScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile.FileEncryptionScheme, keysetPrefName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, keysetAlias: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? )` **This function is deprecated.** Use java.io.File instead |
| `https://developer.android.com/reference/android/content/SharedPreferences.html` | `[EncryptedSharedPreferences](https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedSharedPreferences(android.content.Context,kotlin.String,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedSharedPreferences.PrefKeyEncryptionScheme,androidx.security.crypto.EncryptedSharedPreferences.PrefValueEncryptionScheme))( context: https://developer.android.com/reference/android/content/Context.html, fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, masterKey: https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey, prefKeyEncryptionScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.PrefKeyEncryptionScheme, prefValueEncryptionScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.PrefValueEncryptionScheme )` **This function is deprecated.** Use android.content.SharedPreferences instead |
| `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey` | `[MasterKey](https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#MasterKey(android.content.Context,kotlin.String,androidx.security.crypto.MasterKey.KeyScheme,kotlin.Boolean,kotlin.Int,kotlin.Boolean))( context: https://developer.android.com/reference/android/content/Context.html, keyAlias: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, keyScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey.KeyScheme, authenticationRequired: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, userAuthenticationValidityDurationSeconds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, requestStrongBoxBacked: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` **This function is deprecated.** Use Android Keystore directly instead |

## Top-level functions

### EncryptedFile

Artifact: [androidx.security:security-crypto-ktx](https://developer.android.com/jetpack/androidx/releases/security) [View Source](https://cs.android.com/search?q=file:androidx/security/crypto/EncryptedFile.kt+function:EncryptedFile) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0)

```
fun [EncryptedFile](https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedFile(android.content.Context,java.io.File,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedFile.FileEncryptionScheme,kotlin.String,kotlin.String))(
    context: Context,
    file: File,
    masterKey: MasterKey,
    fileEncryptionScheme: EncryptedFile.FileEncryptionScheme = FileEncryptionScheme.AES256_GCM_HKDF_4KB,
    keysetPrefName: String? = null,
    keysetAlias: String? = null
): EncryptedFile
```

> [!CAUTION]
> **This function is deprecated.**   
> Use java.io.File instead

Creates an `https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedFile(android.content.Context,java.io.File,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedFile.FileEncryptionScheme,kotlin.String,kotlin.String)`

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The context to work with. |
| `file: https://developer.android.com/reference/java/io/File.html` | The backing `https://developer.android.com/reference/java/io/File.html`. |
| `masterKey: https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey` | The `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey` that should be used. |
| `fileEncryptionScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile.FileEncryptionScheme = FileEncryptionScheme.AES256_GCM_HKDF_4KB` | The `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile.FileEncryptionScheme` to use, defaulting to `https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedFile.FileEncryptionScheme#AES256_GCM_HKDF_4KB`. |
| `keysetPrefName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | The `SharedPreferences` file to store the keyset for this `https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedFile(android.content.Context,java.io.File,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedFile.FileEncryptionScheme,kotlin.String,kotlin.String)`. |
| `keysetAlias: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | The alias in the `SharedPreferences` file to store the keyset for this `https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedFile(android.content.Context,java.io.File,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedFile.FileEncryptionScheme,kotlin.String,kotlin.String)`. |

### EncryptedSharedPreferences

Artifact: [androidx.security:security-crypto-ktx](https://developer.android.com/jetpack/androidx/releases/security) [View Source](https://cs.android.com/search?q=file:androidx/security/crypto/EncryptedSharedPreferences.kt+function:EncryptedSharedPreferences) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0)

```
fun [EncryptedSharedPreferences](https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#EncryptedSharedPreferences(android.content.Context,kotlin.String,androidx.security.crypto.MasterKey,androidx.security.crypto.EncryptedSharedPreferences.PrefKeyEncryptionScheme,androidx.security.crypto.EncryptedSharedPreferences.PrefValueEncryptionScheme))(
    context: Context,
    fileName: String,
    masterKey: MasterKey,
    prefKeyEncryptionScheme: EncryptedSharedPreferences.PrefKeyEncryptionScheme = PrefKeyEncryptionScheme.AES256_SIV,
    prefValueEncryptionScheme: EncryptedSharedPreferences.PrefValueEncryptionScheme = PrefValueEncryptionScheme.AES256_GCM
): SharedPreferences
```

> [!CAUTION]
> **This function is deprecated.**   
> Use android.content.SharedPreferences instead

Opens an instance of encrypted SharedPreferences

| Parameters |
|---|---|
| `fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the file to open; can not contain path separators. |
| `masterKey: https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey` | The master key to use. |
| `prefKeyEncryptionScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.PrefKeyEncryptionScheme = PrefKeyEncryptionScheme.AES256_SIV` | The scheme to use for encrypting keys. |
| `prefValueEncryptionScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/EncryptedSharedPreferences.PrefValueEncryptionScheme = PrefValueEncryptionScheme.AES256_GCM` | The scheme to use for encrypting values. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/SharedPreferences.html` | The SharedPreferences instance that encrypts all data. |

### MasterKey

Artifact: [androidx.security:security-crypto-ktx](https://developer.android.com/jetpack/androidx/releases/security) [View Source](https://cs.android.com/search?q=file:androidx/security/crypto/MasterKey.kt+function:MasterKey) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/security#1.1.0)

```
fun [MasterKey](https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#MasterKey(android.content.Context,kotlin.String,androidx.security.crypto.MasterKey.KeyScheme,kotlin.Boolean,kotlin.Int,kotlin.Boolean))(
    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
```

> [!CAUTION]
> **This function is deprecated.**   
> Use Android Keystore directly instead

Creates a `https://developer.android.com/reference/kotlin/androidx/security/crypto/package-summary#MasterKey(android.content.Context,kotlin.String,androidx.security.crypto.MasterKey.KeyScheme,kotlin.Boolean,kotlin.Int,kotlin.Boolean)` with the provided parameters.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The context to work with. |
| `keyAlias: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = MasterKey.DEFAULT_MASTER_KEY_ALIAS` | The alias to use for the `MasterKey`. |
| `keyScheme: https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey.KeyScheme = MasterKey.KeyScheme.AES256_GCM` | The `https://developer.android.com/reference/kotlin/androidx/security/crypto/MasterKey.KeyScheme` to have the `MasterKey` use. |
| `authenticationRequired: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | `true` if the user must authenticate for the `MasterKey` to be used. |
| `userAuthenticationValidityDurationSeconds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = MasterKey.getDefaultAuthenticationValidityDurationSeconds()` | Duration in seconds that the `MasterKey` is valid for after the user has authenticated. Must be a value \> 0. |
| `requestStrongBoxBacked: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = false` | `true` if the key should be stored in Strong Box, if possible. |