public final class

MasterKey.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.security.crypto.MasterKey.Builder

Overview

Builder for generating a MasterKey.

Summary

Constructors
publicBuilder(Context context)

Creates a builder for a MasterKey using the default alias of MasterKey.DEFAULT_MASTER_KEY_ALIAS.

publicBuilder(Context context, java.lang.String keyAlias)

Creates a builder for a MasterKey.

Methods
public MasterKeybuild()

Builds a MasterKey from this builder.

public MasterKey.BuildersetKeyGenParameterSpec(KeyGenParameterSpec keyGenParameterSpec)

Sets a custom KeyGenParameterSpec to use as the basis of the master key.

public MasterKey.BuildersetKeyScheme(MasterKey.KeyScheme keyScheme)

Sets a MasterKey.KeyScheme to be used for the master key.

public MasterKey.BuildersetRequestStrongBoxBacked(boolean requestStrongBoxBacked)

Sets whether or not to request this key is strong box backed.

public MasterKey.BuildersetUserAuthenticationRequired(boolean authenticationRequired)

When used with MasterKey.Builder, sets that the built master key should require the user to authenticate before it's unlocked, probably using the androidx.biometric library.

public MasterKey.BuildersetUserAuthenticationRequired(boolean authenticationRequired, int userAuthenticationValidityDurationSeconds)

When used with MasterKey.Builder, sets that the built master key should require the user to authenticate before it's unlocked, probably using the androidx.biometric library, and that the key should remain unlocked for the provided duration.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Context context)

Creates a builder for a MasterKey using the default alias of MasterKey.DEFAULT_MASTER_KEY_ALIAS.

Parameters:

context: The context to use with this master key.

public Builder(Context context, java.lang.String keyAlias)

Creates a builder for a MasterKey.

Parameters:

context: The context to use with this master key.

Methods

public MasterKey.Builder setKeyScheme(MasterKey.KeyScheme keyScheme)

Sets a MasterKey.KeyScheme to be used for the master key.

This uses a default KeyGenParameterSpec associated with the provided KeyScheme.

NOTE: Either this method OR MasterKey.Builder.setKeyGenParameterSpec(KeyGenParameterSpec) should be used to set the parameters to use for building the master key. Calling either function after the other will throw an java.lang.IllegalArgumentException.

Parameters:

keyScheme: The KeyScheme to use.

Returns:

This builder.

public MasterKey.Builder setUserAuthenticationRequired(boolean authenticationRequired)

When used with MasterKey.Builder, sets that the built master key should require the user to authenticate before it's unlocked, probably using the androidx.biometric library.

This method sets the validity duration of the key to MasterKey.getDefaultAuthenticationValidityDurationSeconds().

Parameters:

authenticationRequired: Whether user authentication should be required to use the key.

Returns:

This builder.

public MasterKey.Builder setUserAuthenticationRequired(boolean authenticationRequired, int userAuthenticationValidityDurationSeconds)

When used with MasterKey.Builder, sets that the built master key should require the user to authenticate before it's unlocked, probably using the androidx.biometric library, and that the key should remain unlocked for the provided duration.

Parameters:

authenticationRequired: Whether user authentication should be required to use the key.
userAuthenticationValidityDurationSeconds: Duration in seconds that the key should remain unlocked following user authentication.

Returns:

This builder.

public MasterKey.Builder setRequestStrongBoxBacked(boolean requestStrongBoxBacked)

Sets whether or not to request this key is strong box backed. This setting is only applicable on and above, and only on devices that support Strongbox.

Parameters:

requestStrongBoxBacked: Whether to request to use strongbox

Returns:

This builder.

public MasterKey.Builder setKeyGenParameterSpec(KeyGenParameterSpec keyGenParameterSpec)

Sets a custom KeyGenParameterSpec to use as the basis of the master key. NOTE: Either this method OR MasterKey.Builder should be used to set the parameters to use for building the master key. Calling either function after the other will throw an java.lang.IllegalArgumentException.

Parameters:

keyGenParameterSpec: The key spec to use.

Returns:

This builder.

public MasterKey build()

Builds a MasterKey from this builder.

Returns:

The master key.