public final class MasterKey


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 MasterKey.Builder

Builder for generating a MasterKey.

Algorithm/Cipher choices used for the master key.

Constants

static final int

The default and recommended size for the master key.

static final String
DEFAULT_MASTER_KEY_ALIAS = "_androidx_security_master_key_"

The default master key alias.

Public methods

static int

The default validity period for authentication in seconds.

int

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

boolean

Checks if this key is backed by the Android Keystore.

boolean

Gets whether the key is backed by strong box.

boolean

Gets whether user authentication is required to use this key.

@NonNull String

Constants

DEFAULT_AES_GCM_MASTER_KEY_SIZE

Added in 1.1.0-alpha07
public static final int DEFAULT_AES_GCM_MASTER_KEY_SIZE = 256

The default and recommended size for the master key.

DEFAULT_MASTER_KEY_ALIAS

Added in 1.1.0-alpha07
public static final String DEFAULT_MASTER_KEY_ALIAS = "_androidx_security_master_key_"

The default master key alias.

Public methods

getDefaultAuthenticationValidityDurationSeconds

Added in 1.1.0-alpha07
public static int getDefaultAuthenticationValidityDurationSeconds()

The default validity period for authentication in seconds.

getUserAuthenticationValidityDurationSeconds

Added in 1.1.0-alpha07
public int getUserAuthenticationValidityDurationSeconds()

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 isUserAuthenticationRequired returns true.

Returns
int

The duration the key is unlocked for in seconds.

isKeyStoreBacked

Added in 1.1.0-alpha07
public boolean isKeyStoreBacked()

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-alpha07
public boolean isStrongBoxBacked()

Gets whether the key is backed by strong box.

isUserAuthenticationRequired

Added in 1.1.0-alpha07
public boolean isUserAuthenticationRequired()

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()