public class BiometricAuthentication extends Object
This class provides methods for checking the biometric authentication capability, and performing and canceling authentication.
SystemCapability.UserIAM#BIOMETRIC_AUTH| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
BiometricAuthentication.AuthenticationTips |
Provides the authentication tips.
|
static class |
BiometricAuthentication.AuthType |
Indicates the authentication type.
|
static class |
BiometricAuthentication.SecureLevel |
Indicates the security level of the data to access.
|
static class |
BiometricAuthentication.SystemAuthDialogInfo |
Provides the customized authentication tips in the system-provided authentication dialog box.
|
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
BA_CHECK_AUTH_TYPE_NOT_SUPPORT |
Indicates that this type of biometric authentication is not supported.
|
static int |
BA_CHECK_DISTRIBUTED_AUTH_NOT_SUPPORT |
Indicates that distributed authentication is not supported.
|
static int |
BA_CHECK_NOT_ENROLLED |
Indicates that no biometric characteristic has been enrolled in the device.
|
static int |
BA_CHECK_SECURE_LEVEL_NOT_SUPPORT |
Indicates that the security level of the biometric authentication is not supported.
|
static int |
BA_CHECK_SUPPORTED |
Indicates that biometric authentication is supported.
|
static int |
BA_CHECK_UNAVAILABLE |
Indicates that this type of biometric authentication is unavailable.
|
static int |
BA_FAILED |
Indicates that a failed execution.
|
static int |
BA_SUCCESS |
Indicates that a successful execution.
|
static int |
INVALID_BIOMETRIC_ID |
Indicates the id for biometric authentication.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
int |
cancelAuthenticationAction() |
Cancels biometric authentication.
|
int |
checkAuthenticationAvailability(BiometricAuthentication.AuthType type,
BiometricAuthentication.SecureLevel level,
boolean isLocalAuth) |
Checks whether a device supports biometric authentication.
|
int |
execAuthenticationAction(BiometricAuthentication.AuthType type,
BiometricAuthentication.SecureLevel level,
boolean isLocalAuth,
boolean isAppAuthDialog,
BiometricAuthentication.SystemAuthDialogInfo information) |
Performs biometric authentication.
|
BiometricAuthentication.AuthenticationTips |
getAuthenticationTips() |
Obtains authentication tips.
|
static BiometricAuthentication |
getInstance(Ability ability) |
Obtains a
BiometricAuthentication singleton object. |
Cipher |
getSecureObjectCipher() |
Obtains an authorized
Cipher object. |
Mac |
getSecureObjectMac() |
Obtains an authorized
Mac object. |
Signature |
getSecureObjectSignature() |
Obtains an authorized
Signature object. |
void |
setSecureObjectCipher(Cipher cipher) |
Sets the
Cipher object associated with the authentication result. |
void |
setSecureObjectMac(Mac mac) |
Sets the
Mac object associated with the authentication result. |
void |
setSecureObjectSignature(Signature sign) |
Sets the
Signature object associated with the authentication result. |
public static final int BA_CHECK_AUTH_TYPE_NOT_SUPPORT
public static final int BA_CHECK_DISTRIBUTED_AUTH_NOT_SUPPORT
public static final int BA_CHECK_NOT_ENROLLED
public static final int BA_CHECK_SECURE_LEVEL_NOT_SUPPORT
public static final int BA_CHECK_SUPPORTED
public static final int BA_CHECK_UNAVAILABLE
public static final int BA_FAILED
public static final int BA_SUCCESS
public static final int INVALID_BIOMETRIC_ID
public static BiometricAuthentication getInstance(Ability ability) throws IllegalAccessException
BiometricAuthentication singleton object.
This method requires ohos.permission.ACCESS_BIOMETRIC.
ability - Indicates the smallest deployment unit on the HarmonyOS, which is defined
in Ability.BiometricAuthentication singleton object.IllegalArgumentException - Throws this exception if the input parameter is null.IllegalAccessException - Throws this exception if the current process has not the permission.public int checkAuthenticationAvailability(BiometricAuthentication.AuthType type, BiometricAuthentication.SecureLevel level, boolean isLocalAuth)
This method is used to check whether the device supports biometric authentication based on AuthType,
SecureLevel, and isLocalAuth. If biometric authentication is not supported, consider using
other authentication capabilities.
type - Indicates the authentication type, which is specified by AuthType.level - Indicates the security level, which is specified by SecureLevel.isLocalAuth - Indicates whether local authentication is used. Value false indicates distributed
authentication. Currently, only local authentication is supported.BA_CHECK_SUPPORTED if the device supports biometric authentication.
Other return values can be referenced by BA_CHECK_AUTH_TYPE_NOT_SUPPORT,
BA_CHECK_SECURE_LEVEL_NOT_SUPPORT, BA_CHECK_DISTRIBUTED_AUTH_NOT_SUPPORT,
BA_CHECK_NOT_ENROLLED, BA_CHECK_UNAVAILABLE, BA_FAILED.public int execAuthenticationAction(BiometricAuthentication.AuthType type, BiometricAuthentication.SecureLevel level, boolean isLocalAuth, boolean isAppAuthDialog, BiometricAuthentication.SystemAuthDialogInfo information)
You can use either the system-provided or a customized authentication dialog box. If you use the former,
you can customize the authentication tips. The authentication result is returned only after the authentication
is complete. To cancel the authentication, use cancelAuthenticationAction().
type - Indicates the authentication type, which is specified by AuthType.level - Indicates the security level, which is specified by SecureLevel.isLocalAuth - Indicates whether local authentication is used. Value false indicates distributed
authentication. Currently, only local authentication is supported.isAppAuthDialog - Indicates whether a customized authentication dialog box is used.information - Indicates the authentication tips in the system-provided authentication dialog box.IFaceAuthentication.FaceAuthResultCode.public BiometricAuthentication.AuthenticationTips getAuthenticationTips()
An example is the tip to adjust the face angle in face recognition.
AuthenticationTips.public int cancelAuthenticationAction()
Performing and canceling an authentication must be in different threads and have the same identifier. This method is used to cancel an ongoing biometric authentication.
BA_SUCCESS if the authentication is canceled;
returns BA_FAILED otherwise.public void setSecureObjectSignature(Signature sign)
Signature object associated with the authentication result.
If an authentication succeeds, the Signature object associated with the authentication result is
authorized and available. The Signature object must be initialized correctly before it is associated
with the authentication result.
sign - Indicates the Signature object to be associated with the authentication result.IllegalArgumentException - Throws this exception if the input parameter is not a Signature object.IllegalStateException - Throws this exception if the private key of the input parameter is not correctly
initialized.public Signature getSecureObjectSignature()
Signature object.Signature object;
returns null if no Signature object is authorized.public void setSecureObjectCipher(Cipher cipher)
Cipher object associated with the authentication result.
If an authentication succeeds, the Cipher object associated with the authentication result is
authorized and available. The Cipher object must be initialized correctly before it is associated with
the authentication result.
cipher - Indicates the Cipher object to be associated with the authentication result.IllegalArgumentException - Throws this exception if the input parameter is not a Cipher object.IllegalStateException - Throws this exception if the private key of the input parameter is not correctly
initialized.public Cipher getSecureObjectCipher()
Cipher object.Cipher object;
returns null if no Cipher object is authorized.public void setSecureObjectMac(Mac mac)
Mac object associated with the authentication result.
If an authentication succeeds, the Mac object associated with the authentication result is authorized
and available. The Mac object must be initialized correctly before it is associated with the
authentication result.
mac - Indicates the Mac object to be associated with the authentication result.IllegalArgumentException - Throws this exception if the input parameter is not a Mac object.IllegalStateException - Throws this exception if the private key of the input parameter is not correctly
initialized.public Mac getSecureObjectMac()
Mac object.Mac object; returns null if no Mac object is authorized.