Enterprise Data Guard Kit allows an app to delete an existing enterprise recovery key in scenarios where related data needs to be deleted when the enterprise recovery key is leaked or disabled.
For details about these APIs, please refer to the API Reference.
| API | Description |
|---|---|
| deleteEnterpriseRecoveryKey(userId: number, signature: Uint8Array): Promise<number> | Deletes data related to the enterprise recovery key using a promise. |
Import required modules.
import { BusinessError, osAccount } from '@kit.BasicServicesKit';
import { recoveryKey } from '@kit.EnterpriseDataGuardKit';
import { hilog } from '@kit.PerformanceAnalysisKit'; Call the getAuthChallenge API to obtain a challenge and sign it. Then call the deleteEnterpriseRecoveryKey API and pass the user ID of the enterprise recovery key to be deleted and the signature of the challenge.
const TAG: string = 'EnterpriseRecoveryKey_Delete';
const DOMAIN: number = 0x0000;
async function testDeleteEnterpriseRecoveryKey() {
try {
let accountManager: osAccount.AccountManager = osAccount.getAccountManager();
let userId: number = await accountManager.getOsAccountLocalId();
// Replace signature with the real signature generated using the enterprise's public key, private key, and challenge.
let signature: Uint8Array = new Uint8Array([0]);
recoveryKey.deleteEnterpriseRecoveryKey(userId, signature).then((ret: number) => {
hilog.info(DOMAIN, TAG, `Succeeded in deleting enterprise recovery key. result is: ${ret}`);
}).catch((err: BusinessError) => {
hilog.error(DOMAIN, TAG, `Failed to delete enterprise recovery key. Code: ${err.code}, message: ${err.message}`);
});
} catch (e) {
hilog.error(DOMAIN, TAG, `Failed to testDeleteEnterpriseRecoveryKey. Code: ${e.code}, message: ${e.message}`);
}
}