1# @ohos.security.certManager (Certificate Management)
2
3The **certManager** module provides system-level certificate management capabilities to ensure secure use and management of certificates throughout their lifecycle (installation, storage, use, and destruction).
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { certificateManager } from '@kit.DeviceCertificateKit';
13```
14
15## CmKeyPurpose
16
17Enumerates the purposes of using the key.
18
19**System capability**: System SystemCapability.Security.CertificateManager
20
21| Name      | Value|  Description     |
22| ---------- | ------ | --------- |
23| CM_KEY_PURPOSE_SIGN | 4      | The key is used for signing.|
24| CM_KEY_PURPOSE_VERIFY | 8      | The key is used for signature verification.|
25
26## CmKeyDigest
27
28Enumerates the digest algorithms that can be used for signing and signature verification.
29
30**System capability**: System SystemCapability.Security.CertificateManager
31
32| Name      | Value|  Description     |
33| ---------- | ------ | --------- |
34| CM_DIGEST_NONE | 0      | No digest algorithm is required. If this option is used, the service needs to pass in the data with the digest generated for signing or signature verification.|
35| CM_DIGEST_MD5 | 1      | MD5.|
36| CM_DIGEST_SHA1 | 2      | SHA-1.|
37| CM_DIGEST_SHA224 | 3      | SHA-224.|
38| CM_DIGEST_SHA256 | 4      | SHA-256.|
39| CM_DIGEST_SHA384 | 5      | SHA-384.|
40| CM_DIGEST_SHA512 | 6      | SHA-512.|
41
42## CmKeyPadding
43
44Enumerates the padding modes that can be used for signing and signature verification.
45
46**System capability**: System SystemCapability.Security.CertificateManager
47
48| Name      | Value|  Description     |
49| ---------- | ------ | --------- |
50| CM_PADDING_NONE | 0      | No padding.|
51| CM_PADDING_PSS | 1      | PSS.|
52| CM_PADDING_PKCS1_V1_5 | 2      | PKCS1-V1_5.|
53
54## CMSignatureSpec
55
56Represents a set of parameters used for signing or signature verification, including the key usage purpose, padding mode, and digest algorithm.
57
58**System capability**: System SystemCapability.Security.CertificateManager
59
60| Name          | Type                             | Read-Only| Optional| Description                                                        |
61| -------------- | --------------------------------- | ---- | ------------------------------------------------------------ | ------------------------------------------------------------ |
62| purpose          | [CmKeyPurpose](#cmkeypurpose)                       | No | No | Purpose of using the key.|
63| padding        | [CmKeyPadding](#cmkeypadding)                       | No  | Yes | Padding mode.|
64| digest        | [CmKeyDigest](#cmkeydigest)                       | No  | Yes | Digest algorithm.|
65
66
67## CertInfo
68
69Represents detailed information about a certificate.
70
71**System capability**: System SystemCapability.Security.CertificateManager
72
73| Name          | Type                             | Read-Only| Optional| Description                                                        |
74| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
75| uri          | string         | No  | No | Unique identifier of the certificate.|
76| certAlias          | string   | No | No | Alias of the certificate.|
77| state          | boolean     | No | No | Certificate state. The value **true** indicates that the certificate is enabled, and **false** means the opposite.|
78| issuerName          | string         | No | No | Issuer of the certificate.|
79| subjectName          | string   | No | No | User of the certificate.|
80| serial          | string     | No | No | Serial number of the certificate.|
81| notBefore          | string         | No | No | Date from which the certificate takes effect.|
82| notAfter          | string   | No | No | Date when the certificate expires.|
83| fingerprintSha256     | string     | No | No | Fingerprint value of the certificate.|
84| cert          | Uint8Array         | No | No | Certificate data in binary format.|
85
86## CertAbstract
87
88Represents brief information about a certificate.
89
90**System capability**: System SystemCapability.Security.CertificateManager
91
92| Name          | Type                             | Read-Only| Optional| Description                                                        |
93| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
94| uri          | string         | No | No | Unique identifier of the certificate.|
95| certAlias          | string   | No | No | Alias of the certificate.|
96| state          | boolean     | No | No | Certificate state. The value **true** indicates that the certificate is enabled, and **false** means the opposite.|
97| subjectName          | string   | No | No | User of the certificate.|
98
99## Credential
100
101Represents detailed information about a credential.
102
103**System capability**: System SystemCapability.Security.CertificateManager
104
105| Name          | Type                             | Read-Only| Optional| Description                                                        |
106| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
107| type          | string         | No | No | Type of the credential.|
108| alias          | string   | No | No | Alias of the credential.|
109| keyUri          | string     | No | No | Unique identifier of the credential.|
110| certNum          | number         | No | No | Number of certificates contained in the credential.|
111| keyNum          | number   | No | No | Number of keys contained in the credential.|
112| credentialData          | Uint8Array   | No | No | Credential data in binary format.|
113
114## CredentialAbstract
115
116Represents brief information about a credential.
117
118**System capability**: System SystemCapability.Security.CertificateManager
119
120| Name          | Type                             | Read-Only| Optional| Description                                                        |
121| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
122| type          | string         | No| No | Type of the credential.|
123| alias          | string   | No | No | Alias of the credential.|
124| keyUri          | string     | No | No | Unique identifier of the credential.|
125
126## CMResult
127
128Represents the result returned.
129
130**System capability**: System SystemCapability.Security.CertificateManager
131
132| Name          | Type                             | Read-Only| Optional| Description                                                        |
133| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
134| certList          | Array<[CertAbstract](#certabstract)> | No | Yes  | Brief certificate information.|
135| certInfo          | [CertInfo](#certinfo) | No | Yes  | Detailed certificate information.|
136| credentialList          | Array<[CredentialAbstract](#credentialabstract)> | No | Yes  | Brief credential information.|
137| credential         | [Credential](#credential) | No | Yes  | Detailed credential information.|
138| appUidList        | Array\<string>     | No | Yes  | List of authorized applications.|
139| uri         | string    | No | Yes  | Unique identifier of the certificate or credential.|
140| outData         | Uint8Array    | No | Yes  | Signature generated.|
141
142## CMHandle
143
144Represents the handle to a signing or signature verification operation.
145
146**System capability**: System SystemCapability.Security.CertificateManager
147
148| Name          | Type                             | Read-Only| Optional| Description                                                        |
149| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
150| handle         | Uint8Array        | No | No  | Handle returned by **certManager.init()** for the subsequent signing or signature verification operation. |
151
152## CMErrorCode
153
154Enumerates the error codes used in the certificate management APIs.
155
156**System capability**: System SystemCapability.Security.CertificateManager
157
158| Name      | Value|  Description     |
159| ---------- | ------ | --------- |
160| CM_ERROR_NO_PERMISSION   | 201      | The application does not have the permission to call the API.|
161| CM_ERROR_INVALID_PARAMS   | 401      | Invalid input parameter is found.|
162| CM_ERROR_GENERIC  | 17500001      | An internal error occurs when the interface is called.|
163| CM_ERROR_NO_FOUND  | 17500002      | The certificate or credential does not exist.|
164| CM_ERROR_INCORRECT_FORMAT  | 17500003      | The certificate or credential is in invalid format.|
165| CM_ERROR_MAX_CERT_COUNT_REACHED<sup>12+</sup>  | 17500004      | The number of certificates or credentials has reached the limit.|
166| CM_ERROR_NO_AUTHORIZATION<sup>12+</sup>  | 17500005      | The application has not obtained user authorization.|
167
168## certificateManager.installPrivateCertificate
169
170installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string, callback: AsyncCallback\<CMResult>): void
171
172Installs a private credential. This API uses an asynchronous callback to return the result.
173
174**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
175
176**System capability**: System SystemCapability.Security.CertificateManager
177
178**Parameters**
179
180| Name  | Type                                             | Mandatory| Description                      |
181| -------- | ------------------------------------------------- | ---- | -------------------------- |
182| keystore | Uint8Array                   | Yes  | Keystore file containing the key pair and certificate.|
183| keystorePwd | string | Yes  | Password of the keystore file. The password cannot exceed 32 bytes.|
184| certAlias | string | Yes  | Credential alias. Currently, the alias can contain only digits, letters, and underscores (_) and should not exceed 32 bytes.|
185| callback | AsyncCallback\<[CMResult](#cmresult)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is **uri** in the [CMResult](#cmresult) object. Otherwise, **err** is an error object.|
186
187**Error codes**
188
189For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
190
191| ID| Error Message                                                    |
192| -------- | ------------------------------------------------------------ |
193| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
194| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
195| 17500001 | Internal error.     |
196| 17500003 | The keystore is in an invalid format or the keystore password is incorrect. |
197| 17500004<sup>12+</sup> | The number of certificates or credentials reaches the maximum allowed. |
198
199**Example**
200```ts
201import { certificateManager } from '@kit.DeviceCertificateKit';
202
203/* The credential data to be installed must be assigned by the service. The data in this example is not the real credential data. */
204let keystore: Uint8Array = new Uint8Array([
205  0x30, 0x82, 0x0b, 0xc1, 0x02, 0x01,
206]);
207let keystorePwd: string = "123456";
208try {
209  certificateManager.installPrivateCertificate(keystore, keystorePwd, "test", (err, cmResult) => {
210    if (err != null) {
211      console.error(`Failed to install private certificate. Code: ${err.code}, message: ${err.message}`);
212    } else {
213      let uri: string = (cmResult?.uri == undefined) ? '' : cmResult.uri;
214      console.info('Succeeded in installing private certificate.');
215    }
216  });
217} catch (error) {
218  console.error(`Failed to install private certificate. Code: ${error.code}, message: ${error.message}`);
219}
220```
221
222## certificateManager.installPrivateCertificate
223
224installPrivateCertificate(keystore: Uint8Array, keystorePwd: string, certAlias: string): Promise\<CMResult>
225
226Installs a private credential. This API uses a promise to return the result.
227
228**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
229
230**System capability**: System SystemCapability.Security.CertificateManager
231
232**Parameters**
233
234| Name  | Type                                             | Mandatory| Description                      |
235| -------- | ------------------------------------------------- | ---- | -------------------------- |
236| keystore | Uint8Array                   | Yes  | Keystore file containing the key pair and certificate.|
237| keystorePwd | string | Yes  | Password of the keystore file. The password cannot exceed 32 bytes.|
238| certAlias | string | Yes  | Credential alias. Currently, the alias can contain only digits, letters, and underscores (_) and should not exceed 32 bytes.|
239
240**Return value**
241
242| Type                           | Description                                                        |
243| ------------------------------- | ------------------------------------------------------------ |
244| Promise\<[CMResult](#cmresult)> | Promise used to return the operation result, that is, **uri** in the [CMResult](#cmresult) object.|
245
246**Error codes**
247
248For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
249
250| ID| Error Message                                                    |
251| -------- | ------------------------------------------------------------ |
252| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
253| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
254| 17500001 | Internal error.     |
255| 17500003 | The keystore is in an invalid format or the keystore password is incorrect. |
256| 17500004<sup>12+</sup> | The number of certificates or credentials reaches the maximum allowed. |
257
258**Example**
259
260```ts
261import { certificateManager } from '@kit.DeviceCertificateKit';
262import { BusinessError } from '@kit.BasicServicesKit';
263
264/* The credential data to be installed must be assigned by the service. The data in this example is not the real credential data. */
265let keystore: Uint8Array = new Uint8Array([
266  0x30, 0x82, 0x0b, 0xc1, 0x02, 0x01,
267]);
268let keystorePwd: string = "123456";
269try {
270  certificateManager.installPrivateCertificate(keystore, keystorePwd, 'test').then((cmResult) => {
271    let uri: string = (cmResult?.uri == undefined) ? '' : cmResult.uri;
272    console.info('Succeeded in installing private certificate.');
273  }).catch((err: BusinessError) => {
274    console.error(`Failed to install private certificate. Code: ${err.code}, message: ${err.message}`);
275  })
276} catch (error) {
277  console.error(`Failed to install private certificate. Code: ${error.code}, message: ${error.message}`);
278}
279```
280
281## certificateManager.getPrivateCertificate
282
283getPrivateCertificate(keyUri: string, callback: AsyncCallback\<CMResult>): void
284
285Obtains detailed information about a private credential. This API uses an asynchronous callback to return the result.
286
287**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
288
289**System capability**: System SystemCapability.Security.CertificateManager
290
291**Parameters**
292
293| Name  | Type                                             | Mandatory| Description                      |
294| -------- | ------------------------------------------------- | ---- | -------------------------- |
295| keyUri | string                   | Yes  | Unique identifier of the target credential.|
296| callback | AsyncCallback\<[CMResult](#cmresult)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is **credential** in the [CMResult](#cmresult) object. Otherwise, **err** is an error object.|
297
298**Error codes**
299
300For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
301
302| ID| Error Message     |
303| -------- | ------------- |
304| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
305| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
306| 17500001 | Internal error. |
307| 17500002 | The certificate does not exist. |
308
309**Example**
310```ts
311import { certificateManager } from '@kit.DeviceCertificateKit';
312
313let uri: string = 'test'; /* URI of the credential installed. The process for installing the credential is omitted here. */
314try {
315  certificateManager.getPrivateCertificate(uri, (err, cmResult) => {
316    if (err != null) {
317      console.error(`Failed to get private certificate. Code: ${err.code}, message: ${err.message}`);
318    } else {
319      if (cmResult?.credential == undefined) {
320        console.info('The result of getting private certificate is undefined.');
321      } else {
322        let list = cmResult.credential;
323        console.info('Succeeded in getting private certificate.');
324      }
325    }
326  });
327} catch (error) {
328  console.error(`Failed to get private certificate. Code: ${error.code}, message: ${error.message}`);
329}
330```
331
332## certificateManager.getPrivateCertificate
333
334getPrivateCertificate(keyUri: string): Promise\<CMResult>
335
336Obtains detailed information about a private credential. This API uses a promise to return the result.
337
338**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
339
340**System capability**: System SystemCapability.Security.CertificateManager
341
342**Parameters**
343
344| Name  | Type                                             | Mandatory| Description                      |
345| -------- | ------------------------------------------------- | ---- | -------------------------- |
346| keyUri | string                   | Yes  | Unique identifier of the target credential.|
347
348**Return value**
349
350| Type                           | Description                                                        |
351| ------------------------------- | ------------------------------------------------------------ |
352| Promise\<[CMResult](#cmresult)> | Promise used to return the private credential details obtained, that is, **credential** in the [CMResult](#cmresult) object.|
353
354**Error codes**
355
356For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
357
358| ID| Error Message     |
359| -------- | ------------- |
360| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
361| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
362| 17500001 | Internal error. |
363| 17500002 | The certificate does not exist. |
364
365**Example**
366```ts
367import { certificateManager } from '@kit.DeviceCertificateKit';
368import { BusinessError } from '@kit.BasicServicesKit';
369
370let uri: string = 'test'; /* URI of the credential installed. The process for installing the credential is omitted here. */
371try {
372  certificateManager.getPrivateCertificate(uri).then((cmResult) => {
373    if (cmResult?.credential == undefined) {
374      console.info('The result of getting private certificate is undefined.');
375    } else {
376      let list = cmResult.credential;
377      console.info('Succeeded in getting private certificate.');
378    }
379  }).catch((err: BusinessError) => {
380    console.error(`Failed to get private certificate. Code: ${err.code}, message: ${err.message}`);
381  })
382} catch (error) {
383  console.error(`Failed to get private certificate. Code: ${error.code}, message: ${error.message}`);
384}
385```
386
387## certificateManager.uninstallPrivateCertificate
388
389uninstallPrivateCertificate(keyUri: string, callback: AsyncCallback\<void>): void
390
391Uninstalls a private credential. This API uses an asynchronous callback to return the result.
392
393**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
394
395**System capability**: System SystemCapability.Security.CertificateManager
396
397**Parameters**
398
399| Name  | Type                                             | Mandatory| Description                      |
400| -------- | ------------------------------------------------- | ---- | -------------------------- |
401| keyUri | string                   | Yes  | Unique identifier of the credential to uninstall.|
402| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
403
404**Error codes**
405
406For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
407
408| ID| Error Message     |
409| -------- | ------------- |
410| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
411| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
412| 17500001 | Internal error. |
413| 17500002 | The certificate does not exist. |
414
415**Example**
416```ts
417import { certificateManager } from '@kit.DeviceCertificateKit';
418
419let uri: string = 'test'; /* URI of the credential installed. The process for installing the credential is omitted here. */
420try {
421  certificateManager.uninstallPrivateCertificate(uri, (err, result) => {
422    if (err != null) {
423      console.error(`Failed to uninstall private certificate. Code: ${err.code}, message: ${err.message}`);
424    } else {
425      console.info('Succeeded in uninstalling private certificate.');
426    }
427  });
428} catch (error) {
429  console.error(`Failed to uninstall private certificate. Code: ${error.code}, message: ${error.message}`);
430}
431```
432
433## certificateManager.uninstallPrivateCertificate
434
435uninstallPrivateCertificate(keyUri: string): Promise\<void>
436
437Uninstalls a private credential. This API uses a promise to return the result.
438
439**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
440
441**System capability**: System SystemCapability.Security.CertificateManager
442
443**Parameters**
444
445| Name  | Type                                             | Mandatory| Description                      |
446| -------- | ------------------------------------------------- | ---- | -------------------------- |
447| keyUri | string                   | Yes  | Unique identifier of the credential to uninstall.|
448
449**Return value**
450
451| Type                                       | Description                |
452| ------------------------------------------- | -------------------- |
453| Promise\<void> | Promise that returns no value.|
454
455**Error codes**
456
457For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
458
459| ID| Error Message     |
460| -------- | ------------- |
461| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
462| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
463| 17500001 | Internal error. |
464| 17500002 | The certificate does not exist. |
465
466**Example**
467```ts
468import { certificateManager } from '@kit.DeviceCertificateKit';
469import { BusinessError } from '@kit.BasicServicesKit';
470
471let uri: string = 'test'; /* URI of the credential installed. The process for installing the credential is omitted here. */
472try {
473  certificateManager.uninstallPrivateCertificate(uri).then((cmResult) => {
474    console.info('Succeeded in uninstalling private certificate.');
475  }).catch((err: BusinessError) => {
476    console.error(`Failed to uninstall private certificate. Code: ${err.code}, message: ${err.message}`);
477  })
478} catch (error) {
479  console.error(`Failed to uninstall private certificate. Code: ${error.code}, message: ${error.message}`);
480}
481```
482
483## certificateManager.init
484
485init(authUri: string, spec: CMSignatureSpec, callback: AsyncCallback\<CMHandle>): void
486
487Initializes the signing or signature verification operation using the specified credential. This API uses an asynchronous callback to return the result.
488
489**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
490
491**System capability**: System SystemCapability.Security.CertificateManager
492
493**Parameters**
494
495| Name  | Type                                             | Mandatory| Description                      |
496| -------- | ------------------------------------------------- | ---- | -------------------------- |
497| authUri | string                   | Yes  | Unique identifier of the credential to use.|
498| spec | [CMSignatureSpec](#cmsignaturespec) | Yes  | Parameters for the signing or signature verification operation.|
499| callback | AsyncCallback\<[CMHandle](#cmhandle)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the obtained **CMHandle**. Otherwise, **err** is an error object.|
500
501**Error codes**
502
503For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
504
505| ID| Error Message     |
506| -------- | ------------- |
507| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
508| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
509| 17500001 | Internal error. |
510| 17500002 | The certificate does not exist. |
511| 17500005<sup>12+</sup> | The application is not authorized by the user. |
512
513**Example**
514```ts
515import { certificateManager } from '@kit.DeviceCertificateKit';
516
517let uri: string = 'test'; /* URI of the credential installed. The process for installing the credential is omitted here. */
518const req: certificateManager.CMSignatureSpec = {
519  purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_SIGN,
520  padding: certificateManager.CmKeyPadding.CM_PADDING_PSS,
521  digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256
522}
523try {
524  certificateManager.init(uri, req, (err, cmHandle) => {
525    if (err != null) {
526      console.error(`Failed to init. Code: ${err.code}, message: ${err.message}`);
527    } else {
528      console.info('Succeeded in initiating.');
529    }
530  })
531} catch (error) {
532  console.error(`Failed to init. Code: ${error.code}, message: ${error.message}`);
533}
534```
535
536## certificateManager.init
537
538init(authUri: string, spec: CMSignatureSpec): Promise\<CMHandle>
539
540Initializes the signing or signature verification operation using the specified credential. This API uses a promise to return the result.
541
542**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
543
544**System capability**: System SystemCapability.Security.CertificateManager
545
546**Parameters**
547
548| Name  | Type                                             | Mandatory| Description                      |
549| -------- | ------------------------------------------------- | ---- | -------------------------- |
550| authUri | string                   | Yes  | Unique identifier of the credential to use.|
551| spec | [CMSignatureSpec](#cmsignaturespec) | Yes  | Parameters for the signing or signature verification operation.|
552
553**Return value**
554
555| Type                                       | Description                |
556| ------------------------------------------- | -------------------- |
557| Promise\<[CMHandle](#cmhandle)> | Promise used to return an operation handle.|
558
559**Error codes**
560
561For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
562
563| ID| Error Message     |
564| -------- | ------------- |
565| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
566| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
567| 17500001 | Internal error. |
568| 17500002 | The certificate does not exist. |
569| 17500005<sup>12+</sup> | The application is not authorized by the user. |
570
571**Example**
572```ts
573import { certificateManager } from '@kit.DeviceCertificateKit';
574import { BusinessError } from '@kit.BasicServicesKit';
575
576let uri: string = 'test'; /* URI of the credential installed. The process for installing the credential is omitted here. */
577const req: certificateManager.CMSignatureSpec = {
578  purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_VERIFY,
579  padding: certificateManager.CmKeyPadding.CM_PADDING_PSS,
580  digest: certificateManager.CmKeyDigest.CM_DIGEST_MD5
581}
582try {
583  certificateManager.init(uri, req).then((handle) => {
584    console.info('Succeeded in initiating.');
585  }).catch((err: BusinessError) => {
586    console.error(`Failed to init. Code: ${err.code}, message: ${err.message}`);
587  })
588} catch (error) {
589  console.error(`Failed to init. Code: ${error.code}, message: ${error.message}`);
590}
591```
592
593## certificateManager.update
594
595update(handle: Uint8Array, data: Uint8Array, callback: AsyncCallback\<void>): void
596
597Updates the data for the signing or signature verification operation. This API uses an asynchronous callback to return the result.
598
599**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
600
601**System capability**: System SystemCapability.Security.CertificateManager
602
603**Parameters**
604
605| Name  | Type                                             | Mandatory| Description                      |
606| -------- | ------------------------------------------------- | ---- | -------------------------- |
607| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
608| data | Uint8Array                   | Yes  | Data to be signed or verified.|
609| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
610
611**Error codes**
612
613For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
614
615| ID| Error Message                                                    |
616| -------- | ------------------------------------------------------------ |
617| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
618| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
619| 17500001 | Internal error.     |
620
621**Example**
622```ts
623import { certificateManager } from '@kit.DeviceCertificateKit';
624
625/* cmHandle is the value returned by init(). The value here is only an example. */
626let cmHandle: Uint8Array = new Uint8Array([
627  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
628]);
629let srcData: Uint8Array = new Uint8Array([
630  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
631]);
632try {
633  certificateManager.update(cmHandle, srcData, (err, result) => {
634    if (err != null) {
635      console.error(`Failed to update. Code: ${err.code}, message: ${err.message}`);
636    } else {
637      console.info('Succeeded in updating.');
638    }
639  });
640} catch (error) {
641  console.error(`Failed to update. Code: ${error.code}, message: ${error.message}`);
642}
643```
644
645## certificateManager.update
646
647update(handle: Uint8Array, data: Uint8Array): Promise\<void>
648
649Updates the data for the signing or signature verification operation. This API uses a promise to return the result.
650
651**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
652
653**System capability**: System SystemCapability.Security.CertificateManager
654
655**Parameters**
656
657| Name  | Type                                             | Mandatory| Description                      |
658| -------- | ------------------------------------------------- | ---- | -------------------------- |
659| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
660| data | Uint8Array                   | Yes  | Data to be signed or verified.|
661
662**Return value**
663
664| Type                                       | Description                |
665| ------------------------------------------- | -------------------- |
666| Promise\<void> | Promise that returns no value.|
667
668**Error codes**
669
670For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
671
672| ID| Error Message                                                    |
673| -------- | ------------------------------------------------------------ |
674| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
675| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
676| 17500001 | Internal error.     |
677
678**Example**
679```ts
680import { certificateManager } from '@kit.DeviceCertificateKit';
681import { BusinessError } from '@kit.BasicServicesKit';
682
683/* cmHandle is the value returned by init(). The value here is only an example. */
684let cmHandle: Uint8Array = new Uint8Array([
685  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
686]);
687let srcData: Uint8Array = new Uint8Array([
688  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
689]);
690try {
691  certificateManager.update(cmHandle, srcData).then((result) => {
692    console.info('Succeeded in updating.');
693  }).catch((err: BusinessError) => {
694    console.error(`Failed to update. Code: ${err.code}, message: ${err.message}`);
695  })
696} catch (error) {
697  console.error(`Failed to update. Code: ${error.code}, message: ${error.message}`);
698}
699```
700
701## certificateManager.finish
702
703finish(handle: Uint8Array, callback: AsyncCallback\<CMResult>): void
704
705Finishes the signing operation. This API uses an asynchronous callback to return the result.
706
707**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
708
709**System capability**: System SystemCapability.Security.CertificateManager
710
711**Parameters**
712
713| Name  | Type                                             | Mandatory| Description                      |
714| -------- | ------------------------------------------------- | ---- | -------------------------- |
715| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
716| callback | AsyncCallback\<[CMResult](#cmresult)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null** and **data** is the signature, that is, **outData** of the [CMResult](#cmresult) object. Otherwise, **err** is an error object.|
717
718**Error codes**
719
720For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
721
722| ID| Error Message                                                    |
723| -------- | ------------------------------------------------------------ |
724| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
725| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
726| 17500001 | Internal error.     |
727
728**Example**
729```ts
730import { certificateManager } from '@kit.DeviceCertificateKit';
731
732/* cmHandle is the value returned by init(). The value here is only an example. */
733let cmHandle: Uint8Array = new Uint8Array([
734  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
735]);
736try {
737  certificateManager.finish(cmHandle, (err, cmResult) => {
738    if (err != null) {
739      console.error(`Failed to finish. Code: ${err.code}, message: ${err.message}`);
740    } else {
741      if (cmResult?.outData != undefined) {
742        let signRes: Uint8Array = cmResult.outData;
743        console.info('Succeeded in finishing.');
744      } else {
745        console.info('The result of finishing is undefined.');
746      }
747    }
748  });
749} catch(error) {
750  console.error(`Failed to finish. Code: ${error.code}, message: ${error.message}`);
751}
752```
753
754## certificateManager.finish
755
756finish(handle: Uint8Array, signature: Uint8Array, callback: AsyncCallback\<CMResult>): void
757
758Finishes the signature verification operation. This API uses an asynchronous callback to return the result.
759
760**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
761
762**System capability**: System SystemCapability.Security.CertificateManager
763
764**Parameters**
765
766| Name  | Type                                             | Mandatory| Description                      |
767| -------- | ------------------------------------------------- | ---- | -------------------------- |
768| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
769| signature | Uint8Array                   | Yes  | Signature data to verify.|
770| callback | AsyncCallback\<[CMResult](#cmresult)> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
771
772**Error codes**
773
774For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
775
776| ID| Error Message                                                    |
777| -------- | ------------------------------------------------------------ |
778| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
779| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
780| 17500001 | Internal error.     |
781
782**Example**
783```ts
784import { certificateManager } from '@kit.DeviceCertificateKit';
785
786/* cmHandle is the value returned by init(). The value here is only an example. */
787let cmHandle: Uint8Array = new Uint8Array([
788  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
789]);
790let signRes: Uint8Array = new Uint8Array([
791  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
792]);
793try {
794  certificateManager.finish(cmHandle, signRes, (err, cmResult) => {
795    if (err != null) {
796      console.error(`Failed to finish. Code: ${err.code}, message: ${err.message}`);
797    } else {
798      console.info('Succeeded in finishing.');
799    }
800  });
801} catch(error) {
802  console.error(`Failed to finish. Code: ${error.code}, message: ${error.message}`);
803}
804```
805
806## certificateManager.finish
807
808finish(handle: Uint8Array, signature?: Uint8Array): Promise\<CMResult>
809
810Finishes the signing or signature verification operation. This API uses a promise to return the result.
811
812**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
813
814**System capability**: System SystemCapability.Security.CertificateManager
815
816**Parameters**
817
818| Name  | Type                                             | Mandatory| Description                      |
819| -------- | ------------------------------------------------- | ---- | -------------------------- |
820| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
821| signature | Uint8Array                   | No  | Data to sign or verify.|
822
823**Return value**
824
825| Type                           | Description                                                        |
826| ------------------------------- | ------------------------------------------------------------ |
827| Promise\<[CMResult](#cmresult)> | Promise used to return the result. For a signing operation, the promise returns the signature, that is, **outData** in the [CMResult](#cmresult) object, is returned. For a signature verification operation, the promise returns no value.|
828
829**Error codes**
830
831For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
832
833| ID| Error Message                                                    |
834| -------- | ------------------------------------------------------------ |
835| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
836| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
837| 17500001 | Internal error.     |
838
839**Example**
840```ts
841import { certificateManager } from '@kit.DeviceCertificateKit';
842import { BusinessError } from '@kit.BasicServicesKit';
843
844/* cmHandle is the value returned by init(). The value here is only an example. */
845let cmHandle: Uint8Array = new Uint8Array([
846  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
847]);
848try {
849  /* Finish the signing operation. */
850  certificateManager.finish(cmHandle).then((cmResult) => {
851    if (cmResult?.outData != undefined) {
852      let signRes1: Uint8Array = cmResult.outData;
853      console.info('Succeeded in finishing signature.');
854    } else {
855      console.info('The result of signature is undefined.');
856    }
857  }).catch((err: BusinessError) => {
858    console.error(`Failed to finish signature. Code: ${err.code}, message: ${err.message}`);
859  })
860
861  /* Signature generated. */
862  let signRes: Uint8Array = new Uint8Array([
863    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
864  ]);
865  /* Finish the signature verification operation. */
866  certificateManager.finish(cmHandle, signRes).then((cmResult) => {
867    console.info('Succeeded in finishing verification.');
868  }).catch((err: BusinessError) => {
869    console.error(`Failed to finish verification. Code: ${err.code}, message: ${err.message}`);
870  })
871} catch(error) {
872  console.error(`Failed to finish. Code: ${error.code}, message: ${error.message}`);
873}
874```
875
876## certificateManager.abort
877
878abort(handle: Uint8Array, callback: AsyncCallback\<void>): void
879
880Aborts the signing or signature verification operation. This API uses an asynchronous callback to return the result.
881
882**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
883
884**System capability**: System SystemCapability.Security.CertificateManager
885
886**Parameters**
887
888| Name  | Type                                             | Mandatory| Description                      |
889| -------- | ------------------------------------------------- | ---- | -------------------------- |
890| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
891| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **null**. Otherwise, **err** is an error object.|
892
893**Error codes**
894
895For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
896
897| ID| Error Message                                                    |
898| -------- | ------------------------------------------------------------ |
899| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
900| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
901| 17500001 | Internal error.     |
902
903**Example**
904```ts
905import { certificateManager } from '@kit.DeviceCertificateKit';
906
907/* cmHandle is the value returned by init(). The value here is only an example. */
908let cmHandle: Uint8Array = new Uint8Array([
909  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
910]);
911try {
912  certificateManager.abort(cmHandle, (err, cmResult) => {
913    if (err != null) {
914      console.error(`Failed to abort. Code: ${err.code}, message: ${err.message}`);
915    } else {
916      console.info('Succeeded in aborting.');
917    }
918  });
919} catch(error) {
920  console.error(`Failed to abort. Code: ${error.code}, message: ${error.message}`);
921}
922```
923
924## certificateManager.abort
925
926abort(handle: Uint8Array): Promise\<void>
927
928Aborts the signing or signature verification operation. This API uses a promise to return the result.
929
930**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
931
932**System capability**: System SystemCapability.Security.CertificateManager
933
934**Parameters**
935
936| Name  | Type                                             | Mandatory| Description                      |
937| -------- | ------------------------------------------------- | ---- | -------------------------- |
938| handle | Uint8Array                   | Yes  | Operation handle returned by **init()**.|
939
940**Return value**
941
942| Type                                       | Description                |
943| ------------------------------------------- | -------------------- |
944| Promise\<void> | Promise that returns no value.|
945
946**Error codes**
947
948For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
949
950| ID| Error Message                                                    |
951| -------- | ------------------------------------------------------------ |
952| 201      | Permission verification failed. The application does not have the permission required to call the API.     |
953| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
954| 17500001 | Internal error.     |
955
956**Example**
957```ts
958import { certificateManager } from '@kit.DeviceCertificateKit';
959import { BusinessError } from '@kit.BasicServicesKit';
960
961/* cmHandle is the value returned by init(). The value here is only an example. */
962let cmHandle: Uint8Array = new Uint8Array([
963  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
964]);
965try {
966  certificateManager.abort(cmHandle).then((result) => {
967    console.info('Succeeded in aborting.');
968  }).catch((err: BusinessError) => {
969    console.error(`Failed to abort. Code: ${err.code}, message: ${err.message}`);
970  })
971} catch (error) {
972  console.error(`Failed to abort. Code: ${error.code}, message: ${error.message}`);
973}
974```
975
976## certificateManager.getPublicCertificate<sup>12+</sup>
977
978getPublicCertificate(keyUri: string): Promise\<CMResult>
979
980Obtains detailed information about a public credential. This API uses a promise to return the result.
981
982**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
983
984**System capability**: System SystemCapability.Security.CertificateManager
985
986**Parameters**
987
988| Name  | Type                                             | Mandatory| Description                      |
989| -------- | ------------------------------------------------- | ---- | -------------------------- |
990| keyUri | string                   | Yes  | Unique identifier of the public credential.|
991
992**Return value**
993
994| Type                           | Description                                                        |
995| ------------------------------- | ------------------------------------------------------------ |
996| Promise\<[CMResult](#cmresult)> | Promise used to return the detailed information about the user's public credential obtained, that is, **credential** in the [CMResult](#cmresult) object.|
997
998**Error codes**
999
1000For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
1001
1002| ID| Error Message     |
1003| -------- | ------------- |
1004| 201 | Permission verification failed. The application does not have the permission required to call the API. |
1005| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1006| 17500001 | Internal error. |
1007| 17500002 | The certificate does not exist. |
1008| 17500005 | The application is not authorized by the user. |
1009
1010**Example**
1011```ts
1012import { certificateManager } from '@kit.DeviceCertificateKit';
1013import { BusinessError } from '@kit.BasicServicesKit';
1014
1015let uri: string = 'test'; /* Unique identifier of the public credential. The process for installing the public credential is omitted here. */
1016try {
1017  certificateManager.getPublicCertificate(uri).then((cmResult) => {
1018    if (cmResult?.credential == undefined) {
1019      console.info('The result of getting public certificate is undefined.');
1020    } else {
1021      let cred = cmResult.credential;
1022      console.info('Succeeded in getting Public certificate.');
1023    }
1024  }).catch((err: BusinessError) => {
1025    console.error(`Failed to get Public certificate. Code: ${err.code}, message: ${err.message}`);
1026  })
1027} catch (error) {
1028  console.error(`Failed to get Public certificate. Code: ${error.code}, message: ${error.message}`);
1029}
1030```
1031
1032## certificateManager.isAuthorizedApp<sup>12+</sup>
1033
1034isAuthorizedApp(keyUri: string): Promise\<boolean>
1035
1036Checks whether this application is authorized by the specified user credential. This API uses a promise to return the result.
1037
1038**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
1039
1040**System capability**: System SystemCapability.Security.CertificateManager
1041
1042**Parameters**
1043
1044| Name  | Type                                             | Mandatory| Description                      |
1045| -------- | ------------------------------------------------- | ---- | -------------------------- |
1046| keyUri | string                   | Yes  | Unique identifier of the credential.|
1047
1048**Return value**
1049
1050| Type             | Description                                                        |
1051| ----------------- | ------------------------------------------------------------ |
1052| Promise\<boolean> | Promise used to return a Boolean value, which indicates whether the application is authorized by the specified user credential.|
1053
1054**Error codes**
1055
1056For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
1057
1058| ID| Error Message     |
1059| -------- | ------------- |
1060| 201 | Permission verification failed. The application does not have the permission required to call the API. |
1061| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1062| 17500001 | Internal error. |
1063
1064**Example**
1065```ts
1066import { certificateManager } from '@kit.DeviceCertificateKit';
1067import { BusinessError } from '@kit.BasicServicesKit';
1068
1069let uri: string = 'test'; /* Unique identifier of the credential. The process for authorizing the credential to the application is omitted here. */
1070try {
1071  certificateManager.isAuthorizedApp(uri).then((res) => {
1072    if (res) {
1073      console.info('The application is authorized by the user.');
1074    } else {
1075      console.info('The application is not authorized by the user.');
1076    }
1077  }).catch((err: BusinessError) => {
1078    console.error(`Failed to get Public certificate. Code: ${err.code}, message: ${err.message}`);
1079  })
1080} catch (error) {
1081  console.error(`Failed to get Public certificate. Code: ${error.code}, message: ${error.message}`);
1082}
1083```
1084
1085## certificateManager.getAllUserTrustedCertificates<sup>12+</sup>
1086
1087getAllUserTrustedCertificates(): Promise\<CMResult>
1088
1089Obtains all the user root CA certificates. The API uses a promise to return the result.
1090
1091**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
1092
1093**System capability**: System SystemCapability.Security.CertificateManager
1094
1095**Return value**
1096
1097| Type                           | Description                                                        |
1098| ------------------------------- | ------------------------------------------------------------ |
1099| Promise\<[CMResult](#cmresult)> | Promise used to return the user's root CA certificates obtained, that is, **certList** in the [CMResult](#cmresult) object.|
1100
1101**Error codes**
1102
1103For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
1104
1105| ID| Error Message     |
1106| -------- | ------------- |
1107| 201 | Permission verification failed. The application does not have the permission required to call the API. |
1108| 17500001 | Internal error. |
1109
1110**Example**
1111```ts
1112import { certificateManager } from '@kit.DeviceCertificateKit';
1113import { BusinessError } from '@kit.BasicServicesKit';
1114
1115try {
1116  certificateManager.getAllUserTrustedCertificates().then((cmResult) => {
1117    if (cmResult?.certList == undefined) {
1118      console.info('The result of getting all user trusted certificates is undefined.');
1119    } else {
1120      let list = cmResult.certList;
1121      console.info('Succeeded in getting all user trusted certificates.');
1122    }
1123  }).catch((err: BusinessError) => {
1124    console.error(`Failed to get all user trusted certificates. Code: ${err.code}, message: ${err.message}`);
1125  })
1126} catch (error) {
1127  console.error(`Failed to get all user trusted certificates. Code: ${error.code}, message: ${error.message}`);
1128}
1129```
1130
1131## certificateManager.getUserTrustedCertificate<sup>12+</sup>
1132
1133getUserTrustedCertificate(certUri: string): Promise\<CMResult>
1134
1135Obtains the detailed information about a user root CA certificate. This API uses a promise to return the result.
1136
1137**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
1138
1139**System capability**: System SystemCapability.Security.CertificateManager
1140
1141**Parameters**
1142
1143| Name  | Type                                             | Mandatory| Description                      |
1144| -------- | ------------------------------------------------- | ---- | -------------------------- |
1145| certUri | string                   | Yes  | Unique identifier of the user root CA certificate.|
1146
1147**Return value**
1148
1149| Type                           | Description                                                        |
1150| ------------------------------- | ------------------------------------------------------------ |
1151| Promise\<[CMResult](#cmresult)> | Promise used to return the detailed CA certificate information obtained, that is, **certInfo** in the [CMResult](#cmresult) object.|
1152
1153**Error codes**
1154
1155For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
1156
1157| ID| Error Message     |
1158| -------- | ------------- |
1159| 201 | Permission verification failed. The application does not have the permission required to call the API. |
1160| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1161| 17500001 | Internal error. |
1162| 17500002 | The certificate does not exist. |
1163
1164**Example**
1165```ts
1166import { certificateManager } from '@kit.DeviceCertificateKit';
1167import { BusinessError } from '@kit.BasicServicesKit';
1168
1169let certUri: string = 'testUserCert'; /* Unique identifier of the user root CA certificate. The process of installing the user root CA certificate is omitted here. */
1170try {
1171  certificateManager.getUserTrustedCertificate(certUri).then((cmResult) => {
1172    if (cmResult?.certInfo == undefined) {
1173      console.info('The result of getting user trusted certificate is undefined.');
1174    } else {
1175      let cert = cmResult.certInfo;
1176      console.info('Succeeded in getting user trusted certificate.');
1177    }
1178  }).catch((err: BusinessError) => {
1179    console.error(`Failed to get user trusted certificate. Code: ${err.code}, message: ${err.message}`);
1180  })
1181} catch (error) {
1182  console.error(`Failed to get user trusted certificate. Code: ${error.code}, message: ${error.message}`);
1183}
1184```
1185## certificateManager.getPrivateCertificates<sup>13+</sup>
1186
1187getPrivateCertificates(): Promise\<CMResult>
1188
1189Obtains the credentials for installing the application. This API uses a promise to return the result asynchronously.
1190
1191**Required permissions**: ohos.permission.ACCESS_CERT_MANAGER
1192
1193**System capability**: System SystemCapability.Security.CertificateManager
1194
1195**Return value**
1196
1197| Type                           | Description                                                        |
1198| ------------------------------- | ------------------------------------------------------------ |
1199| Promise\<[CMResult](#cmresult)> | Promise used to return the credentials obtained, which is **credentialList** in [CMResult](#cmresult).|
1200
1201**Error codes**
1202
1203For details about the following error codes, see [Certificate Management Error Codes](errorcode-certManager.md).
1204
1205| ID| Error Message     |
1206| -------- | ------------- |
1207| 201 | Permission verification failed. The application does not have the permission required to call the API. |
1208| 17500001 | Internal error. |
1209
1210**Example**
1211```ts
1212import { certificateManager } from '@kit.DeviceCertificateKit';
1213import { BusinessError } from '@kit.BasicServicesKit';
1214
1215try {
1216  certificateManager.getPrivateCertificates().then((cmResult) => {
1217    if (cmResult?.credentialList == undefined) {
1218      console.info('The result of getting all private certificates installed by the application is undefined.');
1219    } else {
1220      let list = cmResult.credentialList;
1221      console.info('Succeeded in getting all private certificates installed by the application.');
1222    }
1223  }).catch((err: BusinessError) => {
1224    console.error(`Failed to get all private certificates installed by the application. Code: ${err.code}, message: ${err.message}`);
1225  })
1226} catch (error) {
1227  console.error(`Failed to get all private certificates installed by the application. Code: ${error.code}, message: ${error.message}`);
1228}
1229```
1230