新聞中心
場(chǎng)景介紹

目前創(chuàng)新互聯(lián)公司已為成百上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、雅安服務(wù)器托管、網(wǎng)站托管、服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計(jì)、沅江網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
當(dāng)前生物特征識(shí)別支持 2D 人臉識(shí)別、3D 人臉識(shí)別,可應(yīng)用于設(shè)備解鎖、應(yīng)用登錄、支付等身份認(rèn)證場(chǎng)景。
接口說(shuō)明
BiometricAuthentication 類提供了生物認(rèn)證的相關(guān)方法,包括檢測(cè)認(rèn)證能力、認(rèn)證和取消認(rèn)證等,用戶可以通過(guò)人臉等生物特征信息進(jìn)行認(rèn)證操作。在執(zhí)行認(rèn)證前,需要檢查設(shè)備是否支持該認(rèn)證能力,具體指認(rèn)證類型、安全級(jí)別和是否本地認(rèn)證。如果不支持,需要考慮使用其他認(rèn)證能力。
| 接口名 | 功能描述 |
|---|---|
| getInstance(Ability ability) | 獲取 BiometricAuthentication的單例對(duì)象。 |
| checkAuthenticationAvailability(AuthType type, SecureLevel level, boolean isLocalAuth) | 檢測(cè)設(shè)備是否具有生物認(rèn)證能力。 |
| execAuthenticationAction(AuthType type, SecureLevel level, boolean isLocalAuth,boolean isAppAuthDialog, SystemAuthDialogInfo information) | 調(diào)用者使用該方法進(jìn)行生物認(rèn)證??梢允褂米远x的認(rèn)證界面,也可以使用系統(tǒng)提供的認(rèn)證界面。當(dāng)使用系統(tǒng)認(rèn)證界面時(shí),調(diào)用者可以自定義提示語(yǔ)。該方法直到認(rèn)證結(jié)束才返回認(rèn)證結(jié)果。 |
| getAuthenticationTips() | 獲取生物認(rèn)證過(guò)程中的提示信息。 |
| cancelAuthenticationAction() | 取消生物認(rèn)證操作。 |
| setSecureObjectSignature(Signature sign) | 設(shè)置需要關(guān)聯(lián)認(rèn)證結(jié)果的Signature 對(duì)象,在進(jìn)行認(rèn)證操作后,如果認(rèn)證成功則Signature 對(duì)象被授權(quán)可以使用。設(shè)置前 Signature 對(duì)象需要正確初始化,且配置為認(rèn)證成功才能使用。 |
| getSecureObjectSignature() | 在認(rèn)證成功后,可通過(guò)該方法獲取已授權(quán)的 Signature 對(duì)象。如果未設(shè)置過(guò) Signature 對(duì)象,則返回 null。 |
| setSecureObjectCipher(Cipher cipher) | 設(shè)置需要關(guān)聯(lián)認(rèn)證結(jié)果的 Cipher 對(duì)象,在進(jìn)行認(rèn)證操作后,如果認(rèn)證成功則 Cipher 對(duì)象被授權(quán)可以使用。設(shè)置前 Cipher 對(duì)象需要正確初始化,且配置為認(rèn)證成功才能使用。 |
| getSecureObjectCipher() | 在認(rèn)證成功后,可通過(guò)該方法獲取已授權(quán)的 Cipher 對(duì)象。如果未設(shè)置過(guò) Cipher 對(duì)象,則返回 null。 |
| setSecureObjectMac(Mac mac) | 設(shè)置需要關(guān)聯(lián)認(rèn)證結(jié)果的 Mac 對(duì)象,在進(jìn)行認(rèn)證操作后,如果認(rèn)證成功則 Mac 對(duì)象被授權(quán)可以使用。設(shè)置前 Mac 對(duì)象需要正確初始化,且配置為認(rèn)證成功才能使用。 |
| getSecureObjectMac() | 在認(rèn)證成功后,可通過(guò)該方法獲取已授權(quán)的 Mac 對(duì)象。如果未設(shè)置過(guò) Mac 對(duì)象,則返回 null。 |
開發(fā)步驟
開發(fā)前請(qǐng)完成以下準(zhǔn)備工作:
- 在應(yīng)用配置權(quán)限文件中,增加 ohos.permission.ACCESS_BIOMETRIC 的權(quán)限聲明。
- 在使用生物特征識(shí)別認(rèn)證能力的代碼文件中增加 import ohos.biometrics.authentication.BiometricAuthentication。
開發(fā)過(guò)程:
- 獲取 BiometricAuthentication 的單例對(duì)象,代碼示例如下:
BiometricAuthentication mBiometricAuthentication = BiometricAuthentication.getInstance(MainAbility.mAbility);
- 檢測(cè)設(shè)備是否具有生物認(rèn)證能力:
2D 人臉識(shí)別建議使用 SECURE_LEVEL_S2,3D 人臉識(shí)別建議使用 SECURE_LEVEL_S3。代碼示例如下:
int retChkAuthAvb = mBiometricAuthentication.checkAuthenticationAvailability(
BiometricAuthentication.AuthType.AUTH_TYPE_BIOMETRIC_FACE_ONLY, BiometricAuthentication.SecureLevel.SECURE_LEVEL_S2, true);
- (可選)設(shè)置需要關(guān)聯(lián)認(rèn)證結(jié)果的 Signature 對(duì)象或 Cipher 對(duì)象或 Mac 對(duì)象,代碼示例如下:
// 定義一個(gè)Signature對(duì)象sign;
mBiometricAuthentication.setSecureObjectSignature(sign);
// 定義一個(gè)Cipher對(duì)象cipher;
mBiometricAuthentication.setSecureObjectCipher(cipher);
// 定義一個(gè)Mac對(duì)象mac;
mBiometricAuthentication.setSecureObjectMac(mac);
- 在新線程里面執(zhí)行認(rèn)證操作,避免阻塞其他操作,代碼示例如下:
new Thread(new Runnable() {
@Override
public void run() {
int retExcAuth;
retExcAuth = mBiometricAuthentication.execAuthenticationAction( BiometricAuthentication.AuthType.AUTH_TYPE_BIOMETRIC_FACE_ONLY, BiometricAuthentication.SecureLevel.SECURE_LEVEL_S2, true, false, null);
}
}).start();
- 獲得認(rèn)證過(guò)程中的提示信息,代碼示例如下:
AuthenticationTips mTips = mBiometricAuthentication.getAuthenticationTips();
- (可選)認(rèn)證成功后獲取已設(shè)置的 Signature 對(duì)象或 Cipher 對(duì)象或 Mac 對(duì)象,代碼示例如下:
Signature sign = mBiometricAuthentication.getSecureObjectSignature();
Cipher cipher = mBiometricAuthentication.getSecureObjectCipher();
Mac mac = mBiometricAuthentication.getSecureObjectMac();
- 認(rèn)證過(guò)程中取消認(rèn)證,代碼示例如下:
int ret = mBiometricAuthentication.cancelAuthenticationAction(); 網(wǎng)頁(yè)題目:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OS生物特征識(shí)別開發(fā)指導(dǎo)
文章URL:http://www.dlmjj.cn/article/dhcjihp.html


咨詢
建站咨詢
