When a user no longer needs to use the digital shield, they can disable the digital shield through password authentication. If a user forgets the password or the number of consecutive password authentication failures reaches the upper limit, the digital shield password will be locked. When the digital shield is reactivated, the enterprise app will disable the initially activated digital shield without password authentication and create a new digital shield password through operations in digital shield password setup.
In versions earlier than 6.1.1(24), this function is supported only on mobile phones. In 6.1.1(24) and later versions, this function is supported on PCs/2-in-1 devices and tablets with the TUI capability. You can call the checkConfirmUITextFormat API to check whether a device has the TUI capability. When an unsupported device calls the service APIs of the Digital Shield service, error code 1019100016 is returned.

If password authentication is not required in a request to disable the digital shield, the entire process will not involve Universal Keystore Kit. The challenge generated randomly will be used to disable the digital shield.
For details about the APIs and their usage, see API Reference.
| API | Description |
|---|---|
| disableTrustedAuthentication(challenge: Uint8Array, needAuth: boolean, authID: bigint, label: TUILable): Promise<AuthToken> | Disables the digital shield service. |
Import the huks module, trustedAuthentication module, and dependent modules.
import { resourceManager } from '@kit.LocalizationKit'
import { huks } from '@kit.UniversalKeystoreKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { trustedAuthentication } from '@kit.DeviceSecurityKit';
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { common } from '@kit.AbilityKit'; Before disabling the digital shield, retrieve the authID value obtained during digital shield password setup from the server for the current account.
Initialize the signature session. For details, please refer to Signing and Signature Verification of Universal Keystore Kit.
Call the API for disabling the digital shield service to initiate a digital shield disabling request.
async DisablePwd(challenge: Uint8Array, assetName: string): Promise<trustedAuthentication.AuthToken> {
try {
let resArray: Uint8Array = await AssetUtils.QueryDataFromAssetStore(assetName);
let credentialID: bigint = CryptoUtils.uint8ArrayToBigInt(resArray);
const context = AppStorage.get('context') as Context;
const buffer: ArrayBuffer = await CryptoUtils.ImportImage();
const label: trustedAuthentication.TUILable = {
image: buffer,
title: context.resourceManager.getStringSync($r('app.string.CloseShield').id)
}
const authInfo = await trustedAuthentication.disableTrustedAuthentication(challenge, true, credentialID, label);
AssetUtils.DeleteDataFromAssetStore('pin_label1');
AssetUtils.DeleteDataFromAssetStore('credentialID');
AssetUtils.DeleteDataFromAssetStore('face_credentialID');
AssetUtils.DeleteDataFromAssetStore('finger_credentialID');
hilog.info(DOMAIN, 'testTag', 'Close Shield Success: ', authInfo.authToken);
return authInfo;
} catch (error) {
hilog.error(DOMAIN, 'testTag', 'Close Shield Fail: ', error);
throw new Error('Close Shield Fail: ' + (error as BusinessError).message);
}
} Sign the authToken obtained through disabling the digital shield by referring to Signing and Signature Verification of Universal Keystore Kit. Then end the session.
Use the 32-byte random number generated by the cryptoFramework as the challenge and directly call the API for disabling the digital shield service. The generated authToken information is not authenticated by password and cannot be used for signature verification.
async disablePwdWithoutAuth(challenge: Uint8Array, assetName: string): Promise<ArrayBuffer> {
try {
let resArray: Uint8Array = await AssetUtils.QueryDataFromAssetStore(assetName);
let credentialID: bigint = CryptoUtils.uint8ArrayToBigInt(resArray); // In actual use, replace the value with the credentialID of the account obtained from the server.
let emptyBuffer = new ArrayBuffer(0);
const label: trustedAuthentication.TUILable = {
image: emptyBuffer,
title: ''
}
const authInfo = await trustedAuthentication.disableTrustedAuthentication(challenge, false, credentialID, label);
// Replace it with the process of deleting the digital shield on the server side in actual use.
AssetUtils.DeleteDataFromAssetStore('pin_label1');
AssetUtils.DeleteDataFromAssetStore('credentialID');
AssetUtils.DeleteDataFromAssetStore('face_credentialID');
AssetUtils.DeleteDataFromAssetStore('finger_credentialID');
hilog.info(DOMAIN, 'testTag', 'Close Shield Success: ', authInfo.authToken);
return authInfo.authToken;
} catch (error) {
hilog.error(DOMAIN, 'testTag', 'Close Shield Fail: ', error);
throw new Error('Close Shield Fail: ' + (error as BusinessError).message);
}
}