Język

KeyGenParameterSpec.Builder.SetUserAuthenticationValidityDurationSeconds Method

Definition

Sets the duration of time (seconds) for which this key is authorized to be used after the user is successfully authenticated.

[Android.Runtime.Register("setUserAuthenticationValidityDurationSeconds", "(I)Landroid/security/keystore/KeyGenParameterSpec$Builder;", "", ApiSince=23)]
public Android.Security.Keystore.KeyGenParameterSpec.Builder SetUserAuthenticationValidityDurationSeconds(int seconds);
[<Android.Runtime.Register("setUserAuthenticationValidityDurationSeconds", "(I)Landroid/security/keystore/KeyGenParameterSpec$Builder;", "", ApiSince=23)>]
member this.SetUserAuthenticationValidityDurationSeconds : int -> Android.Security.Keystore.KeyGenParameterSpec.Builder

Parameters

seconds
Int32

duration in seconds or -1 if user authentication must take place for every use of the key. Value is -1 or greater

Returns

Attributes

Remarks

This method was deprecated in API level 30. See setUserAuthenticationParameters(int, int)

Sets the duration of time (seconds) for which this key is authorized to be used after the user is successfully authenticated. This has effect if the key requires user authentication for its use (see setUserAuthenticationRequired(boolean)).

By default, if user authentication is required, it must take place for every use of the key.

Cryptographic operations involving keys which require user authentication to take place for every operation can only use biometric authentication. This is achieved by initializing a cryptographic operation (Signature, Cipher, Mac) with the key, wrapping it into a BiometricPrompt.CryptoObject, invoking BiometricPrompt.authenticate with CryptoObject, and proceeding with the cryptographic operation only if the authentication flow succeeds.

Cryptographic operations involving keys which are authorized to be used for a duration of time after a successful user authentication event can only use secure lock screen authentication. These cryptographic operations will throw UserNotAuthenticatedException during initialization if the user needs to be authenticated to proceed. This situation can be resolved by the user unlocking the secure lock screen of the Android or by going through the confirm credential flow initiated by KeyguardManager.createConfirmDeviceCredentialIntent(CharSequence,CharSequence). Once resolved, initializing a new cryptographic operation using this key (or any other key which is authorized to be used for a fixed duration of time after user authentication) should succeed provided the user authentication flow completed successfully.

Android reference for android.security.keystore.KeyGenParameterSpec.Builder.setUserAuthenticationValidityDurationSeconds.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to