• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.keyManager (User Key Management) (System API)
2<!--Kit: Core File Kit-->
3<!--Subsystem: FileManagement-->
4<!--Owner: @wang_zhangjun; @zhuangzhuang-->
5<!--Designer: @wang_zhangjun; @zhuangzhuang; @renguang1116-->
6<!--Tester: @liuhonggang123; @yue-ye2; @juxiaopang-->
7<!--Adviser: @foryourself-->
8
9This module provides common functions related to user key management, including user key uninstallation.
10
11> **NOTE**
12>
13> - The initial APIs of this module are supported since API version 15. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14> - This topic describes only the system APIs provided by the module.
15
16## Modules to Import
17
18```ts
19import { keyManager } from "@kit.CoreFileKit";
20```
21
22## keyManager.deactivateUserKey
23
24deactivateUserKey(userId: number):void
25
26When the screen is locked, the specified user key is uninstalled synchronously. **(Currently, this API is available only to lock screen applications.)**
27
28**Required permission**: ohos.permission.STORAGE_MANAGER_CRYPT
29
30**System capability**: SystemCapability.FileManagement.StorageService.Encryption
31
32**System API**: This is a system API.
33
34**Parameters**
35
36  | Name    | Type  | Mandatory| Description|
37  | ---------- | ------ | ---- | ---- |
38  | userId | number | Yes  | User ID. This parameter specifies the user who currently logs in to the lock screen application.|
39
40**Error codes**
41
42For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
43
44| ID| Error Message|
45| -------- | -------- |
46| 201 | Permission verification failed. |
47| 202 | The caller is not a system application. |
48| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified; Or input parameter has type different from the type the interface requires. |
49| 13600001 | IPC error. |
50| 13600008 | No such object. Possible causes: Cannot find user key for the specified user. |
51| 13600009 | User ID out of range. Possible causes: input parameter userId < 100 or userId > 10736. |
52
53**Example**:
54
55  ```ts
56  import { keyManager } from "@kit.CoreFileKit";
57  import { BusinessError } from '@ohos.base';
58  let userId: number = 100;
59  try {
60    keyManager.deactivateUserKey(userId);
61    console.info("deactivateUserKey success");
62  } catch (err) {
63    let error: BusinessError = err as BusinessError;
64    console.error("deactivateUserKey failed with error:" + JSON.stringify(error));
65  }
66  ```
67