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