# MasterKey

Artifact: [androidx.security:security-crypto](https://developer.android.com/jetpack/androidx/releases/security) [View Source](https://cs.android.com/search?q=file:androidx/security/crypto/MasterKey.java+class:androidx.security.crypto.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)

*** ** * ** ***


```
public final class MasterKey
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead.

Wrapper for a master key used in the library.

On Android M (API 23) and above, this is class references a key that's stored in the Android Keystore. On Android L (API 21, 22), there isn't a master key.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/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 /> |
| `public enum https://developer.android.com/reference/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 /> |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/security/crypto/MasterKey#DEFAULT_AES_GCM_MASTER_KEY_SIZE() = 256` **This field is deprecated.** Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead. <br /> |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/security/crypto/MasterKey#DEFAULT_MASTER_KEY_ALIAS() = "_androidx_security_master_key_"` **This field is deprecated.** Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead. <br /> |

| ### Public methods |
|---|---|
| `static int` | `[getDefaultAuthenticationValidityDurationSeconds](https://developer.android.com/reference/androidx/security/crypto/MasterKey#getDefaultAuthenticationValidityDurationSeconds())()` **This method is deprecated.** Deprecated in Java |
| `int` | `[getUserAuthenticationValidityDurationSeconds](https://developer.android.com/reference/androidx/security/crypto/MasterKey#getUserAuthenticationValidityDurationSeconds())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isKeyStoreBacked](https://developer.android.com/reference/androidx/security/crypto/MasterKey#isKeyStoreBacked())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isStrongBoxBacked](https://developer.android.com/reference/androidx/security/crypto/MasterKey#isStrongBoxBacked())()` **This method is deprecated.** Deprecated in Java |
| `boolean` | `[isUserAuthenticationRequired](https://developer.android.com/reference/androidx/security/crypto/MasterKey#isUserAuthenticationRequired())()` **This method is deprecated.** Deprecated in Java |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `[toString](https://developer.android.com/reference/androidx/security/crypto/MasterKey#toString())()` **This method is deprecated.** Deprecated in Java |

## Constants

### DEFAULT_AES_GCM_MASTER_KEY_SIZE

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)

```
public static final int DEFAULT_AES_GCM_MASTER_KEY_SIZE = 256
```

> [!CAUTION]
> **This field is deprecated.**   
>
> Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead.

The default and recommended size for the master key.

### DEFAULT_MASTER_KEY_ALIAS

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)

```
public static final String DEFAULT_MASTER_KEY_ALIAS = "_androidx_security_master_key_"
```

> [!CAUTION]
> **This field is deprecated.**   
>
> Use `https://docs.oracle.com/javase/8/docs/api/javax/crypto/KeyGenerator.html` with AndroidKeyStore instance instead.

The default master key alias.

## Public methods

### getDefaultAuthenticationValidityDurationSeconds

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)

```
public static int [getDefaultAuthenticationValidityDurationSeconds](https://developer.android.com/reference/androidx/security/crypto/MasterKey#getDefaultAuthenticationValidityDurationSeconds())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

The default validity period for authentication in seconds.

### getUserAuthenticationValidityDurationSeconds

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)

```
public int [getUserAuthenticationValidityDurationSeconds](https://developer.android.com/reference/androidx/security/crypto/MasterKey#getUserAuthenticationValidityDurationSeconds())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets the duration in seconds that the key is unlocked for following user authentication.

The value returned for this method is only meaningful on Android M+ (API 23) when `https://developer.android.com/reference/androidx/security/crypto/MasterKey#isUserAuthenticationRequired()` returns `true`.

| Returns |
|---|---|
| `int` | The duration the key is unlocked for in seconds. |

### isKeyStoreBacked

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)

```
public boolean [isKeyStoreBacked](https://developer.android.com/reference/androidx/security/crypto/MasterKey#isKeyStoreBacked())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Checks if this key is backed by the Android Keystore.

| Returns |
|---|---|
| `boolean` | `true` if the key is in Android Keystore, `false` otherwise. This method always returns false when called on Android Lollipop (API 21 and 22). |

### isStrongBoxBacked

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)

```
public boolean [isStrongBoxBacked](https://developer.android.com/reference/androidx/security/crypto/MasterKey#isStrongBoxBacked())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets whether the key is backed by strong box.

### isUserAuthenticationRequired

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)

```
public boolean [isUserAuthenticationRequired](https://developer.android.com/reference/androidx/security/crypto/MasterKey#isUserAuthenticationRequired())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Gets whether user authentication is required to use this key.

This method always returns `false` on Android L (API 21 + 22).

### toString

```
public @NonNull String [toString](https://developer.android.com/reference/androidx/security/crypto/MasterKey#toString())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java