• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.keyManager (用户秘钥管理)(系统接口)
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
9该模块提供用户秘钥管理相关的常用功能:包括用户秘钥卸载等。
10
11> **说明:**
12>
13> - 本模块首批接口从API version 15开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14> - 当前页面仅包含本模块的系统接口。
15
16## 导入模块
17
18```ts
19import { keyManager } from "@kit.CoreFileKit";
20```
21
22## keyManager.deactivateUserKey
23
24deactivateUserKey(userId: number):void
25
26用户锁屏时,同步卸载指定用户对应秘钥。**(该接口目前仅开放给锁屏应用)**
27
28**需要权限**:ohos.permission.STORAGE_MANAGER_CRYPT
29
30**系统能力**:SystemCapability.FileManagement.StorageService.Encryption
31
32**系统接口**:该接口为系统接口。
33
34**参数:**
35
36  | 参数名     | 类型   | 必填 | 说明 |
37  | ---------- | ------ | ---- | ---- |
38  | userId | number | 是   | 用户id。锁屏应用感知设备当前登录的用户,指定为该用户。|
39
40**错误码:**
41
42以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
43
44| 错误码ID | 错误信息 |
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**示例:**
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  ```