1# @ohos.security.cert (Certificate) 2 3The certificate algorithm library framework provides certificate-related APIs. The **certFramework** module depends on the basic algorithm capabilities of the Crypto framework. For details, see [Crypto Framework](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md). 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { cert } from '@kit.DeviceCertificateKit'; 13import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 14``` 15 16## CertResult 17 18 Enumerates the error codes. 19 20 **Atomic service API**: This API can be used in atomic services since API version 12. 21 22 **System capability**: SystemCapability.Security.Cert 23 24| Name | Value | Description | 25| --------------------------------------| -------- | -----------------------------| 26| INVALID_PARAMS | 401 | Invalid parameters. | 27| NOT_SUPPORT | 801 | This operation is not supported. | 28| ERR_OUT_OF_MEMORY | 19020001 | Memory error. | 29| ERR_RUNTIME_ERROR | 19020002 | Runtime error. | 30| ERR_CRYPTO_OPERATION | 19030001 | Crypto operation error. | 31| ERR_CERT_SIGNATURE_FAILURE | 19030002 | The certificate signature verification failed. | 32| ERR_CERT_NOT_YET_VALID | 19030003 | The certificate has not taken effect. | 33| ERR_CERT_HAS_EXPIRED | 19030004 | The certificate has expired. | 34| ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY | 19030005 | Failed to obtain the certificate issuer. | 35| ERR_KEYUSAGE_NO_CERTSIGN | 19030006 | The key cannot be used for signing a certificate. | 36| ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE | 19030007 | The key cannot be used for digital signature. | 37 38## DataBlob 39Defines a binary data array. 40 41 **Atomic service API**: This API can be used in atomic services since API version 12. 42 43 **System capability**: SystemCapability.Security.Cert 44| Name | Type | Readable | Writable | Description | 45| -------------- | -------------- | ---- | ---- | ----------------| 46| data | Uint8Array | Yes | Yes | Data. | 47 48## DataArray 49 50Defines a list of data arrays. 51 52 **Atomic service API**: This API can be used in atomic services since API version 12. 53 54 **System capability**: SystemCapability.Security.Cert 55| Name | Type | Readable | Writable | Description | 56| -------------- | -------------- | ---- | ---- | ----------------| 57| data | Uint8Array | Yes | Yes | Data list. | 58 59## EncodingFormat 60 61 Enumerates the certificate encoding formats. 62 63**Atomic service API**: This API can be used in atomic services since API version 12. 64 65 **System capability**: SystemCapability.Security.Cert 66 67| Name | Value | Description | 68| ---------- | ------ | --------- | 69| FORMAT_DER | 0 | Distinguished Encoding Rules (DER) format. | 70| FORMAT_PEM | 1 | Privacy-Enhanced Mail (PEM) format. | 71| FORMAT_PKCS7<sup>11+</sup> | 2 | PKCS #7 format.| 72 73## CertItemType<sup>10+</sup> 74 75 Enumerates the certificate fields that can be obtained. 76 77**Atomic service API**: This API can be used in atomic services since API version 12. 78 79 **System capability**: SystemCapability.Security.Cert 80 81| Name | Value | Description | 82| -------------------------------- | ---- | ------------------------------ | 83| CERT_ITEM_TYPE_TBS | 0 | Information to be signed. | 84| CERT_ITEM_TYPE_PUBLIC_KEY | 1 | Public key of the certificate. | 85| CERT_ITEM_TYPE_ISSUER_UNIQUE_ID | 2 | Unique ID of the certificate issuer. | 86| CERT_ITEM_TYPE_SUBJECT_UNIQUE_ID | 3 | Unique ID of the certificate subject. | 87| CERT_ITEM_TYPE_EXTENSIONS | 4 | Certificate extensions, each of which is identified by a unique object identifier (OID). | 88 89## ExtensionOidType<sup>10+</sup> 90 91 Enumerates the OID types of the certificate extensions that can be obtained. 92 93 **Atomic service API**: This API can be used in atomic services since API version 12. 94 95 **System capability**: SystemCapability.Security.Cert 96 97| Name | Value | Description | 98| ----------------------------- | ---- | --------------------------------------------- | 99| EXTENSION_OID_TYPE_ALL | 0 | All object identifiers. | 100| EXTENSION_OID_TYPE_CRITICAL | 1 | Object identifier whose **critical** is **true**. | 101| EXTENSION_OID_TYPE_UNCRITICAL | 2 | Object identifier whose **critical** is **false**. | 102 103## ExtensionEntryType<sup>10+</sup> 104 105 Enumerates the object types in certificate extensions that can be obtained. 106 107 **Atomic service API**: This API can be used in atomic services since API version 12. 108 109 **System capability**: SystemCapability.Security.Cert 110 111| Name | Value | Description | 112| ----------------------------------- | ---- | ---------------------------- | 113| EXTENSION_ENTRY_TYPE_ENTRY | 0 | Entire object. | 114| EXTENSION_ENTRY_TYPE_ENTRY_CRITICAL | 1 | Critical attribute of the object. | 115| EXTENSION_ENTRY_TYPE_ENTRY_VALUE | 2 | Data of the object. | 116 117## EncodingType<sup>12+</sup> 118 119 Enumerates the encoding formats of the subject name in an X.509 certificate. 120 121**Atomic service API**: This API can be used in atomic services since API version 12. 122 123 **System capability**: SystemCapability.Security.Cert 124 125| Name | Value | Description | 126| ---------- | ------ | --------- | 127| ENCODING_UTF8 | 0 | UTF-8. | 128 129## EncodingBlob 130 131Defines a certificate binary array in encoding format. 132 133### Properties 134 135**Atomic service API**: This API can be used in atomic services since API version 12. 136 137**System capability**: SystemCapability.Security.Cert 138 139| Name | Type | Readable | Writable | Description | 140| -------------- | --------------------------------- | ---- | ---- | ------------------------------ | 141| data | Uint8Array | Yes | Yes | Certificate data. | 142| encodingFormat | [EncodingFormat](#encodingformat) | Yes | Yes | Certificate encoding format. | 143 144 145## CertChainData 146 147Defines the certificate chain data, which is passed in as input parameters during certificate chain verification. 148 149### Properties 150 151**Atomic service API**: This API can be used in atomic services since API version 12. 152 153**System capability**: SystemCapability.Security.Cert 154 155| Name | Type | Readable | Writable | Description | 156| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ | 157| data | Uint8Array | Yes | Yes | Certificate data, in the *length* (2 bytes) + *data* format. For example, **08ABCDEFGH07ABCDEFG**. The first two bytes indicate the length of the first certificate is eight bytes, and the following eight bytes indicate the certificate data. Then, the next two bytes indicate the length of another certificate is seven bytes, and the seven bytes followed indicate the certificate data. | 158| count | number | Yes | Yes | Number of certificates contained in the input data. | 159| encodingFormat | [EncodingFormat](#encodingformat) | Yes | Yes | Certificate encoding format. | 160 161## GeneralNameType<sup>12+</sup> 162 163Enumerates the types of the common name (CN), which uniquely identifies the subject of the certificate. 164 165**Atomic service API**: This API can be used in atomic services since API version 12. 166 167**System capability**: SystemCapability.Security.Cert 168 169| Name | Value | Description | 170| -------------- | --------------------------------- | ------------------ | 171| GENERAL_NAME_TYPE_OTHER_NAME | 0 | Indicates others. | 172| GENERAL_NAME_TYPE_RFC822_NAME | 1 | Indicates an email address. | 173| GENERAL_NAME_TYPE_DNS_NAME | 2 | Indicates a DNS name. | 174| GENERAL_NAME_TYPE_X400_ADDRESS | 3 | Indicates an X.400 address. | 175| GENERAL_NAME_TYPE_DIRECTORY_NAME | 4 | Indicates a directory name. | 176| GENERAL_NAME_TYPE_EDI_PARTY_NAME | 5 | Indicates an Electronic Data Interchange (EDI) entity. | 177| GENERAL_NAME_TYPE_UNIFORM_RESOURCE_ID | 6 | Indicates a uniform resource identifier. | 178| GENERAL_NAME_TYPE_IP_ADDRESS | 7 | Indicates an IP address. | 179| GENERAL_NAME_TYPE_REGISTERED_ID | 8 | Indicates a registered object identifier. | 180 181## GeneralName<sup>12+</sup> 182 183Represents the CN information of a certificate. 184 185**Atomic service API**: This API can be used in atomic services since API version 12. 186 187**System capability**: SystemCapability.Security.Cert 188 189| Name | Type | Mandatory | Description | 190| -------------- | --------------------------------- | ---- | ------------------ | 191| type | [GeneralNameType](#generalname12) | Yes | Type of the certificate subject. | 192| name | Uint8Array | No | DER format of the certificate subject. | 193 194## X509CertMatchParameters<sup>11+</sup> 195 196Defines the parameters used to match a certificate. If no parameter is specified, all certificates are matched. 197 198**Atomic service API**: This API can be used in atomic services since API version 12. 199 200**System capability**: SystemCapability.Security.Cert 201 202| Name | Type | Mandatory | Description | 203| -------------- | --------------------------------- | ---- | ------------------ | 204| x509Cert | [X509Cert](#x509cert) | No | Certificate object. | 205| validDate | string | No | Certificate validity period. | 206| issuer | Uint8Array | No | Certificate issuer, in DER format. | 207| keyUsage | Array\<boolean> | No | Whether to match the key usage. | 208| serialNumber | bigint | No | Serial number of the certificate. | 209| subject | Uint8Array | No | Certificate subject, in DER format. | 210| publicKey | [DataBlob](#datablob) | No | Public key of the certificate, in DER format. | 211| publicKeyAlgID | string | No | Algorithm of the certificate public key. | 212| subjectAlternativeNames<sup>12+</sup> | Array\<[GeneralName](#generalname12)> | No | Subject Alternative Names (SANs) of the certificate. | 213| matchAllSubjectAltNames<sup>12+</sup> | boolean | No | Whether to match all SANs of the certificate. | 214| authorityKeyIdentifier<sup>12+</sup> | Uint8Array | No | Key of the certificate authority (CA). | 215| minPathLenConstraint<sup>12+</sup> | number | No | Minimum length of the certification path (chain of trust) that can be built from the certificate to a trusted root CA. | 216| extendedKeyUsage<sup>12+</sup> | Array\<string> | No | Usage of the certificate. | 217| nameConstraints<sup>12+</sup> | Uint8Array | No | Constraints on the subject names that can be included in certificates. | 218| certPolicy<sup>12+</sup> | Array\<string> | No | Certificate policy. | 219| privateKeyValid<sup>12+</sup> | string | No | Validity period of the certificate private key. | 220| subjectKeyIdentifier<sup>12+</sup> | Uint8Array | No | Identifier of the public key of the certificate's subject. | 221 222## X509CRLMatchParameters<sup>11+</sup> 223 224Represents the parameters used to match a certificate revocation list (CRL). If no parameter is specified, all CRLs are matched. 225 226**Atomic service API**: This API can be used in atomic services since API version 12. 227 228**System capability**: SystemCapability.Security.Cert 229 230| Name | Type | Mandatory | Description | 231| -------------- | --------------------------------- | ---- | ------------------ | 232| issuer | Array\<Uint8Array> | No | Issuers of the certificates. At least one issuer must be matched. | 233| x509Cert | [X509Cert](#x509cert) | No | Certificate object used to determine whether the certificate is in the CRL. | 234| updateDateTime<sup>12+</sup> | string | No | Certificate update time. | 235| maxCRL<sup>12+</sup> | bigint | No | Maximum number of CRLs. | 236| minCRL<sup>12+</sup> | bigint | No | Minimum number of CRLs. | 237 238## CertChainBuildParameters<sup>12+</sup> 239 240Represents the parameters for building a certificate chain. 241 242**Atomic service API**: This API can be used in atomic services since API version 12. 243 244**System capability**: SystemCapability.Security.Cert 245 246| Name | Type | Mandatory | Description | 247| -------------- | --------------------------------- | ---- | ------------------ | 248| certMatchParameters | [X509CertMatchParameters](#x509certmatchparameters11) | Yes | Filter criteria. | 249| maxLength | number | No | Maximum length of the CA certificate in the certificate chain. | 250| validationParameters | [CertChainValidationParameters](#certchainvalidationparameters11) | Yes | Parameters for certificate chain validation. | 251 252## CertChainBuildResult<sup>12+</sup> 253 254Represents the certificate chain build result. 255 256**Atomic service API**: This API can be used in atomic services since API version 12. 257 258**System capability**: SystemCapability.Security.Cert 259 260| Name | Type | Mandatory | Description | 261| -------------- | --------------------------------- | ---- | ------------------ | 262| certChain | [X509CertChain](#x509certchain11) | Yes | Certificate chain object created. | 263| validationResult | [CertChainValidationResult](#certchainvalidationresult11) | Yes | Result of the certificate chain validation. | 264 265## X509TrustAnchor<sup>11+</sup> 266 267Represents an X.509 trust anchor, which is used to verify the certificate chain. The certificate or public key in the trust anchor is used as the trusted root to verify the certificate chain. 268 269**Atomic service API**: This API can be used in atomic services since API version 12. 270 271**System capability**: SystemCapability.Security.Cert 272 273| Name | Type | Readable | Writable | Description | 274| --------- | --------------------- | ---- | ---- | --------------------------- | 275| CACert | [X509Cert](#x509cert) | Yes | Yes | Trusted CA certificate. | 276| CAPubKey | Uint8Array | Yes | Yes | Public key of the trusted CA certificate, in DER format. | 277| CASubject | Uint8Array | Yes | Yes | Subject of the trusted CA certificate, in DER format. | 278| nameConstraints<sup>12+</sup> | Uint8Array | Yes | Yes | Name constraints, in DER format. | 279 280## RevocationCheckOptions<sup>12+</sup> 281 282 Enumerates the options for checking the certificate revocation status. 283 284 **Atomic service API**: This API can be used in atomic services since API version 12. 285 286 **System capability**: SystemCapability.Security.Cert 287 288| Name | Value | Description | 289| --------------------------------------| -------- | -----------------------------| 290| REVOCATION_CHECK_OPTION_PREFER_OCSP | 0 | Use OCSP over CRL (default). | 291| REVOCATION_CHECK_OPTION_ACCESS_NETWORK | 1 | Obtain the CRL/OCSP response over the network. By default, it is disabled. | 292| REVOCATION_CHECK_OPTION_FALLBACK_NO_PREFER | 2 | This parameter is valid when the **ACCESS_NETWORK** option is enabled. It allows the alternative solution to be used to obtain the certificate revocation status if the preferred solution cannot be used due to network problems. | 293| REVOCATION_CHECK_OPTION_FALLBACK_LOCAL | 3 | This parameter is valid when the **ACCESS_NETWORK** option is enabled. It allows the locally configured CRL/OCSP response to be used to check the certificate revocation status if the online CRL/OCSP response cannot be used due to network problems. | 294 295## ValidationPolicyType<sup>12+</sup> 296 297 Enumerates the types of the online certificate chain validation policy. 298 299 **Atomic service API**: This API can be used in atomic services since API version 12. 300 301 **System capability**: SystemCapability.Security.Cert 302 303| Name | Value | Description | 304| --------------------------------------| -------- | -----------------------------| 305| VALIDATION_POLICY_TYPE_X509 | 0 | Do not verify **sslHostname** or **dNSName** in the certificate. It is the default value. | 306| VALIDATION_POLICY_TYPE_SSL | 1 | Verify **sslHostname** or **dNSName** in the certificate. | 307 308## KeyUsageType<sup>12+</sup> 309 310 Enumerates the purposes, for which the key in the certificate is used. 311 **Atomic service API**: This API can be used in atomic services since API version 12. 312 313 **System capability**: SystemCapability.Security.Cert 314 315| Name | Value | Description | 316| --------------------------------------| -------- | -----------------------------| 317| KEYUSAGE_DIGITAL_SIGNATURE | 0 | The certificate holder can use the private key contained in the certificate to generate a digital signature. | 318| KEYUSAGE_NON_REPUDIATION | 1 | The certificate holder can use the key to verify a digital signature as part of a nonrepudiation service. | 319| KEYUSAGE_KEY_ENCIPHERMENT | 2 | The certificate holder can use the public key contained in the certificate for key encryption. | 320| KEYUSAGE_DATA_ENCIPHERMENT | 3 | The certificate holder can use the public key contained in the certificate for data encryption. | 321| KEYUSAGE_KEY_AGREEMENT | 4 | The certificate holder can use the private key contained in the certificate to perform key agreement operations. | 322| KEYUSAGE_KEY_CERT_SIGN | 5 | The certificate holder can use the private key contained in the certificate to sign other certificates. | 323| KEYUSAGE_CRL_SIGN | 6 | The certificate holder can use the private key contained in the certificate to sign CRLs. | 324| KEYUSAGE_ENCIPHER_ONLY | 7 | The certificate holder can use the key to perform encryption operations only. | 325| KEYUSAGE_DECIPHER_ONLY | 8 | The certificate holder can use the key to perform decryption operations only. | 326 327## RevocationCheckParameter<sup>12+</sup> 328 329Represents the parameters for checking the certificate revocation status for a certificate chain. 330 331**Atomic service API**: This API can be used in atomic services since API version 12. 332 333**System capability**: SystemCapability.Security.Cert 334 335| Name | Type | Mandatory | Description | 336| ------------ | ------------------------------------------------- | ---- | -------------------------------------- | 337| ocspRequestExtension | Array\<Uint8Array> | No | OCSP request extensions.| 338| ocspResponderURI | string | No | URL of the alternative server used to send OCSP requests. HTTP and HTTPS are supported. The specific configuration is determined via the negotiation with the server. | 339| ocspResponderCert | [X509Cert](#x509cert) | No | Signing certificate used for verifying the signature of the OCSP response. | 340| ocspResponses | Uint8Array | No | Alternative OCSP responses. | 341| crlDownloadURI | string | No | Address used to download the CRLs. | 342| options | Array\<[RevocationCheckOptions](#revocationcheckoptions12)> | No | A set of rules for obtaining the certificate revocation status. | 343| ocspDigest | string | No | Hash algorithm used to create a certificate ID during OCSP communication. The options **MD5**, **SHA1**, **SHA224**, **SHA256**, **SHA384**, and **SHA512** are supported. The default value is **SHA256**.| 344 345## CertChainValidationParameters<sup>11+</sup> 346 347Represents the parameters for certificate chain validation. 348 349**Atomic service API**: This API can be used in atomic services since API version 12. 350 351**System capability**: SystemCapability.Security.Cert 352 353| Name | Type | Mandatory | Description | 354| ------------ | ------------------------------------------------- | ---- | -------------------------------------- | 355| date | string | No | Validity period of the certificate to validate. | 356| trustAnchors | Array\<[X509TrustAnchor](#x509trustanchor11)> | Yes | List of trusted anchors. | 357| certCRLs | Array\<[CertCRLCollection](#certcrlcollection11)> | No | Check whether the certificate is in a CRL. | 358| revocationCheckParam<sup>12+</sup> | [RevocationCheckParameter](#revocationcheckparameter12) | No | Parameters for checking the certificate revocation status online. | 359| policy<sup>12+</sup> | [ValidationPolicyType](#validationpolicytype12) | No | Type of the policy for certificate validation. | 360| sslHostname<sup>12+</sup> | string | No | Host name in the certificate to be verified. This parameter must be used with **policy** together. | 361| keyUsage<sup>12+</sup> | Array\<[KeyUsageType](#keyusagetype12)> | No | Usage of the key in the certificate to be validated. | 362 363## CertChainValidationResult<sup>11+</sup> 364 365Represents the return value of certificate chain validation. 366 367**Atomic service API**: This API can be used in atomic services since API version 12. 368 369**System capability**: SystemCapability.Security.Cert 370 371| Name | Type | Readable | Writable | Description | 372| ----------- | ------------------------------------- | ---- | ---- | -------------- | 373| trustAnchor | [X509TrustAnchor](#x509trustanchor11) | Yes | No | Trust anchor. | 374| entityCert | [X509Cert](#x509cert) | Yes | No | Entity certificate. | 375 376## cert.createX509Cert 377 378createX509Cert(inStream : EncodingBlob, callback : AsyncCallback\<X509Cert>) : void 379 380Creates an X.509 certificate instance. This API uses an asynchronous callback to return the result. 381 382**Atomic service API**: This API can be used in atomic services since API version 12. 383 384**System capability**: SystemCapability.Security.Cert 385 386**Parameters** 387 388| Name | Type | Mandatory | Description | 389| -------- | ------------------------------------- | ---- | -------------------------- | 390| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data. | 391| callback | AsyncCallback\<[X509Cert](#x509cert)> | Yes | Callback used to return the **X509Cert** instance created. | 392 393**Error codes** 394 395For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 396 397| ID | Error Message | 398| -------- | ------------- | 399| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 400| 801 | this operation is not supported. | 401| 19020001 | memory error. | 402 403**Example** 404 405```ts 406import { cert } from '@kit.DeviceCertificateKit'; 407 408// Convert the string into a Uint8Array. 409function stringToUint8Array(str: string): Uint8Array { 410 let arr: Array<number> = []; 411 for (let i = 0, j = str.length; i < j; i++) { 412 arr.push(str.charCodeAt(i)); 413 } 414 return new Uint8Array(arr); 415} 416 417// Certificate binary data, which varies with the service. 418let certData = '-----BEGIN CERTIFICATE-----\n' + 419 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 420 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 421 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 422 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 423 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 424 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 425 'Qw==\n' + 426 '-----END CERTIFICATE-----\n'; 427 428let encodingBlob: cert.EncodingBlob = { 429 data: stringToUint8Array(certData), 430 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 431 encodingFormat: cert.EncodingFormat.FORMAT_PEM 432}; 433 434cert.createX509Cert(encodingBlob, (error, x509Cert) => { 435 if (error) { 436 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 437 } else { 438 console.log('createX509Cert success'); 439 } 440}); 441``` 442 443## cert.createX509Cert 444 445createX509Cert(inStream : EncodingBlob) : Promise\<X509Cert> 446 447Creates an X.509 certificate instance. This API uses a promise to return the result. 448 449**Atomic service API**: This API can be used in atomic services since API version 12. 450 451**System capability**: SystemCapability.Security.Cert 452 453**Parameters** 454 455| Name | Type | Mandatory | Description | 456| -------- | ----------------------------- | ---- | ------------------ | 457| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data. | 458 459**Return value** 460 461| Type | Description | 462| ------- | ---------------- | 463| Promise\<[X509Cert](#x509cert)> | Promise used to return the **X509Cert** instance created. | 464 465**Error codes** 466 467For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 468 469| ID | Error Message | 470| -------- | ------------- | 471| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 472| 801 | this operation is not supported. | 473| 19020001 | memory error. | 474 475**Example** 476 477```ts 478import { cert } from '@kit.DeviceCertificateKit'; 479import { BusinessError } from '@kit.BasicServicesKit'; 480 481// Convert the string into a Uint8Array. 482function stringToUint8Array(str: string): Uint8Array { 483 let arr: Array<number> = []; 484 for (let i = 0, j = str.length; i < j; i++) { 485 arr.push(str.charCodeAt(i)); 486 } 487 return new Uint8Array(arr); 488} 489 490// Certificate binary data, which varies with the service. 491let certData = '-----BEGIN CERTIFICATE-----\n' + 492 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 493 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 494 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 495 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 496 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 497 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 498 'Qw==\n' + 499 '-----END CERTIFICATE-----\n'; 500 501let encodingBlob: cert.EncodingBlob = { 502 data: stringToUint8Array(certData), 503 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 504 encodingFormat: cert.EncodingFormat.FORMAT_PEM 505}; 506 507cert.createX509Cert(encodingBlob).then(x509Cert => { 508 console.log('createX509Cert success'); 509}).catch((error: BusinessError) => { 510 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 511}); 512``` 513 514## X509Cert 515 516Provides APIs for X.509 certificate operations. 517 518### verify 519 520verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void 521 522Verifies the signature of an X.509 certificate. This API uses an asynchronous callback to return the result. 523 524**Atomic service API**: This API can be used in atomic services since API version 12. 525 526**System capability**: SystemCapability.Security.Cert 527 528**Parameters** 529 530| Name | Type | Mandatory | Description | 531| -------- | --------------------- | ---- | ------------------------------------------------------------ | 532| key | [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Yes | Public key used for signature verification. | 533| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails. | 534 535**Error codes** 536 537For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 538 539| ID | Error Message | 540| -------- | ------------------ | 541| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 542| 19030001 | crypto operation error. | 543 544**Example** 545 546```ts 547import { cert } from '@kit.DeviceCertificateKit'; 548import { BusinessError } from '@kit.BasicServicesKit'; 549 550// Convert the string into a Uint8Array. 551function stringToUint8Array(str: string): Uint8Array { 552 let arr: Array<number> = []; 553 for (let i = 0, j = str.length; i < j; i++) { 554 arr.push(str.charCodeAt(i)); 555 } 556 return new Uint8Array(arr); 557} 558 559// Certificate binary data, which varies with the service. 560let certData = '-----BEGIN CERTIFICATE-----\n' + 561 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 562 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 563 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 564 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 565 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 566 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 567 'Qw==\n' + 568 '-----END CERTIFICATE-----\n'; 569 570let encodingBlob: cert.EncodingBlob = { 571 data: stringToUint8Array(certData), 572 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 573 encodingFormat: cert.EncodingFormat.FORMAT_PEM 574}; 575 576cert.createX509Cert(encodingBlob, (error, x509Cert) => { 577 if (error) { 578 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 579 } else { 580 console.log('createX509Cert success'); 581 582 // Obtain PubKey by using getPublicKey() of the upper-level X509Cert object (or the current certificate object is a self-signed certificate). 583 try { 584 let pubKey = x509Cert.getPublicKey(); 585 586 // Verify the certificate signature. 587 x509Cert.verify(pubKey, (err, data) => { 588 if (err) { 589 console.error('verify failed, errCode: ' + err.code + ', errMsg: ' + err.message); 590 } else { 591 console.log('verify success'); 592 } 593 }); 594 } catch (error) { 595 let e: BusinessError = error as BusinessError; 596 console.error('getPublicKey failed, errCode: ' + e.code + ', errMsg: ' + e.message); 597 } 598 } 599}); 600``` 601 602### verify 603 604verify(key : cryptoFramework.PubKey) : Promise\<void> 605 606Verifies the signature of an X.509 certificate. This API uses a promise to return the result. 607 608**Atomic service API**: This API can be used in atomic services since API version 12. 609 610**System capability**: SystemCapability.Security.Cert 611 612**Parameters** 613 614| Name | Type | Mandatory | Description | 615| ------ | ------ | ---- | ------------------ | 616| key | [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Yes | Public key used for signature verification. | 617 618**Return value** 619 620| Type | Description | 621| -------------- | ----------- | 622| Promise\<void> | Promise used to return the result. | 623 624**Error codes** 625 626For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 627 628| ID | Error Message | 629| -------- | ------------------ | 630| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 631| 19030001 | crypto operation error. | 632 633**Example** 634 635```ts 636import { cert } from '@kit.DeviceCertificateKit'; 637import { BusinessError } from '@kit.BasicServicesKit'; 638 639// Convert the string into a Uint8Array. 640function stringToUint8Array(str: string): Uint8Array { 641 let arr: Array<number> = []; 642 for (let i = 0, j = str.length; i < j; i++) { 643 arr.push(str.charCodeAt(i)); 644 } 645 return new Uint8Array(arr); 646} 647 648// Certificate binary data, which varies with the service. 649let certData = '-----BEGIN CERTIFICATE-----\n' + 650 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 651 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 652 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 653 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 654 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 655 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 656 'Qw==\n' + 657 '-----END CERTIFICATE-----\n'; 658 659let encodingBlob: cert.EncodingBlob = { 660 data: stringToUint8Array(certData), 661 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 662 encodingFormat: cert.EncodingFormat.FORMAT_PEM 663}; 664 665cert.createX509Cert(encodingBlob).then(x509Cert => { 666 console.log('createX509Cert success'); 667 668 try { 669 // Obtain PubKey by using getPublicKey() of the upper-level X509Cert object (or the current certificate object is a self-signed certificate). 670 let pubKey = x509Cert.getPublicKey(); 671 x509Cert.verify(pubKey).then(result => { 672 console.log('verify success'); 673 }).catch((error: BusinessError) => { 674 console.error('verify failed, errCode: ' + error.code + ', errMsg: ' + error.message); 675 }); 676 } catch (err) { 677 console.error('get public key failed'); 678 } 679}).catch((error: BusinessError) => { 680 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 681}); 682``` 683 684### getEncoded 685 686getEncoded(callback : AsyncCallback\<EncodingBlob>) : void 687 688Obtains the serialized X.509 certificate data. This API uses an asynchronous callback to return the result. 689 690**Atomic service API**: This API can be used in atomic services since API version 12. 691 692**System capability**: SystemCapability.Security.Cert 693 694**Parameters** 695 696| Name | Type | Mandatory | Description | 697| -------- | --------------------------------------------- | ---- | -------------------------------- | 698| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback used to return the serialized X.509 certificate data obtained. | 699 700**Error codes** 701 702For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 703 704| ID | Error Message | 705| -------- | ------------------------------------------------- | 706| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 707| 19020001 | memory error. | 708| 19020002 | runtime error. | 709| 19030001 | crypto operation error.| 710 711**Example** 712 713```ts 714import { cert } from '@kit.DeviceCertificateKit'; 715 716// Convert the string into a Uint8Array. 717function stringToUint8Array(str: string): Uint8Array { 718 let arr: Array<number> = []; 719 for (let i = 0, j = str.length; i < j; i++) { 720 arr.push(str.charCodeAt(i)); 721 } 722 return new Uint8Array(arr); 723} 724 725// Certificate binary data, which varies with the service. 726let certData = '-----BEGIN CERTIFICATE-----\n' + 727 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 728 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 729 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 730 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 731 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 732 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 733 'Qw==\n' + 734 '-----END CERTIFICATE-----\n'; 735 736let encodingBlob: cert.EncodingBlob = { 737 data: stringToUint8Array(certData), 738 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 739 encodingFormat: cert.EncodingFormat.FORMAT_PEM 740}; 741 742cert.createX509Cert(encodingBlob, (error, x509Cert) => { 743 if (error) { 744 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 745 } else { 746 console.log('createX509Cert success'); 747 x509Cert.getEncoded((error, data) => { 748 if (error) { 749 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 750 } else { 751 console.log('getEncoded success'); 752 } 753 }); 754 } 755}); 756``` 757 758### getEncoded 759 760getEncoded() : Promise\<EncodingBlob> 761 762Obtains the serialized X.509 certificate data. This API uses a promise to return the result. 763 764**Atomic service API**: This API can be used in atomic services since API version 12. 765 766**System capability**: SystemCapability.Security.Cert 767 768**Return value** 769 770| Type | Description | 771| --------------------------------------- | ---------------------- | 772| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized X.509 certificate data obtained. | 773 774**Error codes** 775 776For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 777 778| ID | Error Message | 779| -------- | ------------------------------------------------- | 780| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 781| 19020001 | memory error. | 782| 19020002 | runtime error. | 783| 19030001 | crypto operation error.| 784 785**Example** 786 787```ts 788import { cert } from '@kit.DeviceCertificateKit'; 789import { BusinessError } from '@kit.BasicServicesKit'; 790 791// Convert the string into a Uint8Array. 792function stringToUint8Array(str: string): Uint8Array { 793 let arr: Array<number> = []; 794 for (let i = 0, j = str.length; i < j; i++) { 795 arr.push(str.charCodeAt(i)); 796 } 797 return new Uint8Array(arr); 798} 799 800// Certificate binary data, which varies with the service. 801let certData = '-----BEGIN CERTIFICATE-----\n' + 802 'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' + 803 'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' + 804 'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' + 805 'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' + 806 'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' + 807 '0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' + 808 'BetUokslUfjT6+s/X4ByaxycAA==\n' + 809 '-----END CERTIFICATE-----\n'; 810 811// Certificate binary data, which varies with the service. 812let encodingBlob: cert.EncodingBlob = { 813 data: stringToUint8Array(certData), 814 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 815 encodingFormat: cert.EncodingFormat.FORMAT_PEM 816}; 817cert.createX509Cert(encodingBlob).then(x509Cert => { 818 console.log('createX509Cert success'); 819 x509Cert.getEncoded().then(result => { 820 console.log('getEncoded success'); 821 }).catch((error: BusinessError) => { 822 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 823 }); 824}).catch((error: BusinessError) => { 825 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 826}); 827``` 828 829### getPublicKey 830 831getPublicKey() : cryptoFramework.PubKey 832 833Obtains the public key of this X.509 certificate. 834 835**Atomic service API**: This API can be used in atomic services since API version 12. 836 837**System capability**: SystemCapability.Security.Cert 838 839**Return value** 840 841| Type | Description | 842| ------ | ---------------- | 843| [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Public key of the X509 certificate obtained. This object is used only for **verify()** of **X509Cert**. | 844 845**Error codes** 846 847For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 848 849| ID | Error Message | 850| -------- | ------------------------------------------------- | 851| 19020001 | memory error. | 852| 19030001 | crypto operation error.| 853 854**Example** 855 856```ts 857import { cert } from '@kit.DeviceCertificateKit'; 858import { BusinessError } from '@kit.BasicServicesKit'; 859 860// Convert the string into a Uint8Array. 861function stringToUint8Array(str: string): Uint8Array { 862 let arr: Array<number> = []; 863 for (let i = 0, j = str.length; i < j; i++) { 864 arr.push(str.charCodeAt(i)); 865 } 866 return new Uint8Array(arr); 867} 868 869// Certificate binary data, which varies with the service. 870let certData = '-----BEGIN CERTIFICATE-----\n' + 871 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 872 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 873 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 874 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 875 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 876 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 877 'Qw==\n' + 878 '-----END CERTIFICATE-----\n'; 879 880let encodingBlob: cert.EncodingBlob = { 881 data: stringToUint8Array(certData), 882 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 883 encodingFormat: cert.EncodingFormat.FORMAT_PEM 884}; 885 886cert.createX509Cert(encodingBlob, (error, x509Cert) => { 887 if (error) { 888 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 889 } else { 890 console.log('createX509Cert success'); 891 try { 892 let pubKey = x509Cert.getPublicKey(); 893 } catch (error) { 894 let e: BusinessError = error as BusinessError; 895 console.error('getPublicKey failed, errCode: ' + e.code + ', errMsg: ' + e.message); 896 } 897 } 898}); 899``` 900 901### checkValidityWithDate 902 903checkValidityWithDate(date: string) : void 904 905Checks the validity period of this X.509 certificate. 906 907**Atomic service API**: This API can be used in atomic services since API version 12. 908 909**System capability**: SystemCapability.Security.Cert 910 911**Parameters** 912 913| Name | Type | Mandatory | Description | 914| -------- | -------------- | ---- | ---------- | 915| date | string | Yes | Date in the ASN.1 format. | 916 917**Error codes** 918 919For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 920 921| ID | Error Message | 922| -------- | ------------------------------------------------- | 923| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 924| 19020001 | memory error. | 925| 19030001 | crypto operation error.| 926| 19030003 | the certificate has not taken effect. | 927| 19030004 | the certificate has expired.| 928 929**Example** 930 931```ts 932import { cert } from '@kit.DeviceCertificateKit'; 933import { BusinessError } from '@kit.BasicServicesKit'; 934 935// Convert the string into a Uint8Array. 936function stringToUint8Array(str: string): Uint8Array { 937 let arr: Array<number> = []; 938 for (let i = 0, j = str.length; i < j; i++) { 939 arr.push(str.charCodeAt(i)); 940 } 941 return new Uint8Array(arr); 942} 943 944// Certificate binary data, which varies with the service. 945let certData = '-----BEGIN CERTIFICATE-----\n' + 946 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 947 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 948 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 949 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 950 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 951 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 952 'Qw==\n' + 953 '-----END CERTIFICATE-----\n'; 954 955let encodingBlob: cert.EncodingBlob = { 956 data: stringToUint8Array(certData), 957 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 958 encodingFormat: cert.EncodingFormat.FORMAT_PEM 959}; 960 961cert.createX509Cert(encodingBlob, (error, x509Cert) => { 962 if (error) { 963 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 964 } else { 965 console.log('createX509Cert success'); 966 967 let date = '231001000001Z'; 968 // Verify the certificate validity period. 969 try { 970 x509Cert.checkValidityWithDate(date); 971 } catch (error) { 972 let e: BusinessError = error as BusinessError; 973 console.error('checkValidityWithDate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 974 } 975 } 976}); 977``` 978 979### getVersion 980 981getVersion() : number 982 983Obtains the X.509 certificate version. 984 985**Atomic service API**: This API can be used in atomic services since API version 12. 986 987**System capability**: SystemCapability.Security.Cert 988 989**Return value** 990 991| Type | Description | 992| ------ | ---------------- | 993| number | X.509 certificate version obtained. | 994 995**Example** 996 997```ts 998import { cert } from '@kit.DeviceCertificateKit'; 999 1000// Convert the string into a Uint8Array. 1001function stringToUint8Array(str: string): Uint8Array { 1002 let arr: Array<number> = []; 1003 for (let i = 0, j = str.length; i < j; i++) { 1004 arr.push(str.charCodeAt(i)); 1005 } 1006 return new Uint8Array(arr); 1007} 1008 1009// Certificate binary data, which varies with the service. 1010let certData = '-----BEGIN CERTIFICATE-----\n' + 1011 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1012 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1013 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1014 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1015 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1016 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1017 'Qw==\n' + 1018 '-----END CERTIFICATE-----\n'; 1019 1020let encodingBlob: cert.EncodingBlob = { 1021 data: stringToUint8Array(certData), 1022 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1023 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1024}; 1025cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1026 if (error) { 1027 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1028 } else { 1029 console.log('createX509Cert success'); 1030 let version = x509Cert.getVersion(); 1031 } 1032}); 1033``` 1034 1035### getSerialNumber<sup>(deprecated)</sup> 1036 1037getSerialNumber() : number 1038 1039Obtains the X.509 certificate serial number. 1040 1041> **NOTE** 1042> 1043> This API is supported since API version 9 and deprecated since API version 10. Use [getCertSerialNumber](#getcertserialnumber10) instead. 1044 1045**System capability**: SystemCapability.Security.Cert 1046 1047**Return value** 1048 1049| Type | Description | 1050| ------ | ------------------ | 1051| number | X.509 certificate serial number obtained. | 1052 1053**Example** 1054 1055```ts 1056import { cert } from '@kit.DeviceCertificateKit'; 1057 1058// Convert the string into a Uint8Array. 1059function stringToUint8Array(str: string): Uint8Array { 1060 let arr: Array<number> = []; 1061 for (let i = 0, j = str.length; i < j; i++) { 1062 arr.push(str.charCodeAt(i)); 1063 } 1064 return new Uint8Array(arr); 1065} 1066 1067// Certificate binary data, which varies with the service. 1068let certData = '-----BEGIN CERTIFICATE-----\n' + 1069 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1070 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1071 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1072 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1073 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1074 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1075 'Qw==\n' + 1076 '-----END CERTIFICATE-----\n'; 1077 1078let encodingBlob: cert.EncodingBlob = { 1079 data: stringToUint8Array(certData), 1080 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1081 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1082}; 1083 1084cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1085 if (error) { 1086 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1087 } else { 1088 console.log('createX509Cert success'); 1089 let serialNumber = x509Cert.getSerialNumber(); 1090 } 1091}); 1092``` 1093 1094### getCertSerialNumber<sup>10+</sup> 1095 1096getCertSerialNumber() : bigint 1097 1098Obtains the X.509 certificate serial number. 1099 1100**Atomic service API**: This API can be used in atomic services since API version 12. 1101 1102**System capability**: SystemCapability.Security.Cert 1103 1104**Return value** 1105 1106| Type | Description | 1107| ------ | ------------------ | 1108| bigint | X.509 certificate serial number obtained. | 1109 1110**Error codes** 1111 1112For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1113 1114| ID | Error Message | 1115| -------- | ------------------------------------------------- | 1116| 19020002 | runtime error. | 1117 1118**Example** 1119 1120```ts 1121import { cert } from '@kit.DeviceCertificateKit'; 1122import { BusinessError } from '@kit.BasicServicesKit'; 1123 1124// Convert the string into a Uint8Array. 1125function stringToUint8Array(str: string): Uint8Array { 1126 let arr: Array<number> = []; 1127 for (let i = 0, j = str.length; i < j; i++) { 1128 arr.push(str.charCodeAt(i)); 1129 } 1130 return new Uint8Array(arr); 1131} 1132 1133// Certificate binary data, which varies with the service. 1134let certData = '-----BEGIN CERTIFICATE-----\n' + 1135 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1136 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1137 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1138 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1139 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1140 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1141 'Qw==\n' + 1142 '-----END CERTIFICATE-----\n'; 1143 1144let encodingBlob: cert.EncodingBlob = { 1145 data: stringToUint8Array(certData), 1146 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1147 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1148}; 1149 1150cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1151 if (error) { 1152 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1153 } else { 1154 console.log('createX509Cert success'); 1155 try { 1156 let serialNumber = x509Cert.getCertSerialNumber(); 1157 } catch (err) { 1158 let e: BusinessError = err as BusinessError; 1159 console.error('getCertSerialNumber failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1160 } 1161 } 1162}); 1163``` 1164 1165### getIssuerName 1166 1167getIssuerName() : DataBlob 1168 1169Obtains the X.509 certificate issuer. 1170 1171**Atomic service API**: This API can be used in atomic services since API version 12. 1172 1173**System capability**: SystemCapability.Security.Cert 1174 1175**Return value** 1176 1177| Type | Description | 1178| --------------------- | ---------------------- | 1179| [DataBlob](#datablob) | X.509 certificate issuer obtained. | 1180 1181**Error codes** 1182 1183For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1184 1185| ID | Error Message | 1186| -------- | ------------------------------------------------- | 1187| 19020001 | memory error. | 1188| 19020002 | runtime error. | 1189| 19030001 | crypto operation error.| 1190 1191**Example** 1192 1193```ts 1194import { cert } from '@kit.DeviceCertificateKit'; 1195import { BusinessError } from '@kit.BasicServicesKit'; 1196 1197// Convert the string into a Uint8Array. 1198function stringToUint8Array(str: string): Uint8Array { 1199 let arr: Array<number> = []; 1200 for (let i = 0, j = str.length; i < j; i++) { 1201 arr.push(str.charCodeAt(i)); 1202 } 1203 return new Uint8Array(arr); 1204} 1205 1206// Certificate binary data, which varies with the service. 1207let certData = '-----BEGIN CERTIFICATE-----\n' + 1208 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1209 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1210 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1211 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1212 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1213 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1214 'Qw==\n' + 1215 '-----END CERTIFICATE-----\n'; 1216 1217let encodingBlob: cert.EncodingBlob = { 1218 data: stringToUint8Array(certData), 1219 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1220 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1221}; 1222 1223cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1224 if (error) { 1225 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1226 } else { 1227 console.log('createX509Cert success'); 1228 try { 1229 let issuerName = x509Cert.getIssuerName(); 1230 } catch (err) { 1231 let e: BusinessError = err as BusinessError; 1232 console.error('getIssuerName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1233 } 1234 } 1235}); 1236``` 1237 1238### getSubjectName 1239 1240getSubjectName(encodingType?: EncodingType) : DataBlob 1241 1242Obtains the subject of this X.509 certificate. 1243 1244**Atomic service API**: This API can be used in atomic services since API version 12. 1245 1246**System capability**: SystemCapability.Security.Cert 1247 1248**Parameters** 1249 1250| Name | Type | Mandatory | Description | 1251| -------- | ------------------------------------- | ---- | ------------------------------ | 1252| encodingType | [EncodingType](#encodingtype12) | No | Encoding type. If this parameter is set, the subject name in UTF-8 format is to be obtained. If this parameter is not set, the subject name in ASCII encoding format is obtained by default.<br>This parameter is available since API version 12. | 1253 1254**Return value** 1255 1256| Type | Description | 1257| --------------------- | -------------------- | 1258| [DataBlob](#datablob) | Subject name obtained. | 1259 1260**Error codes** 1261 1262For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1263 1264| ID | Error Message | 1265| -------- | ------------------------------------------------- | 1266| 401 | invalid parameters. Possible causes: <br>1. Incorrect parameter types;<br>2. Parameter verification failed. | 1267| 19020001 | memory error. | 1268| 19020002 | runtime error. | 1269| 19030001 | crypto operation error.| 1270 1271**Example** 1272 1273```ts 1274import { cert } from '@kit.DeviceCertificateKit'; 1275import { BusinessError } from '@kit.BasicServicesKit'; 1276 1277// Convert the string into a Uint8Array. 1278function stringToUint8Array(str: string): Uint8Array { 1279 let arr: Array<number> = []; 1280 for (let i = 0, j = str.length; i < j; i++) { 1281 arr.push(str.charCodeAt(i)); 1282 } 1283 return new Uint8Array(arr); 1284} 1285 1286// Certificate binary data, which varies with the service. 1287let certData = '-----BEGIN CERTIFICATE-----\n' + 1288 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1289 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1290 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1291 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1292 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1293 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1294 'Qw==\n' + 1295 '-----END CERTIFICATE-----\n'; 1296 1297let encodingBlob: cert.EncodingBlob = { 1298 data: stringToUint8Array(certData), 1299 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1300 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1301}; 1302 1303cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1304 if (error) { 1305 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1306 } else { 1307 console.log('createX509Cert success'); 1308 try { 1309 let subjectName = x509Cert.getSubjectName(); 1310 } catch (err) { 1311 let e: BusinessError = err as BusinessError; 1312 console.error('getSubjectName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1313 } 1314 try { 1315 let subjectNameutf8 = x509Cert.getSubjectName(cert.EncodingType.ENCODING_UTF8); 1316 } catch (err) { 1317 let e: BusinessError = err as BusinessError; 1318 console.error('getSubjectNameUtf8 failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1319 } 1320 } 1321}); 1322``` 1323 1324### getNotBeforeTime 1325 1326getNotBeforeTime() : string 1327 1328Obtains the start time of this X.509 certificate. 1329 1330**Atomic service API**: This API can be used in atomic services since API version 12. 1331 1332**System capability**: SystemCapability.Security.Cert 1333 1334**Return value** 1335 1336| Type | Description | 1337| ------ | ------------------------------------------------------------ | 1338| string | Certificate start time obtained, in ASN.1 format. | 1339 1340**Error codes** 1341 1342For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1343 1344| ID | Error Message | 1345| -------- | ------------------------------------------------- | 1346| 19020001 | memory error. | 1347| 19020002 | runtime error. | 1348| 19030001 | crypto operation error.| 1349 1350**Example** 1351 1352```ts 1353import { cert } from '@kit.DeviceCertificateKit'; 1354import { BusinessError } from '@kit.BasicServicesKit'; 1355 1356// Convert the string into a Uint8Array. 1357function stringToUint8Array(str: string): Uint8Array { 1358 let arr: Array<number> = []; 1359 for (let i = 0, j = str.length; i < j; i++) { 1360 arr.push(str.charCodeAt(i)); 1361 } 1362 return new Uint8Array(arr); 1363} 1364 1365// Certificate binary data, which varies with the service. 1366let certData = '-----BEGIN CERTIFICATE-----\n' + 1367 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1368 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1369 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1370 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1371 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1372 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1373 'Qw==\n' + 1374 '-----END CERTIFICATE-----\n'; 1375 1376let encodingBlob: cert.EncodingBlob = { 1377 data: stringToUint8Array(certData), 1378 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1379 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1380}; 1381 1382cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1383 if (error) { 1384 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1385 } else { 1386 console.log('createX509Cert success'); 1387 try { 1388 let notBefore = x509Cert.getNotBeforeTime(); 1389 } catch (err) { 1390 let e: BusinessError = err as BusinessError; 1391 console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1392 } 1393 } 1394}); 1395``` 1396 1397### getNotAfterTime 1398 1399getNotAfterTime() : string 1400 1401Obtains the expiration time of this X.509 certificate. 1402 1403**Atomic service API**: This API can be used in atomic services since API version 12. 1404 1405**System capability**: SystemCapability.Security.Cert 1406 1407**Return value** 1408 1409| Type | Description | 1410| ------ | ------------------------------------------------------------ | 1411| string | Certificate expiration time obtained, in ASN.1 format. | 1412 1413**Error codes** 1414 1415For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1416 1417| ID | Error Message | 1418| -------- | ------------------------------------------------- | 1419| 19020001 | memory error. | 1420| 19020002 | runtime error. | 1421| 19030001 | crypto operation error.| 1422 1423**Example** 1424 1425```ts 1426import { cert } from '@kit.DeviceCertificateKit'; 1427 1428import { BusinessError } from '@kit.BasicServicesKit'; 1429 1430// Convert the string into a Uint8Array. 1431function stringToUint8Array(str: string): Uint8Array { 1432 let arr: Array<number> = []; 1433 for (let i = 0, j = str.length; i < j; i++) { 1434 arr.push(str.charCodeAt(i)); 1435 } 1436 return new Uint8Array(arr); 1437} 1438 1439// Certificate binary data, which varies with the service. 1440let certData = '-----BEGIN CERTIFICATE-----\n' + 1441 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1442 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1443 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1444 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1445 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1446 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1447 'Qw==\n' + 1448 '-----END CERTIFICATE-----\n'; 1449 1450let encodingBlob: cert.EncodingBlob = { 1451 data: stringToUint8Array(certData), 1452 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1453 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1454}; 1455 1456cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1457 if (error) { 1458 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1459 } else { 1460 console.log('createX509Cert success'); 1461 try { 1462 let notAfter = x509Cert.getNotAfterTime(); 1463 } catch (err) { 1464 let e: BusinessError = err as BusinessError; 1465 console.error('getNotAfterTime failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1466 } 1467 } 1468}); 1469``` 1470 1471### getSignature 1472 1473getSignature() : DataBlob 1474 1475Obtains the signature data of this X.509 certificate. 1476 1477**Atomic service API**: This API can be used in atomic services since API version 12. 1478 1479**System capability**: SystemCapability.Security.Cert 1480 1481**Return value** 1482 1483| Type | Description | 1484| --------------------- | -------------------- | 1485| [DataBlob](#datablob) | Signature data obtained. | 1486 1487**Error codes** 1488 1489For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1490 1491| ID | Error Message | 1492| -------- | ------------------------------------------------- | 1493| 19020001 | memory error. | 1494| 19020002 | runtime error. | 1495| 19030001 | crypto operation error.| 1496 1497**Example** 1498 1499```ts 1500import { cert } from '@kit.DeviceCertificateKit'; 1501 1502import { BusinessError } from '@kit.BasicServicesKit'; 1503 1504// Convert the string into a Uint8Array. 1505function stringToUint8Array(str: string): Uint8Array { 1506 let arr: Array<number> = []; 1507 for (let i = 0, j = str.length; i < j; i++) { 1508 arr.push(str.charCodeAt(i)); 1509 } 1510 return new Uint8Array(arr); 1511} 1512 1513// Certificate binary data, which varies with the service. 1514let certData = '-----BEGIN CERTIFICATE-----\n' + 1515 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1516 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1517 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1518 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1519 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1520 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1521 'Qw==\n' + 1522 '-----END CERTIFICATE-----\n'; 1523 1524let encodingBlob: cert.EncodingBlob = { 1525 data: stringToUint8Array(certData), 1526 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1527 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1528}; 1529 1530cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1531 if (error) { 1532 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1533 } else { 1534 console.log('createX509Cert success'); 1535 try { 1536 let signature = x509Cert.getSignature(); 1537 } catch (err) { 1538 let e: BusinessError = err as BusinessError; 1539 console.error('getSignature failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1540 } 1541 } 1542}); 1543``` 1544 1545### getSignatureAlgName 1546 1547getSignatureAlgName() : string 1548 1549Obtains the signing algorithm of this X.509 certificate. 1550 1551**Atomic service API**: This API can be used in atomic services since API version 12. 1552 1553**System capability**: SystemCapability.Security.Cert 1554 1555**Return value** 1556 1557| Type | Description | 1558| ------ | ------------------------ | 1559| string | X.509 certificate signing algorithm obtained. | 1560 1561**Error codes** 1562 1563For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1564 1565| ID | Error Message | 1566| -------- | ------------------------------------------------- | 1567| 19020001 | memory error. | 1568| 19020002 | runtime error. | 1569| 19030001 | crypto operation error.| 1570 1571**Example** 1572 1573```ts 1574import { cert } from '@kit.DeviceCertificateKit'; 1575 1576import { BusinessError } from '@kit.BasicServicesKit'; 1577 1578// Convert the string into a Uint8Array. 1579function stringToUint8Array(str: string): Uint8Array { 1580 let arr: Array<number> = []; 1581 for (let i = 0, j = str.length; i < j; i++) { 1582 arr.push(str.charCodeAt(i)); 1583 } 1584 return new Uint8Array(arr); 1585} 1586 1587// Certificate binary data, which varies with the service. 1588let certData = '-----BEGIN CERTIFICATE-----\n' + 1589 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1590 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1591 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1592 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1593 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1594 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1595 'Qw==\n' + 1596 '-----END CERTIFICATE-----\n'; 1597 1598let encodingBlob: cert.EncodingBlob = { 1599 data: stringToUint8Array(certData), 1600 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1601 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1602}; 1603 1604cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1605 if (error) { 1606 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1607 } else { 1608 console.log('createX509Cert success'); 1609 try { 1610 let sigAlgName = x509Cert.getSignatureAlgName(); 1611 } catch (err) { 1612 let e: BusinessError = err as BusinessError; 1613 console.error('getSignatureAlgName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1614 } 1615 } 1616}); 1617``` 1618 1619### getSignatureAlgOid 1620 1621getSignatureAlgOid() : string 1622 1623Obtains the object identifier (OID) of the X.509 certificate signing algorithm. OIDs are allocated by the International Organization for Standardization (ISO). 1624 1625**Atomic service API**: This API can be used in atomic services since API version 12. 1626 1627**System capability**: SystemCapability.Security.Cert 1628 1629**Return value** 1630 1631| Type | Description | 1632| ------ | --------------------------------- | 1633| string | OID obtained. | 1634 1635**Error codes** 1636 1637For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1638 1639| ID | Error Message | 1640| -------- | ------------------------------------------------- | 1641| 19020001 | memory error. | 1642| 19020002 | runtime error. | 1643| 19030001 | crypto operation error.| 1644 1645**Example** 1646 1647```ts 1648import { cert } from '@kit.DeviceCertificateKit'; 1649import { BusinessError } from '@kit.BasicServicesKit'; 1650 1651// Convert the string into a Uint8Array. 1652function stringToUint8Array(str: string): Uint8Array { 1653 let arr: Array<number> = []; 1654 for (let i = 0, j = str.length; i < j; i++) { 1655 arr.push(str.charCodeAt(i)); 1656 } 1657 return new Uint8Array(arr); 1658} 1659 1660// Certificate binary data, which varies with the service. 1661let certData = '-----BEGIN CERTIFICATE-----\n' + 1662 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1663 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1664 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1665 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1666 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1667 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1668 'Qw==\n' + 1669 '-----END CERTIFICATE-----\n'; 1670 1671let encodingBlob: cert.EncodingBlob = { 1672 data: stringToUint8Array(certData), 1673 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1674 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1675}; 1676 1677cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1678 if (error) { 1679 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1680 } else { 1681 console.log('createX509Cert success'); 1682 try { 1683 let sigAlgOid = x509Cert.getSignatureAlgOid(); 1684 } catch (err) { 1685 let e: BusinessError = err as BusinessError; 1686 console.error('getSignatureAlgOid failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1687 } 1688 } 1689}); 1690``` 1691 1692### getSignatureAlgParams 1693 1694getSignatureAlgParams() : DataBlob 1695 1696Obtains the signing algorithm parameters of this X.509 certificate. 1697 1698**Atomic service API**: This API can be used in atomic services since API version 12. 1699 1700**System capability**: SystemCapability.Security.Cert 1701 1702**Return value** 1703 1704| Type | Description | 1705| --------------------- | ------------------------ | 1706| [DataBlob](#datablob) | X.509 certificate signing algorithm parameters obtained. | 1707 1708**Error codes** 1709 1710For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1711 1712| ID | Error Message | 1713| -------- | ------------------------------------------------- | 1714| 801 | this operation is not supported. | 1715| 19020001 | memory error. | 1716| 19020002 | runtime error. | 1717| 19030001 | crypto operation error.| 1718 1719**Example** 1720 1721```ts 1722import { cert } from '@kit.DeviceCertificateKit'; 1723import { BusinessError } from '@kit.BasicServicesKit'; 1724 1725// Convert the string into a Uint8Array. 1726function stringToUint8Array(str: string): Uint8Array { 1727 let arr: Array<number> = []; 1728 for (let i = 0, j = str.length; i < j; i++) { 1729 arr.push(str.charCodeAt(i)); 1730 } 1731 return new Uint8Array(arr); 1732} 1733 1734// Certificate binary data, which varies with the service. 1735let certData = '-----BEGIN CERTIFICATE-----\n' + 1736 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1737 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1738 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1739 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1740 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1741 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1742 'Qw==\n' + 1743 '-----END CERTIFICATE-----\n'; 1744 1745let encodingBlob: cert.EncodingBlob = { 1746 data: stringToUint8Array(certData), 1747 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1748 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1749}; 1750 1751cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1752 if (error) { 1753 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1754 } else { 1755 console.log('createX509Cert success'); 1756 try { 1757 let sigAlgParams = x509Cert.getSignatureAlgParams(); 1758 } catch (err) { 1759 let e: BusinessError = err as BusinessError; 1760 console.error('getSignatureAlgParams failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1761 } 1762 } 1763}); 1764``` 1765 1766### getKeyUsage 1767 1768getKeyUsage() : DataBlob 1769 1770Obtains the key usage of this X.509 certificate. 1771 1772**Atomic service API**: This API can be used in atomic services since API version 12. 1773 1774**System capability**: SystemCapability.Security.Cert 1775 1776**Return value** 1777 1778| Type | Description | 1779| --------------------- | -------------------- | 1780| [DataBlob](#datablob) | Key usage of the X.509 certificate obtained. | 1781 1782**Error codes** 1783 1784For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1785 1786| ID | Error Message | 1787| -------- | ------------------------------------------------- | 1788| 19020001 | memory error. | 1789| 19030001 | crypto operation error.| 1790 1791**Example** 1792 1793```ts 1794import { cert } from '@kit.DeviceCertificateKit'; 1795import { BusinessError } from '@kit.BasicServicesKit'; 1796 1797// Convert the string into a Uint8Array. 1798function stringToUint8Array(str: string): Uint8Array { 1799 let arr: Array<number> = []; 1800 for (let i = 0, j = str.length; i < j; i++) { 1801 arr.push(str.charCodeAt(i)); 1802 } 1803 return new Uint8Array(arr); 1804} 1805 1806// Certificate binary data, which varies with the service. 1807let certData = '-----BEGIN CERTIFICATE-----\n' + 1808 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1809 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1810 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1811 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1812 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1813 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1814 'Qw==\n' + 1815 '-----END CERTIFICATE-----\n'; 1816 1817let encodingBlob: cert.EncodingBlob = { 1818 data: stringToUint8Array(certData), 1819 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1820 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1821}; 1822 1823cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1824 if (error) { 1825 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1826 } else { 1827 console.log('createX509Cert success'); 1828 try { 1829 let keyUsage = x509Cert.getKeyUsage(); 1830 } catch (err) { 1831 let e: BusinessError = err as BusinessError; 1832 console.error('getKeyUsage failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1833 } 1834 } 1835}); 1836``` 1837 1838### getExtKeyUsage 1839 1840getExtKeyUsage() : DataArray 1841 1842Obtains the usage of the extended key of this X.509 certificate. 1843 1844**Atomic service API**: This API can be used in atomic services since API version 12. 1845 1846**System capability**: SystemCapability.Security.Cert 1847 1848**Return value** 1849 1850| Type | Description | 1851| ----------------------- | ------------------------ | 1852| [DataArray](#dataarray) | Usage of the extended key obtained. | 1853 1854**Error codes** 1855 1856For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1857 1858| ID | Error Message | 1859| -------- | ------------------------------------------------- | 1860| 19020001 | memory error. | 1861| 19020002 | runtime error. | 1862| 19030001 | crypto operation error.| 1863 1864**Example** 1865 1866```ts 1867import { cert } from '@kit.DeviceCertificateKit'; 1868import { BusinessError } from '@kit.BasicServicesKit'; 1869 1870// Convert the string into a Uint8Array. 1871function stringToUint8Array(str: string): Uint8Array { 1872 let arr: Array<number> = []; 1873 for (let i = 0, j = str.length; i < j; i++) { 1874 arr.push(str.charCodeAt(i)); 1875 } 1876 return new Uint8Array(arr); 1877} 1878 1879// Certificate binary data, which varies with the service. 1880let certData = '-----BEGIN CERTIFICATE-----\n' + 1881 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1882 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1883 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1884 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1885 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1886 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1887 'Qw==\n' + 1888 '-----END CERTIFICATE-----\n'; 1889 1890let encodingBlob: cert.EncodingBlob = { 1891 data: stringToUint8Array(certData), 1892 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1893 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1894}; 1895 1896cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1897 if (error) { 1898 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1899 } else { 1900 console.log('createX509Cert success'); 1901 try { 1902 let extKeyUsage = x509Cert.getExtKeyUsage(); 1903 } catch (err) { 1904 let e: BusinessError = err as BusinessError; 1905 console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message); 1906 } 1907 } 1908}); 1909``` 1910 1911### getBasicConstraints 1912 1913getBasicConstraints() : number 1914 1915Obtains the basic constraints for obtaining this X.509 certificate. 1916 1917**Atomic service API**: This API can be used in atomic services since API version 12. 1918 1919**System capability**: SystemCapability.Security.Cert 1920 1921**Return value** 1922 1923| Type | Description | 1924| ------ | -------------------- | 1925| number | Basic constraints obtained. | 1926 1927**Example** 1928 1929```ts 1930import { cert } from '@kit.DeviceCertificateKit'; 1931 1932// Convert the string into a Uint8Array. 1933function stringToUint8Array(str: string): Uint8Array { 1934 let arr: Array<number> = []; 1935 for (let i = 0, j = str.length; i < j; i++) { 1936 arr.push(str.charCodeAt(i)); 1937 } 1938 return new Uint8Array(arr); 1939} 1940 1941// Certificate binary data, which varies with the service. 1942let certData = '-----BEGIN CERTIFICATE-----\n' + 1943 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 1944 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 1945 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 1946 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 1947 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 1948 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 1949 'Qw==\n' + 1950 '-----END CERTIFICATE-----\n'; 1951 1952let encodingBlob: cert.EncodingBlob = { 1953 data: stringToUint8Array(certData), 1954 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 1955 encodingFormat: cert.EncodingFormat.FORMAT_PEM 1956}; 1957 1958cert.createX509Cert(encodingBlob, (error, x509Cert) => { 1959 if (error) { 1960 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 1961 } else { 1962 console.log('createX509Cert success'); 1963 let basicConstraints = x509Cert.getBasicConstraints(); 1964 } 1965}); 1966``` 1967 1968### getSubjectAltNames 1969 1970getSubjectAltNames() : DataArray 1971 1972Obtains the Subject Alternative Names (SANs) of this X.509 certificate. 1973 1974**Atomic service API**: This API can be used in atomic services since API version 12. 1975 1976**System capability**: SystemCapability.Security.Cert 1977 1978**Return value** 1979 1980| Type | Description | 1981| ----------------------- | ------------------------ | 1982| [DataArray](#dataarray) | SANs obtained. | 1983 1984**Error codes** 1985 1986For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 1987 1988| ID | Error Message | 1989| -------- | ------------------------------------------------- | 1990| 19020001 | memory error. | 1991| 19020002 | runtime error. | 1992| 19030001 | crypto operation error.| 1993 1994**Example** 1995 1996```ts 1997import { cert } from '@kit.DeviceCertificateKit'; 1998import { BusinessError } from '@kit.BasicServicesKit'; 1999 2000// Convert the string into a Uint8Array. 2001function stringToUint8Array(str: string): Uint8Array { 2002 let arr: Array<number> = []; 2003 for (let i = 0, j = str.length; i < j; i++) { 2004 arr.push(str.charCodeAt(i)); 2005 } 2006 return new Uint8Array(arr); 2007} 2008 2009// Certificate binary data, which varies with the service. 2010let certData = '-----BEGIN CERTIFICATE-----\n' + 2011 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 2012 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 2013 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 2014 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 2015 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 2016 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 2017 'Qw==\n' + 2018 '-----END CERTIFICATE-----\n'; 2019 2020let encodingBlob: cert.EncodingBlob = { 2021 data: stringToUint8Array(certData), 2022 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2023 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2024}; 2025 2026cert.createX509Cert(encodingBlob, (error, x509Cert) => { 2027 if (error) { 2028 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 2029 } else { 2030 console.log('createX509Cert success'); 2031 try { 2032 let subjectAltNames = x509Cert.getSubjectAltNames(); 2033 } catch (err) { 2034 let e: BusinessError = err as BusinessError; 2035 console.error('getSubjectAltNames failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2036 } 2037 } 2038}); 2039``` 2040 2041### getIssuerAltNames 2042 2043getIssuerAltNames() : DataArray 2044 2045Obtains the Issuer Alternative Names (IANs) of this X.509 certificate. 2046 2047**Atomic service API**: This API can be used in atomic services since API version 12. 2048 2049**System capability**: SystemCapability.Security.Cert 2050 2051**Return value** 2052 2053| Type | Description | 2054| ----------------------- | -------------------------- | 2055| [DataArray](#dataarray) | IANs obtained. | 2056 2057**Error codes** 2058 2059For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2060 2061| ID | Error Message | 2062| -------- | ------------------------------------------------- | 2063| 19020001 | memory error. | 2064| 19020002 | runtime error. | 2065| 19030001 | crypto operation error.| 2066 2067**Example** 2068 2069```ts 2070import { cert } from '@kit.DeviceCertificateKit'; 2071import { BusinessError } from '@kit.BasicServicesKit'; 2072 2073// Convert the string into a Uint8Array. 2074function stringToUint8Array(str: string): Uint8Array { 2075 let arr: Array<number> = []; 2076 for (let i = 0, j = str.length; i < j; i++) { 2077 arr.push(str.charCodeAt(i)); 2078 } 2079 return new Uint8Array(arr); 2080} 2081 2082// Certificate binary data, which varies with the service. 2083let certData = '-----BEGIN CERTIFICATE-----\n' + 2084 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 2085 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 2086 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 2087 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 2088 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 2089 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 2090 'Qw==\n' + 2091 '-----END CERTIFICATE-----\n'; 2092 2093let encodingBlob: cert.EncodingBlob = { 2094 data: stringToUint8Array(certData), 2095 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2096 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2097}; 2098 2099cert.createX509Cert(encodingBlob, (error, x509Cert) => { 2100 if (error) { 2101 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 2102 } else { 2103 console.log('createX509Cert success'); 2104 try { 2105 let issuerAltNames = x509Cert.getIssuerAltNames(); 2106 } catch (err) { 2107 let e: BusinessError = err as BusinessError; 2108 console.error('getIssuerAltNames failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2109 } 2110 } 2111}); 2112``` 2113 2114### getItem<sup>10+</sup> 2115 2116getItem(itemType: CertItemType) : DataBlob 2117 2118Obtains the fields in the X.509 certificate. 2119 2120**Atomic service API**: This API can be used in atomic services since API version 12. 2121 2122**System capability**: SystemCapability.Security.Cert 2123 2124**Return value** 2125 2126| Type | Description | 2127| --------------------- | ----------------------------------------- | 2128| [DataBlob](#datablob) | Fields in DER format. | 2129 2130**Error codes** 2131 2132For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2133 2134| ID | Error Message | 2135| -------- | ----------------------- | 2136| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 2137| 19020001 | memory error. | 2138| 19020002 | runtime error. | 2139| 19030001 | crypto operation error. | 2140 2141**Example** 2142 2143```ts 2144import { cert } from '@kit.DeviceCertificateKit'; 2145import { BusinessError } from '@kit.BasicServicesKit'; 2146 2147// Convert the string into a Uint8Array. 2148function stringToUint8Array(str: string): Uint8Array { 2149 let arr: Array<number> = []; 2150 for (let i = 0, j = str.length; i < j; i++) { 2151 arr.push(str.charCodeAt(i)); 2152 } 2153 return new Uint8Array(arr); 2154} 2155 2156// Certificate binary data, which varies with the service. 2157let certData = '-----BEGIN CERTIFICATE-----\n' + 2158 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 2159 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 2160 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 2161 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 2162 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 2163 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 2164 'Qw==\n' + 2165 '-----END CERTIFICATE-----\n'; 2166 2167let encodingBlob: cert.EncodingBlob = { 2168 data: stringToUint8Array(certData), 2169 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2170 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2171}; 2172 2173cert.createX509Cert(encodingBlob, (error, x509Cert) => { 2174 if (error) { 2175 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 2176 } else { 2177 console.log('createX509Cert success'); 2178 try { 2179 let tbs = x509Cert.getItem(cert.CertItemType.CERT_ITEM_TYPE_TBS); 2180 let pubKey = x509Cert.getItem(cert.CertItemType.CERT_ITEM_TYPE_PUBLIC_KEY); 2181 } catch (err) { 2182 let e: BusinessError = err as BusinessError; 2183 console.error('getItem failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2184 } 2185 } 2186}); 2187``` 2188### match<sup>11+</sup> 2189 2190match(param: X509CertMatchParameters): boolean 2191 2192Checks whether this certificate matches the specified parameters. 2193 2194**Atomic service API**: This API can be used in atomic services since API version 12. 2195 2196**System capability**: SystemCapability.Security.Cert 2197 2198**Parameters** 2199 2200| Name | Type | Mandatory | Description | 2201| --------- | ------ | ---- | ------------------------------------------ | 2202| param | [X509CertMatchParameters](#x509certmatchparameters11) | Yes | Parameters specified for matching the certificate. | 2203 2204**Return value** 2205 2206| Type | Description | 2207| --------------------- | ----------------------------------------- | 2208| boolean | Returns **true** if the certificate matches the parameters specified; returns **false** otherwise. | 2209 2210**Error codes** 2211 2212For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2213 2214| ID | Error Message | 2215| -------- | ------------- | 2216| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 2217| 19020001 | memory error. | 2218| 19030001 | crypto operation error. | 2219 2220**Example** 2221 2222```ts 2223import { cert } from '@kit.DeviceCertificateKit'; 2224import { BusinessError } from '@kit.BasicServicesKit'; 2225 2226// Convert the string into a Uint8Array. 2227function stringToUint8Array(str: string): Uint8Array { 2228 let arr: Array<number> = []; 2229 for (let i = 0, j = str.length; i < j; i++) { 2230 arr.push(str.charCodeAt(i)); 2231 } 2232 return new Uint8Array(arr); 2233} 2234 2235async function createX509Cert(): Promise<cert.X509Cert> { 2236 let certData = '-----BEGIN CERTIFICATE-----\n' + 2237 'MIIDTTCCA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Na\n' + 2252 'zFwz8LJ7ukWvf5koBqcHq2zsuVByOIPXLIrAJPtMmBb/pHCFt8hxOxwqujdrxz16\n' + 2253 'pe5LQUYzvG1YCxw3Ye9OrM1yXJQr/4KYncQC1yQQo+UK7NsDRK30PsMEYxhierLA\n' + 2254 'JKyPn1xSlOJiGa2rRn/uevmEOhfagj5TtprU9Gu1+nZo\n' + 2255 '-----END CERTIFICATE-----\n'; 2256 2257 let encodingBlob: cert.EncodingBlob = { 2258 data: stringToUint8Array(certData), 2259 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2260 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2261 }; 2262 2263 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2264 try { 2265 x509Cert = await cert.createX509Cert(encodingBlob); 2266 } catch (err) { 2267 let e: BusinessError = err as BusinessError; 2268 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2269 } 2270 return x509Cert; 2271} 2272 2273async function matchX509Cert() { 2274 const x509Cert = await createX509Cert(); 2275 try { 2276 // The data vary with the service. 2277 const param: cert.X509CertMatchParameters = { 2278 x509Cert, 2279 validDate: '20241121074700Z', 2280 keyUsage: [true, false, false, false, false, false, false, false, false], 2281 publicKeyAlgID: '1.2.840.113549.1.1.1' 2282 }; 2283 const result = x509Cert.match(param); 2284 console.log('call x509Cert match success'); 2285 } catch (err) { 2286 console.error('call x509Cert match failed'); 2287 } 2288} 2289``` 2290 2291### getCRLDistributionPoint<sup>12+</sup> 2292 2293getCRLDistributionPoint(): DataArray 2294 2295Obtains the CRL distribution points of this X.509 certificate. 2296 2297**Atomic service API**: This API can be used in atomic services since API version 12. 2298 2299**System capability**: SystemCapability.Security.Cert 2300 2301**Return value** 2302 2303| Type | Description | 2304| ----------------------- | -------------------------- | 2305| [DataArray](#dataarray) | URIs of the CRL distribution points obtained. | 2306 2307**Error codes** 2308 2309For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2310 2311| ID | Error Message | 2312| -------- | ------------- | 2313| 19020001 | memory error. | 2314| 19020002 | runtime error. | 2315| 19030001 | crypto operation error. | 2316 2317**Example** 2318 2319```ts 2320import { cert } from '@kit.DeviceCertificateKit'; 2321import { BusinessError } from '@kit.BasicServicesKit'; 2322 2323// Convert the string into a Uint8Array. 2324function stringToUint8Array(str: string): Uint8Array { 2325 let arr: Array<number> = []; 2326 for (let i = 0, j = str.length; i < j; i++) { 2327 arr.push(str.charCodeAt(i)); 2328 } 2329 return new Uint8Array(arr); 2330} 2331 2332let certData = "-----BEGIN CERTIFICATE-----\n" + 2333 "MIIB/jCCAaSgAwIBAgICA+gwCgYIKoZIzj0EAwIwLDELMAkGA1UEBhMCQ04xDTAL\n" + 2334 "BgNVBAoMBHRlc3QxDjAMBgNVBAMMBXN1YmNhMB4XDTIzMTAwNzA0MDEwOFoXDTMz\n" + 2335 "MTAwNDA0MDEwOFowLDELMAkGA1UEBhMCQ04xDTALBgNVBAoMBHRlc3QxDjAMBgNV\n" + 2336 "BAMMBWxvY2FsMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZDPvdlJI6Yv4fiaR\n" + 2337 "nQHcusXVbukk90mQ0rBGOYRikFvgvm5cjTdaUGcQKEtwYIKDQl5n6Pf7ElCJ7GRz\n" + 2338 "raWZ+qOBtTCBsjAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdl\n" + 2339 "bmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU63Gbl8gIsUn0VyZ4rya3PCjm\n" + 2340 "sfEwHwYDVR0jBBgwFoAU77mynM0rz1SD43DQjleWM7bF+MEwNwYDVR0fBDAwLjAs\n" + 2341 "oCqgKIYmaHR0cDovL3Rlc3QudGVzdENSTGRwLmNvbS9DUkxfRFBfMS5jcmwwCgYI\n" + 2342 "KoZIzj0EAwIDSAAwRQIhAISKHH9u221mBgdDWfll3loLvEHJ3or9NUO5Zn6SrX6L\n" + 2343 "AiAtRlOa6/mTD68faQTdhsAaQP955QfW34B4yFqU2Bq72A==\n" + 2344 "-----END CERTIFICATE-----\n"; 2345 2346 // Certificate binary data, which varies with the service. 2347let encodingBlob: cert.EncodingBlob = { 2348 data: stringToUint8Array(certData), 2349 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2350 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2351}; 2352 2353async function certGetCRLDistributionPoint() { 2354 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2355 try { 2356 x509Cert = await cert.createX509Cert(encodingBlob); 2357 console.log('createX509Cert success'); 2358 let point = x509Cert.getCRLDistributionPoint(); 2359 } catch (err) { 2360 let e: BusinessError = err as BusinessError; 2361 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2362 } 2363} 2364``` 2365 2366### getIssuerX500DistinguishedName<sup>12+</sup> 2367 2368getIssuerX500DistinguishedName(): X500DistinguishedName 2369 2370Obtains the distinguished name (DN) of the X.509 certificate issuer. 2371 2372**Atomic service API**: This API can be used in atomic services since API version 12. 2373 2374**System capability**: SystemCapability.Security.Cert 2375 2376**Return value** 2377 2378| Type | Description | 2379| --------------------- | ----------------------------------------- | 2380| [X500DistinguishedName](#x500distinguishedname12) | DN object obtained.| 2381 2382**Error codes** 2383 2384For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2385 2386| ID | Error Message | 2387| -------- | ------------- | 2388| 19020001 | memory error. | 2389| 19020002 | runtime error. | 2390| 19030001 | crypto operation error. | 2391 2392**Example** 2393 2394```ts 2395import { cert } from '@kit.DeviceCertificateKit'; 2396import { BusinessError } from '@kit.BasicServicesKit'; 2397 2398// Convert the string into a Uint8Array. 2399function stringToUint8Array(str: string): Uint8Array { 2400 let arr: Array<number> = []; 2401 for (let i = 0, j = str.length; i < j; i++) { 2402 arr.push(str.charCodeAt(i)); 2403 } 2404 return new Uint8Array(arr); 2405} 2406 2407let certData = "-----BEGIN CERTIFICATE-----\n" + 2408 "MIID1TCCA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0aWZpY2F0ZTANBgkqhkiG9w0B\n" + 2423 "AQsFAAOCAQEAWu0u72g5y1weexPoJQnUgcwVtuC+/tTS9YvyCtKYE91gn97LSWn9\n" + 2424 "mXXGmLceU27B8JwhER9JeiQO1SUdDcvlfb5vt6eB+5cbZcgeERUBP8t0znh7DbMg\n" + 2425 "4TFjt9gZ970PZ1OlTBNPoZNRBKIox61KVUhiVKTVSbXlVP1yUF1uSlSq+0NYayHw\n" + 2426 "MnX1BeLxbAcAsTPYHjoeFJIrGkKlydLyt/8hDQzpLRW5uEUTjjqLh7vef0OaOP80\n" + 2427 "MmADt6ojRYvwdMDHF0ASJyupLQ+hiRLVadciK8Z5W34JGN2jwEw5X3nXyAgErIJZ\n" + 2428 "pqdTflnFLnSwy5M3QHB+xjYAcS9l1br2LA==\n" + 2429 "-----END CERTIFICATE-----\n" 2430 2431 // Certificate binary data, which varies with the service. 2432 let encodingBlob: cert.EncodingBlob = { 2433 data: stringToUint8Array(certData), 2434 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2435 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2436 }; 2437 2438async function certGetIssuerX500DistinguishedName() { 2439 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2440 try { 2441 x509Cert = await cert.createX509Cert(encodingBlob); 2442 console.log('createX509Cert success'); 2443 let name = x509Cert.getIssuerX500DistinguishedName(); 2444 } catch (err) { 2445 let e: BusinessError = err as BusinessError; 2446 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2447 } 2448} 2449``` 2450 2451### getSubjectX500DistinguishedName<sup>12+</sup> 2452 2453getSubjectX500DistinguishedName(): X500DistinguishedName 2454 2455Obtains the DN of the X.509 certificate subject (holder). 2456 2457**Atomic service API**: This API can be used in atomic services since API version 12. 2458 2459**System capability**: SystemCapability.Security.Cert 2460 2461**Return value** 2462 2463| Type | Description | 2464| --------------------- | ----------------------------------------- | 2465| [X500DistinguishedName](#x500distinguishedname12) | DN object obtained.| 2466 2467**Error codes** 2468 2469For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2470 2471| ID | Error Message | 2472| -------- | ------------- | 2473| 19020001 | memory error. | 2474| 19020002 | runtime error. | 2475| 19030001 | crypto operation error. | 2476 2477**Example** 2478 2479```ts 2480import { cert } from '@kit.DeviceCertificateKit'; 2481import { BusinessError } from '@kit.BasicServicesKit'; 2482 2483// Convert the string into a Uint8Array. 2484function stringToUint8Array(str: string): Uint8Array { 2485 let arr: Array<number> = []; 2486 for (let i = 0, j = str.length; i < j; i++) { 2487 arr.push(str.charCodeAt(i)); 2488 } 2489 return new Uint8Array(arr); 2490} 2491 2492let certData = "-----BEGIN CERTIFICATE-----\n" + 2493 "MIID1TCCAr2gAwIBAgIITXr1++kFUU4wDQYJKoZIhvcNAQELBQAwcDELMAkGA1UE\n" + 2494 "BhMCQ04xEjAQBgNVBAgTCWd1YW5nZG9uZzERMA8GA1UEBxMIc2hlbnpoZW4xEjAQ\n" + 2495 "BgNVBAoTCXRlc3RTZWNDYTESMBAGA1UECxMJdGVzdFNlY0NhMRIwEAYDVQQDEwl0\n" + 2496 "ZXN0U2VjQ2EwHhcNMjMxMjIxMDAwMDAwWhcNMjcxMjIwMjM1OTU5WjBxMQswCQYD\n" + 2497 "VQQGEwJDTjEOMAwGA1UECBMFZ2Fuc3UxEDAOBgNVBAcTB2xhbnpob3UxFDASBgNV\n" + 2498 "BAoTC3Rlc3RUaGlyZENhMRQwEgYDVQQLEwt0ZXN0VGhpcmRDYTEUMBIGA1UEAxML\n" + 2499 "dGVzdFRoaXJkQ2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDJMKSq\n" + 2500 "Fn4G4EJATauw+4s+n/JbINBAiuhzURzzdt2T8JJQLDV9RHj4mZt84yv6lqEpl2fm\n" + 2501 "gIClfu173pEV51/PSq5IaV481u/Dz/OTy9TwfxmIXAWdNpyodDOg4I9K7LC01ge8\n" + 2502 "xxyKFi7k7m2eTGA4dYQM0E0AEXzCpg2JN3IIIPhzHCIVJmYjcbVxiaFkvT4ZFFUk\n" + 2503 "4rDSbAQdn6dJ29msrFm8iGhMGC/bzq9Bii38Qg4y4o89QYiboRWCxv3XfuibT+jw\n" + 2504 "O3pmfsFuT8/bKOWVm94FmRxiKuj6iE8UVewxtByzDgAsBtJKDjaCv3IkqfbIu+sq\n" + 2505 "/eeJkVJRJXAP3ZpLAgMBAAGjcjBwMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYE\n" + 2506 "FIxvPSwEmjOMW10H+gn2gy5HvMmMMAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEE\n" + 2507 "BAMCAAcwHgYJYIZIAYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTANBgkqhkiG9w0B\n" + 2508 "AQsFAAOCAQEAWu0u72g5y1weexPoJQnUgcwVtuC+/tTS9YvyCtKYE91gn97LSWn9\n" + 2509 "mXXGmLceU27B8JwhER9JeiQO1SUdDcvlfb5vt6eB+5cbZcgeERUBP8t0znh7DbMg\n" + 2510 "4TFjt9gZ970PZ1OlTBNPoZNRBKIox61KVUhiVKTVSbXlVP1yUF1uSlSq+0NYayHw\n" + 2511 "MnX1BeLxbAcAsTPYHjoeFJIrGkKlydLyt/8hDQzpLRW5uEUTjjqLh7vef0OaOP80\n" + 2512 "MmADt6ojRYvwdMDHF0ASJyupLQ+hiRLVadciK8Z5W34JGN2jwEw5X3nXyAgErIJZ\n" + 2513 "pqdTflnFLnSwy5M3QHB+xjYAcS9l1br2LA==\n" + 2514 "-----END CERTIFICATE-----\n" 2515 2516 // Certificate binary data, which varies with the service. 2517 let encodingBlob: cert.EncodingBlob = { 2518 data: stringToUint8Array(certData), 2519 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2520 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2521 }; 2522 2523async function certGetSubjectX500DistinguishedName() { 2524 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2525 try { 2526 x509Cert = await cert.createX509Cert(encodingBlob); 2527 console.log('createX509Cert success'); 2528 let name = x509Cert.getSubjectX500DistinguishedName(); 2529 } catch (err) { 2530 let e: BusinessError = err as BusinessError; 2531 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2532 } 2533} 2534``` 2535 2536### toString<sup>12+</sup> 2537 2538toString(): string 2539 2540Converts the object data into a string. 2541 2542**Atomic service API**: This API can be used in atomic services since API version 12. 2543 2544**System capability**: SystemCapability.Security.Cert 2545 2546**Return value** 2547 2548| Type | Description | 2549| --------------------- | ----------------------------------------- | 2550| string | String obtained.| 2551 2552**Error codes** 2553 2554For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2555 2556| ID | Error Message | 2557| -------- | ------------- | 2558| 19020001 | memory error. | 2559| 19020002 | runtime error. | 2560| 19030001 | crypto operation error. | 2561 2562**Example** 2563 2564```ts 2565import { cert } from '@kit.DeviceCertificateKit'; 2566import { BusinessError } from '@kit.BasicServicesKit'; 2567 2568// Convert the string into a Uint8Array. 2569function stringToUint8Array(str: string): Uint8Array { 2570 let arr: Array<number> = []; 2571 for (let i = 0, j = str.length; i < j; i++) { 2572 arr.push(str.charCodeAt(i)); 2573 } 2574 return new Uint8Array(arr); 2575} 2576 2577let certData = "-----BEGIN CERTIFICATE-----\n" + 2578 "MIID1TCCAr2gAwIBAgIITXr1++kFUU4wDQYJKoZIhvcNAQELBQAwcDELMAkGA1UE\n" + 2579 "BhMCQ04xEjAQBgNVBAgTCWd1YW5nZG9uZzERMA8GA1UEBxMIc2hlbnpoZW4xEjAQ\n" + 2580 "BgNVBAoTCXRlc3RTZWNDYTESMBAGA1UECxMJdGVzdFNlY0NhMRIwEAYDVQQDEwl0\n" + 2581 "ZXN0U2VjQ2EwHhcNMjMxMjIxMDAwMDAwWhcNMjcxMjIwMjM1OTU5WjBxMQswCQYD\n" + 2582 "VQQGEwJDTjEOMAwGA1UECBMFZ2Fuc3UxEDAOBgNVBAcTB2xhbnpob3UxF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+hiRLVadciK8Z5W34JGN2jwEw5X3nXyAgErIJZ\n" + 2598 "pqdTflnFLnSwy5M3QHB+xjYAcS9l1br2LA==\n" + 2599 "-----END CERTIFICATE-----\n" 2600 2601 // Certificate binary data, which varies with the service. 2602 let encodingBlob: cert.EncodingBlob = { 2603 data: stringToUint8Array(certData), 2604 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2605 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2606 }; 2607 2608async function certToString() { 2609 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2610 try { 2611 x509Cert = await cert.createX509Cert(encodingBlob); 2612 console.log('createX509Cert success'); 2613 console.info('certToString success: ' + JSON.stringify(x509Cert.toString())); 2614 } catch (err) { 2615 let e: BusinessError = err as BusinessError; 2616 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2617 } 2618} 2619``` 2620 2621### hashCode<sup>12+</sup> 2622 2623hashCode(): Uint8Array 2624 2625Obtains the hash value of the data in DER format. 2626 2627**Atomic service API**: This API can be used in atomic services since API version 12. 2628 2629**System capability**: SystemCapability.Security.Cert 2630 2631**Return value** 2632 2633| Type | Description | 2634| --------------------- | ----------------------------------------- | 2635| Uint8Array | Hash value obtained.| 2636 2637**Error codes** 2638 2639For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2640 2641| ID | Error Message | 2642| -------- | ------------- | 2643| 19020001 | memory error. | 2644| 19020002 | runtime error. | 2645| 19030001 | crypto operation error. | 2646 2647**Example** 2648 2649```ts 2650import { cert } from '@kit.DeviceCertificateKit'; 2651import { BusinessError } from '@kit.BasicServicesKit'; 2652 2653// Convert the string into a Uint8Array. 2654function stringToUint8Array(str: string): Uint8Array { 2655 let arr: Array<number> = []; 2656 for (let i = 0, j = str.length; i < j; i++) { 2657 arr.push(str.charCodeAt(i)); 2658 } 2659 return new Uint8Array(arr); 2660} 2661 2662let certData = "-----BEGIN CERTIFICATE-----\n" + 2663 "MIID1TCCAr2gAwIBAg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0ZTANBgkqhkiG9w0B\n" + 2678 "AQsFAAOCAQEAWu0u72g5y1weexPoJQnUgcwVtuC+/tTS9YvyCtKYE91gn97LSWn9\n" + 2679 "mXXGmLceU27B8JwhER9JeiQO1SUdDcvlfb5vt6eB+5cbZcgeERUBP8t0znh7DbMg\n" + 2680 "4TFjt9gZ970PZ1OlTBNPoZNRBKIox61KVUhiVKTVSbXlVP1yUF1uSlSq+0NYayHw\n" + 2681 "MnX1BeLxbAcAsTPYHjoeFJIrGkKlydLyt/8hDQzpLRW5uEUTjjqLh7vef0OaOP80\n" + 2682 "MmADt6ojRYvwdMDHF0ASJyupLQ+hiRLVadciK8Z5W34JGN2jwEw5X3nXyAgErIJZ\n" + 2683 "pqdTflnFLnSwy5M3QHB+xjYAcS9l1br2LA==\n" + 2684 "-----END CERTIFICATE-----\n" 2685 2686 // Certificate binary data, which varies with the service. 2687 let encodingBlob: cert.EncodingBlob = { 2688 data: stringToUint8Array(certData), 2689 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2690 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2691 }; 2692 2693async function certHashCode() { 2694 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2695 try { 2696 x509Cert = await cert.createX509Cert(encodingBlob); 2697 console.log('createX509Cert success'); 2698 console.info('certHashCode success: ' + JSON.stringify(x509Cert.hashCode())); 2699 } catch (err) { 2700 let e: BusinessError = err as BusinessError; 2701 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2702 } 2703} 2704``` 2705 2706### getExtensionsObject<sup>12+</sup> 2707 2708getExtensionsObject(): CertExtension 2709 2710Obtains the certification extensions in DER format. 2711 2712**Atomic service API**: This API can be used in atomic services since API version 12. 2713 2714**System capability**: SystemCapability.Security.Cert 2715 2716**Return value** 2717 2718| Type | Description | 2719| --------------------- | ----------------------------------------- | 2720| [CertExtension](#certextension10) | Certificate extensions object obtained.| 2721 2722**Error codes** 2723 2724For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2725 2726| ID | Error Message | 2727| -------- | ------------- | 2728| 19020001 | memory error. | 2729| 19020002 | runtime error. | 2730| 19030001 | crypto operation error. | 2731 2732**Example** 2733 2734```ts 2735import { cert } from '@kit.DeviceCertificateKit'; 2736import { BusinessError } from '@kit.BasicServicesKit'; 2737 2738// Convert the string into a Uint8Array. 2739function stringToUint8Array(str: string): Uint8Array { 2740 let arr: Array<number> = []; 2741 for (let i = 0, j = str.length; i < j; i++) { 2742 arr.push(str.charCodeAt(i)); 2743 } 2744 return new Uint8Array(arr); 2745} 2746 2747let certData = "-----BEGIN CERTIFICATE-----\n" + 2748 "MIID1TCCAr2gAwIBAgIITXr1++kFUU4wDQYJKoZIhvcNAQELBQAwcDELMAkGA1UE\n" + 2749 "BhMCQ04xEjAQBgNVBAgTCWd1YW5nZG9uZzERMA8GA1UEBxMIc2hlbnpoZW4xEjAQ\n" + 2750 "BgNVBAoTCXRlc3RTZWNDYTESMBAGA1UECxMJdGVzdFNlY0NhMRIwEAYDVQQDEwl0\n" + 2751 "ZXN0U2VjQ2EwHhcNMjMxMjIxMDAwMDAwWhcNMjcxMjIwMjM1OTU5WjBxMQswCQYD\n" + 2752 "VQQGEwJDTjEOMAwGA1UECBMFZ2Fuc3UxEDAOBgNVBAcTB2xhbnpob3UxFDASBgNV\n" + 2753 "BAoTC3Rlc3RUaGlyZENhMRQwEgYDVQQLEwt0ZXN0VGhpcmRDYTEUMBIGA1UEAxML\n" + 2754 "dGVzdFRoaXJkQ2EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDJMKSq\n" + 2755 "Fn4G4EJATauw+4s+n/JbINBAiuhzURzzdt2T8JJQLDV9RHj4mZt84yv6lqEpl2fm\n" + 2756 "gIClfu173pEV51/PSq5IaV481u/Dz/OTy9TwfxmIXAWdNpyodDOg4I9K7LC01ge8\n" + 2757 "xxyKFi7k7m2eTGA4dYQM0E0AEXzCpg2JN3IIIPhzHCIVJmYjcbVxiaFkvT4ZFFUk\n" + 2758 "4rDSbAQdn6dJ29msrFm8iGhMGC/bzq9Bii38Qg4y4o89QYiboRWCxv3XfuibT+jw\n" + 2759 "O3pmfsFuT8/bKOWVm94FmRxiKuj6iE8UVewxtByzDgAsBtJKDjaCv3IkqfbIu+sq\n" + 2760 "/eeJkVJRJXAP3ZpLAgMBAAGjcjBwMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYE\n" + 2761 "FIxvPSwEmjOMW10H+gn2gy5HvMmMMAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEE\n" + 2762 "BAMCAAcwHgYJYIZIAYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTANBgkqhkiG9w0B\n" + 2763 "AQsFAAOCAQEAWu0u72g5y1weexPoJQnUgcwVtuC+/tTS9YvyCtKYE91gn97LSWn9\n" + 2764 "mXXGmLceU27B8JwhER9JeiQO1SUdDcvlfb5vt6eB+5cbZcgeERUBP8t0znh7DbMg\n" + 2765 "4TFjt9gZ970PZ1OlTBNPoZNRBKIox61KVUhiVKTVSbXlVP1yUF1uSlSq+0NYayHw\n" + 2766 "MnX1BeLxbAcAsTPYHjoeFJIrGkKlydLyt/8hDQzpLRW5uEUTjjqLh7vef0OaOP80\n" + 2767 "MmADt6ojRYvwdMDHF0ASJyupLQ+hiRLVadciK8Z5W34JGN2jwEw5X3nXyAgErIJZ\n" + 2768 "pqdTflnFLnSwy5M3QHB+xjYAcS9l1br2LA==\n" + 2769 "-----END CERTIFICATE-----\n" 2770 2771 // Certificate binary data, which varies with the service. 2772 let encodingBlob: cert.EncodingBlob = { 2773 data: stringToUint8Array(certData), 2774 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 2775 encodingFormat: cert.EncodingFormat.FORMAT_PEM 2776 }; 2777 2778async function certGetExtensionsObject() { 2779 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 2780 try { 2781 x509Cert = await cert.createX509Cert(encodingBlob); 2782 console.log('createX509Cert success'); 2783 let object = x509Cert.getExtensionsObject(); 2784 } catch (err) { 2785 let e: BusinessError = err as BusinessError; 2786 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2787 } 2788} 2789``` 2790 2791## cert.createCertExtension<sup>10+</sup> 2792 2793createCertExtension(inStream : EncodingBlob, callback : AsyncCallback\<CertExtension>) : void 2794 2795Creates a **CertExtension** instance. This API uses an asynchronous callback to return the result. 2796 2797**Atomic service API**: This API can be used in atomic services since API version 12. 2798 2799**System capability**: SystemCapability.Security.Cert 2800 2801**Parameters** 2802 2803| Name | Type | Mandatory | Description | 2804| -------- | ------------------------------------------------- | ---- | -------------------------- | 2805| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized data of the certificate extension. | 2806| callback | AsyncCallback\<[CertExtension](#certextension10)> | Yes | Callback used to return the **CertExtension** instance created. | 2807 2808**Error codes** 2809 2810For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2811 2812| ID | Error Message | 2813| -------- | ------------- | 2814| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 2815| 801 | this operation is not supported. | 2816| 19020001 | memory error. | 2817 2818**Example** 2819 2820```ts 2821import { cert } from '@kit.DeviceCertificateKit'; 2822 2823// Binary data of the certificate extension, which varies with the services. 2824let extData = new Uint8Array([ 2825 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 2826 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 2827 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 2828 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 2829 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 2830 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 2831 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 2832 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 2833 0xD9, 0xE4 2834]); 2835 2836let encodingBlob: cert.EncodingBlob = { 2837 data: extData, 2838 // Assign a value based on the encodingData format. Currently, only FORMAT_DER is supported. 2839 encodingFormat: cert.EncodingFormat.FORMAT_DER 2840}; 2841 2842cert.createCertExtension(encodingBlob, (error, certExt) => { 2843 if (error) { 2844 console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message); 2845 } else { 2846 console.log('createCertExtension success'); 2847 } 2848}); 2849``` 2850 2851## cert.createCertExtension<sup>10+</sup> 2852 2853createCertExtension(inStream : EncodingBlob) : Promise\<CertExtension> 2854 2855Creates a **CertExtension** instance. This API uses a promise to return the result. 2856 2857**Atomic service API**: This API can be used in atomic services since API version 12. 2858 2859**System capability**: SystemCapability.Security.Cert 2860 2861**Parameters** 2862 2863| Name | Type | Mandatory | Description | 2864| -------- | ----------------------------- | ---- | -------------------------- | 2865| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized data of the certificate extension. | 2866 2867**Return value** 2868 2869| Type | Description | 2870| ------------------------------------------- | -------------------- | 2871| Promise\<[CertExtension](#certextension10)> | Promise used to return the **CertExtension** instance created. | 2872 2873**Error codes** 2874 2875For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2876 2877| ID | Error Message | 2878| -------- | ------------- | 2879| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 2880| 801 | this operation is not supported. | 2881| 19020001 | memory error. | 2882 2883**Example** 2884 2885```ts 2886import { cert } from '@kit.DeviceCertificateKit'; 2887import { BusinessError } from '@kit.BasicServicesKit'; 2888 2889// Binary data of the certificate extension, which varies with the services. 2890let extData = new Uint8Array([ 2891 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 2892 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 2893 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 2894 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 2895 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 2896 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 2897 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 2898 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 2899 0xD9, 0xE4 2900]); 2901 2902let encodingBlob: cert.EncodingBlob = { 2903 data: extData, 2904 // Assign a value based on the encodingData format. Currently, only FORMAT_DER is supported. 2905 encodingFormat: cert.EncodingFormat.FORMAT_DER 2906}; 2907 2908cert.createCertExtension(encodingBlob).then(certExt => { 2909 console.log('createCertExtension success'); 2910}).catch((error: BusinessError) => { 2911 console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message); 2912}); 2913``` 2914 2915## CertExtension<sup>10+</sup> 2916 2917Provides APIs for operating the certificate extensions. 2918 2919### getEncoded<sup>10+</sup> 2920 2921getEncoded() : EncodingBlob 2922 2923Obtains the serialized data of the certificate extensions. 2924 2925**Atomic service API**: This API can be used in atomic services since API version 12. 2926 2927**System capability**: SystemCapability.Security.Cert 2928 2929**Return value** 2930 2931| Type | Description | 2932| ----------------------------- | ---------------------------- | 2933| [EncodingBlob](#encodingblob) | Serialized data obtained. | 2934 2935**Error codes** 2936 2937For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 2938 2939| ID | Error Message | 2940| -------- | ----------------------- | 2941| 19020001 | memory error. | 2942| 19020002 | runtime error. | 2943| 19030001 | crypto operation error. | 2944 2945**Example** 2946 2947```ts 2948import { cert } from '@kit.DeviceCertificateKit'; 2949import { BusinessError } from '@kit.BasicServicesKit'; 2950 2951// Binary data of the certificate extension, which varies with the services. 2952let extData = new Uint8Array([ 2953 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 2954 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 2955 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 2956 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 2957 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 2958 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 2959 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 2960 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 2961 0xD9, 0xE4 2962]); 2963 2964let encodingBlob: cert.EncodingBlob = { 2965 data: extData, 2966 // Assign a value based on the encodingData format. Currently, only FORMAT_DER is supported. 2967 encodingFormat: cert.EncodingFormat.FORMAT_DER 2968}; 2969 2970cert.createCertExtension(encodingBlob, (error, certExt) => { 2971 if (error) { 2972 console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message); 2973 } else { 2974 console.log('createCertExtension success'); 2975 try { 2976 let extEncodedBlob = certExt.getEncoded(); 2977 } catch (err) { 2978 let e: BusinessError = err as BusinessError; 2979 console.error('ext getEncoded failed, errCode: ' + e.code + ', errMsg: ' + e.message); 2980 } 2981 } 2982}); 2983``` 2984 2985### getOidList<sup>10+</sup> 2986 2987getOidList(valueType : ExtensionOidType) : DataArray 2988 2989Obtains the OIDs of the certificate extensions. 2990 2991**Atomic service API**: This API can be used in atomic services since API version 12. 2992 2993**System capability**: SystemCapability.Security.Cert 2994 2995**Parameters** 2996 2997| Name | Type | Mandatory | Description | 2998| --------- | ------------------------------------- | ---- | ------------------------------ | 2999| valueType | [ExtensionOidType](#extensionoidtype10) | Yes | Type of the OIDs to obtain. | 3000 3001**Return value** 3002 3003| Type | Description | 3004| ----------------------- | -------------------------------- | 3005| [DataArray](#dataarray) | OIDs obtained. | 3006 3007**Error codes** 3008 3009For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3010 3011| ID | Error Message | 3012| -------- | ----------------------- | 3013| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3014| 19020001 | memory error. | 3015| 19020002 | runtime error. | 3016| 19030001 | crypto operation error. | 3017 3018**Example** 3019 3020```ts 3021import { cert } from '@kit.DeviceCertificateKit'; 3022import { BusinessError } from '@kit.BasicServicesKit'; 3023 3024// Binary data of the certificate extension, which varies with the services. 3025let extData = new Uint8Array([ 3026 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 3027 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 3028 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 3029 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 3030 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 3031 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 3032 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 3033 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 3034 0xD9, 0xE4 3035]); 3036 3037let encodingBlob: cert.EncodingBlob = { 3038 data: extData, 3039 // Assign a value based on the encodingData format. Currently, only FORMAT_DER is supported. 3040 encodingFormat: cert.EncodingFormat.FORMAT_DER 3041}; 3042 3043cert.createCertExtension(encodingBlob, (error, certExt) => { 3044 if (error) { 3045 console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3046 } else { 3047 console.log('createCertExtension success'); 3048 try { 3049 let oidList = certExt.getOidList(cert.ExtensionOidType.EXTENSION_OID_TYPE_ALL); 3050 } catch (err) { 3051 let e: BusinessError = err as BusinessError; 3052 console.error('ext getOidList failed, errCode: ' + e.code + ', errMsg: ' + e.message); 3053 } 3054 } 3055}); 3056``` 3057 3058### getEntry<sup>10+</sup> 3059 3060getEntry(valueType: ExtensionEntryType, oid : DataBlob) : DataBlob 3061 3062Obtains the certificate extension object information. 3063 3064**Atomic service API**: This API can be used in atomic services since API version 12. 3065 3066**System capability**: SystemCapability.Security.Cert 3067 3068**Parameters** 3069 3070| Name | Type | Mandatory | Description | 3071| --------- | ----------------------------------------- | ---- | -------------------------------- | 3072| valueType | [ExtensionEntryType](#extensionentrytype10) | Yes | Type of the information to obtain. | 3073| oid | [DataBlob](#datablob) | Yes | OID of the certificate extension to obtain. | 3074 3075**Return value** 3076 3077| Type | Description | 3078| --------------------- | ---------------------------- | 3079| [DataBlob](#datablob) | Certificate extension object information obtained. | 3080 3081**Error codes** 3082 3083For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3084 3085| ID | Error Message | 3086| -------- | ----------------------- | 3087| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3088| 19020001 | memory error. | 3089| 19020002 | runtime error. | 3090| 19030001 | crypto operation error. | 3091 3092**Example** 3093 3094```ts 3095import { cert } from '@kit.DeviceCertificateKit'; 3096import { BusinessError } from '@kit.BasicServicesKit'; 3097 3098// Binary data of the certificate extension, which varies with the services. 3099let extData = new Uint8Array([ 3100 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 3101 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 3102 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 3103 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 3104 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 3105 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 3106 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 3107 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 3108 0xD9, 0xE4 3109]); 3110 3111let encodingBlob: cert.EncodingBlob = { 3112 data: extData, 3113 // Assign a value based on the encodingData format. Currently, only FORMAT_DER is supported. 3114 encodingFormat: cert.EncodingFormat.FORMAT_DER 3115}; 3116 3117cert.createCertExtension(encodingBlob, (error, certExt) => { 3118 if (error) { 3119 console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3120 } else { 3121 console.log('createCertExtension success'); 3122 let oid = new Uint8Array([0x32, 0x2e, 0x35, 0x2e, 0x32, 0x39, 0x2e, 0x31, 0x35]); 3123 let oidBlob: cert.DataBlob = { 3124 data: oid 3125 } 3126 try { 3127 let entry = certExt.getEntry(cert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, oidBlob); 3128 } catch (err) { 3129 let e: BusinessError = err as BusinessError; 3130 console.error('ext getEntry failed, errCode: ' + e.code + ', errMsg: ' + e.message); 3131 } 3132 } 3133}); 3134``` 3135 3136 3137### checkCA<sup>10+</sup> 3138 3139checkCA() : number 3140 3141Checks whether the certificate is a CA certificate. 3142 3143**Atomic service API**: This API can be used in atomic services since API version 12. 3144 3145**System capability**: SystemCapability.Security.Cert 3146 3147**Return value** 3148 3149| Type | Description | 3150| ------ | ------------------------------------------------------------ | 3151| number | If the key purpose in the certificate extension contains signing and the CA field in the basic constraints is **true**, the certificate is a CA certificate. Returns **-1** if the certificate is not a CA certificate; returns the path length in the basic constraints otherwise. Returns **-2** if the certificate is a CA certificate but the path length is not specified in the basic constraints, which means the path length is not limited. | 3152 3153**Error codes** 3154 3155For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3156 3157| ID | Error Message | 3158| -------- | ----------------------- | 3159| 19020001 | memory error. | 3160| 19020002 | runtime error. | 3161| 19030001 | crypto operation error. | 3162 3163**Example** 3164 3165```ts 3166import { cert } from '@kit.DeviceCertificateKit'; 3167import { BusinessError } from '@kit.BasicServicesKit'; 3168 3169// Binary data of the certificate extension, which varies with the services. 3170let extData = new Uint8Array([ 3171 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 3172 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 3173 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 3174 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 3175 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 3176 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 3177 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 3178 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 3179 0xD9, 0xE4 3180]); 3181 3182let encodingBlob: cert.EncodingBlob = { 3183 data: extData, 3184 // Assign a value based on the encodingData format. Currently, only FORMAT_DER is supported. 3185 encodingFormat: cert.EncodingFormat.FORMAT_DER 3186}; 3187cert.createCertExtension(encodingBlob, (error, certExt) => { 3188 if (error) { 3189 console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3190 } else { 3191 console.log('createCertExtension success'); 3192 try { 3193 let res = certExt.checkCA(); 3194 } catch (err) { 3195 let e: BusinessError = err as BusinessError; 3196 console.error('ext checkCA failed, errCode: ' + e.code + ', errMsg: ' + e.message); 3197 } 3198 } 3199}); 3200``` 3201 3202### hasUnsupportedCriticalExtension<sup>11+</sup> 3203 3204hasUnsupportedCriticalExtension(): boolean 3205 3206Checks whether there is critical extension that is not supported. 3207 3208**Atomic service API**: This API can be used in atomic services since API version 12. 3209 3210**System capability**: SystemCapability.Security.Cert 3211 3212**Return value** 3213 3214| Type | Description | 3215| ------- | ------------------------------------------------------- | 3216| boolean | Returns **true** if unsupported critical extension is found; returns **false** otherwise. | 3217 3218**Error codes** 3219 3220For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3221 3222| ID | Error Message | 3223| -------- | ----------------------- | 3224| 19020001 | memory error. | 3225| 19020002 | runtime error. | 3226| 19030001 | crypto operation error. | 3227 3228**Example** 3229 3230```ts 3231import { cert } from '@kit.DeviceCertificateKit'; 3232import { BusinessError } from '@kit.BasicServicesKit'; 3233 3234let encodingData = new Uint8Array([ 3235 0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D, 3236 0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03, 3237 0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55, 3238 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03, 3239 0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55, 3240 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C, 3241 0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86, 3242 0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0, 3243 0xD9, 0xE4 3244]); 3245let encodingBlob: cert.EncodingBlob = { 3246 data: new Uint8Array(encodingData), 3247 encodingFormat: cert.EncodingFormat.FORMAT_DER 3248}; 3249 3250cert.createCertExtension(encodingBlob).then((extensionObj) => { 3251 console.log('createCertExtension success!'); 3252 const result = extensionObj.hasUnsupportedCriticalExtension() 3253 console.log('has unsupported critical extension result is:' + result); 3254}).catch((err: BusinessError) => { 3255 console.error('createCertExtension failed'); 3256}); 3257``` 3258 3259## cert.createX509Crl<sup>(deprecated)</sup> 3260 3261createX509Crl(inStream : EncodingBlob, callback : AsyncCallback\<X509Crl>) : void 3262 3263Creates an **X509Crl** instance. This API uses an asynchronous callback to return the result. 3264 3265> **NOTE** 3266> 3267> This API is deprecated since API version 11. Use [cert.createX509CRL](#certcreatex509crl11) instead. 3268 3269**System capability**: SystemCapability.Security.Cert 3270 3271**Parameters** 3272 3273| Name | Type | Mandatory | Description | 3274| -------- | ----------------------------------- | ---- | ------------------------------ | 3275| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized CRL data. | 3276| callback | AsyncCallback\<[X509Crl](#x509crldeprecated)> | Yes | Callback used to return the **X509Crl** instance created. | 3277 3278**Error codes** 3279 3280For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3281 3282| ID | Error Message | 3283| -------- | ------------- | 3284| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3285| 801 | this operation is not supported. | 3286| 19020001 | memory error. | 3287 3288**Example** 3289 3290```ts 3291import { cert } from '@kit.DeviceCertificateKit'; 3292 3293// Convert the string into a Uint8Array. 3294function stringToUint8Array(str: string): Uint8Array { 3295 let arr: Array<number> = []; 3296 for (let i = 0, j = str.length; i < j; i++) { 3297 arr.push(str.charCodeAt(i)); 3298 } 3299 return new Uint8Array(arr); 3300} 3301 3302let crlData = '-----BEGIN X509 CRL-----\n' + 3303 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3304 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3305 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3306 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3307 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3308 'eavsH0Q3\n' + 3309 '-----END X509 CRL-----\n'; 3310 3311// Binary data of the CRL, which varies with the service. 3312let encodingBlob: cert.EncodingBlob = { 3313 data: stringToUint8Array(crlData), 3314 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3315 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3316}; 3317 3318cert.createX509Crl(encodingBlob, (error, x509Crl) => { 3319 if (error) { 3320 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3321 } else { 3322 console.log('createX509Crl success'); 3323 } 3324}); 3325``` 3326 3327## cert.createX509Crl<sup>(deprecated)</sup> 3328 3329createX509Crl(inStream : EncodingBlob) : Promise\<X509Crl> 3330 3331Creates an **X509Crl** instance. This API uses a promise to return the result. 3332 3333> **NOTE** 3334> 3335> This API is deprecated since API version 11. Use [cert.createX509CRL](#certcreatex509crl11-1) instead. 3336 3337**System capability**: SystemCapability.Security.Cert 3338 3339**Parameters** 3340 3341| Name | Type | Mandatory | Description | 3342| -------- | ----------------------------- | ---- | -------------------------- | 3343| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized CRL data. | 3344 3345**Return value** 3346 3347| Type | Description | 3348| ----------------------------- | -------------------- | 3349| Promise\<[X509Crl](#x509crldeprecated)> | Promise used to return the **X509Crl** instance created. | 3350 3351**Error codes** 3352 3353For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3354 3355| ID | Error Message | 3356| -------- | ------------- | 3357| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3358| 801 | this operation is not supported. | 3359| 19020001 | memory error. | 3360 3361**Example** 3362 3363```ts 3364import { cert } from '@kit.DeviceCertificateKit'; 3365import { BusinessError } from '@kit.BasicServicesKit'; 3366 3367// Convert the string into a Uint8Array. 3368function stringToUint8Array(str: string): Uint8Array { 3369 let arr: Array<number> = []; 3370 for (let i = 0, j = str.length; i < j; i++) { 3371 arr.push(str.charCodeAt(i)); 3372 } 3373 return new Uint8Array(arr); 3374} 3375 3376let crlData = '-----BEGIN X509 CRL-----\n' + 3377 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3378 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3379 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3380 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3381 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3382 'eavsH0Q3\n' + 3383 '-----END X509 CRL-----\n'; 3384 3385// Binary data of the CRL, which varies with the service. 3386let encodingBlob: cert.EncodingBlob = { 3387 data: stringToUint8Array(crlData), 3388 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3389 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3390}; 3391 3392cert.createX509Crl(encodingBlob).then(x509Crl => { 3393 console.log('createX509Crl success'); 3394}).catch((error: BusinessError) => { 3395 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3396}); 3397``` 3398 3399## cert.createX509CRL<sup>11+</sup> 3400 3401createX509CRL(inStream : EncodingBlob, callback : AsyncCallback\<X509CRL>) : void 3402 3403Creates an **X509Crl** instance. This API uses an asynchronous callback to return the result. 3404 3405**Atomic service API**: This API can be used in atomic services since API version 12. 3406 3407**System capability**: SystemCapability.Security.Cert 3408 3409**Parameters** 3410 3411| Name | Type | Mandatory | Description | 3412| -------- | ------------------------------------- | ---- | ------------------------------ | 3413| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized CRL data. | 3414| callback | AsyncCallback\<[X509CRL](#x509crl11)> | Yes | Callback used to return the **X509Crl** instance created. | 3415 3416**Error codes** 3417 3418For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3419 3420| ID | Error Message | 3421| -------- | ------------- | 3422| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3423| 801 | this operation is not supported. | 3424| 19020001 | memory error. | 3425 3426**Example** 3427 3428```ts 3429import { cert } from '@kit.DeviceCertificateKit'; 3430 3431// Convert the string into a Uint8Array. 3432function stringToUint8Array(str: string): Uint8Array { 3433 let arr: Array<number> = []; 3434 for (let i = 0, j = str.length; i < j; i++) { 3435 arr.push(str.charCodeAt(i)); 3436 } 3437 return new Uint8Array(arr); 3438} 3439 3440let crlData = '-----BEGIN X509 CRL-----\n' + 3441 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3442 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3443 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3444 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3445 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3446 'eavsH0Q3\n' + 3447 '-----END X509 CRL-----\n'; 3448 3449// Binary data of the CRL, which varies with the service. 3450let encodingBlob: cert.EncodingBlob = { 3451 data: stringToUint8Array(crlData), 3452 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3453 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3454}; 3455 3456cert.createX509CRL(encodingBlob, (error, X509CRL) => { 3457 if (error) { 3458 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3459 } else { 3460 console.log('createX509CRL success'); 3461 } 3462}); 3463``` 3464 3465## cert.createX509CRL<sup>11+</sup> 3466 3467createX509CRL(inStream : EncodingBlob) : Promise\<X509CRL> 3468 3469Creates an **X509Crl** instance. This API uses a promise to return the result. 3470 3471**Atomic service API**: This API can be used in atomic services since API version 12. 3472 3473**System capability**: SystemCapability.Security.Cert 3474 3475**Parameters** 3476 3477| Name | Type | Mandatory | Description | 3478| -------- | ----------------------------- | ---- | -------------------------- | 3479| inStream | [EncodingBlob](#encodingblob) | Yes | Serialized CRL data. | 3480 3481**Return value** 3482 3483| Type | Description | 3484| ------------------------------- | -------------------- | 3485| Promise\<[X509CRL](#x509crl11)> | Promise used to return the **X509Crl** instance created. | 3486 3487**Error codes** 3488 3489For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3490 3491| ID | Error Message | 3492| -------- | ------------- | 3493| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3494| 801 | this operation is not supported. | 3495| 19020001 | memory error. | 3496 3497**Example** 3498 3499```ts 3500import { cert } from '@kit.DeviceCertificateKit'; 3501import { BusinessError } from '@kit.BasicServicesKit'; 3502 3503// Convert the string into a Uint8Array. 3504function stringToUint8Array(str: string): Uint8Array { 3505 let arr: Array<number> = []; 3506 for (let i = 0, j = str.length; i < j; i++) { 3507 arr.push(str.charCodeAt(i)); 3508 } 3509 return new Uint8Array(arr); 3510} 3511 3512let crlData = '-----BEGIN X509 CRL-----\n' + 3513 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3514 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3515 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3516 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3517 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3518 'eavsH0Q3\n' + 3519 '-----END X509 CRL-----\n'; 3520 3521// Binary data of the CRL, which varies with the service. 3522let encodingBlob: cert.EncodingBlob = { 3523 data: stringToUint8Array(crlData), 3524 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3525 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3526}; 3527 3528cert.createX509CRL(encodingBlob).then(X509CRL => { 3529 console.log('createX509CRL success'); 3530}).catch((error: BusinessError) => { 3531 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3532}); 3533``` 3534 3535## X509Crl<sup>(deprecated)</sup> 3536 3537Provides APIs for X.509 certificate CRL operations. 3538 3539> **NOTE** 3540> 3541> This API is deprecated since API version 11. Use [X509CRL](#x509crl11) instead. 3542 3543### isRevoked<sup>(deprecated)</sup> 3544 3545isRevoked(cert : X509Cert) : boolean 3546 3547Checks whether an X.509 certificate is revoked. 3548 3549> **NOTE** 3550> 3551> This API is deprecated since API version 11. Use [X509CRL.isRevoked](#isrevoked11) instead. 3552 3553**System capability**: SystemCapability.Security.Cert 3554 3555**Parameters** 3556 3557| Name | Type | Mandatory | Description | 3558| ------ | -------- | ---- | -------------------- | 3559| cert | X509Cert | Yes | X.509 certificate to check. | 3560 3561**Return value** 3562 3563| Type | Description | 3564| --------- | --------------------------------------------- | 3565| boolean | Returns **true** if the certificate is revoked; returns **false** otherwise. | 3566 3567**Error codes** 3568 3569For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3570 3571| ID | Error Message | 3572| -------- | ------------- | 3573| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3574 3575**Example** 3576 3577```ts 3578import { cert } from '@kit.DeviceCertificateKit'; 3579import { BusinessError } from '@kit.BasicServicesKit'; 3580 3581// Convert the string into a Uint8Array. 3582function stringToUint8Array(str: string): Uint8Array { 3583 let arr: Array<number> = []; 3584 for (let i = 0, j = str.length; i < j; i++) { 3585 arr.push(str.charCodeAt(i)); 3586 } 3587 return new Uint8Array(arr); 3588} 3589 3590let crlData = '-----BEGIN X509 CRL-----\n' + 3591 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3592 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3593 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3594 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3595 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3596 'eavsH0Q3\n' + 3597 '-----END X509 CRL-----\n'; 3598 3599let certData = '-----BEGIN CERTIFICATE-----\n' + 3600 'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' + 3601 'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' + 3602 'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' + 3603 'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' + 3604 'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' + 3605 '0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' + 3606 'BetUokslUfjT6+s/X4ByaxycAA==\n' + 3607 '-----END CERTIFICATE-----\n'; 3608 3609// Binary data of the CRL, which varies with the service. 3610let encodingBlob: cert.EncodingBlob = { 3611 data: stringToUint8Array(crlData), 3612 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3613 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3614}; 3615 3616let certEncodingBlob: cert.EncodingBlob = { 3617 data: stringToUint8Array(certData), 3618 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3619 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3620}; 3621 3622cert.createX509Crl(encodingBlob, (error, x509Crl) => { 3623 if (error) { 3624 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3625 } else { 3626 console.log('createX509Crl success'); 3627 // Create an X509Cert instance. 3628 cert.createX509Cert(certEncodingBlob, (error, x509Cert) => { 3629 if (error) { 3630 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3631 } else { 3632 try { 3633 let revokedFlag = x509Crl.isRevoked(x509Cert); 3634 } catch (error) { 3635 let e: BusinessError = error as BusinessError; 3636 console.error('isRevoked failed, errCode: ' + e.code + ', errMsg: ' + e.message); 3637 } 3638 } 3639 }); 3640 } 3641}); 3642``` 3643 3644### getType<sup>(deprecated)</sup> 3645 3646getType() : string 3647 3648Obtains the CRL type. 3649 3650> **NOTE** 3651> 3652> This API is deprecated since API version 11. Use [X509CRL.getType](#gettype11) instead. 3653 3654**System capability**: SystemCapability.Security.Cert 3655 3656**Return value** 3657 3658| Type | Description | 3659| ------ | -------------------- | 3660| string | CRL type obtained. | 3661 3662**Example** 3663 3664```ts 3665import { cert } from '@kit.DeviceCertificateKit'; 3666 3667// Convert the string into a Uint8Array. 3668function stringToUint8Array(str: string): Uint8Array { 3669 let arr: Array<number> = []; 3670 for (let i = 0, j = str.length; i < j; i++) { 3671 arr.push(str.charCodeAt(i)); 3672 } 3673 return new Uint8Array(arr); 3674} 3675 3676let crlData = '-----BEGIN X509 CRL-----\n' + 3677 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3678 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3679 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3680 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3681 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3682 'eavsH0Q3\n' + 3683 '-----END X509 CRL-----\n'; 3684 3685// Binary data of the CRL, which varies with the service. 3686let encodingBlob: cert.EncodingBlob = { 3687 data: stringToUint8Array(crlData), 3688 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3689 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3690}; 3691 3692cert.createX509Crl(encodingBlob, (error, x509Crl) => { 3693 if (error) { 3694 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3695 } else { 3696 console.log('createX509Crl success'); 3697 let type = x509Crl.getType(); 3698 } 3699}); 3700``` 3701 3702### getEncoded<sup>(deprecated)</sup> 3703 3704getEncoded(callback : AsyncCallback\<EncodingBlob>) : void 3705 3706Obtains the serialized X.509 CRL data. This API uses an asynchronous callback to return the result. 3707 3708> **NOTE** 3709> 3710> This API is deprecated since API version 11. Use [X509CRL.getEncoded](#getencoded11) instead. 3711 3712**System capability**: SystemCapability.Security.Cert 3713 3714**Parameters** 3715 3716| Name | Type | Mandatory | Description | 3717| -------- | ---------------------------- | ---- | ------------------------------------------ | 3718| callback | AsyncCallback\<EncodingBlob> | Yes | Callback used to return the serialized X.509 CRL data obtained. | 3719 3720**Error codes** 3721 3722For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3723 3724| ID | Error Message | 3725| -------- | ----------------------- | 3726| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 3727| 19020001 | memory error. | 3728| 19020002 | runtime error. | 3729| 19030001 | crypto operation error. | 3730 3731**Example** 3732 3733```ts 3734import { cert } from '@kit.DeviceCertificateKit'; 3735 3736// Convert the string into a Uint8Array. 3737function stringToUint8Array(str: string): Uint8Array { 3738 let arr: Array<number> = []; 3739 for (let i = 0, j = str.length; i < j; i++) { 3740 arr.push(str.charCodeAt(i)); 3741 } 3742 return new Uint8Array(arr); 3743} 3744 3745let crlData = '-----BEGIN X509 CRL-----\n' + 3746 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3747 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3748 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3749 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3750 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3751 'eavsH0Q3\n' + 3752 '-----END X509 CRL-----\n'; 3753 3754// Binary data of the CRL, which varies with the service. 3755let encodingBlob: cert.EncodingBlob = { 3756 data: stringToUint8Array(crlData), 3757 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3758 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3759}; 3760 3761cert.createX509Crl(encodingBlob, (error, x509Crl) => { 3762 if (error) { 3763 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3764 } else { 3765 console.log('createX509Crl success'); 3766 x509Crl.getEncoded((error, data) => { 3767 if (error) { 3768 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3769 } else { 3770 console.log('getEncoded success'); 3771 } 3772 }); 3773 } 3774}); 3775``` 3776 3777### getEncoded<sup>(deprecated)</sup> 3778 3779getEncoded() : Promise\<EncodingBlob> 3780 3781Obtains the serialized X.509 CRL data. This API uses a promise to return the result. 3782 3783> **NOTE** 3784> 3785> This API is deprecated since API version 11. Use [X509CRL.getEncoded](#getencoded11-1) instead. 3786 3787**System capability**: SystemCapability.Security.Cert 3788 3789**Return value** 3790 3791| Type | Description | 3792| ---------------------- | -------------------------------- | 3793| Promise\<EncodingBlob> | Promise used to return the serialized X.509 CRL data obtained. | 3794 3795**Error codes** 3796 3797For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3798 3799| ID | Error Message | 3800| -------- | ----------------------- | 3801| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 3802| 19020001 | memory error. | 3803| 19020002 | runtime error. | 3804| 19030001 | crypto operation error. | 3805 3806**Example** 3807 3808```ts 3809import { cert } from '@kit.DeviceCertificateKit'; 3810import { BusinessError } from '@kit.BasicServicesKit'; 3811 3812// Convert the string into a Uint8Array. 3813function stringToUint8Array(str: string): Uint8Array { 3814 let arr: Array<number> = []; 3815 for (let i = 0, j = str.length; i < j; i++) { 3816 arr.push(str.charCodeAt(i)); 3817 } 3818 return new Uint8Array(arr); 3819} 3820 3821let crlData = '-----BEGIN X509 CRL-----\n' + 3822 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3823 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3824 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3825 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3826 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3827 'eavsH0Q3\n' + 3828 '-----END X509 CRL-----\n'; 3829 3830// Binary data of the CRL, which varies with the service. 3831let encodingBlob: cert.EncodingBlob = { 3832 data: stringToUint8Array(crlData), 3833 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3834 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3835}; 3836 3837cert.createX509Crl(encodingBlob).then(x509Crl => { 3838 console.log('createX509Crl success'); 3839 x509Crl.getEncoded().then(result => { 3840 console.log('getEncoded success'); 3841 }).catch((error: BusinessError) => { 3842 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3843 }); 3844}).catch((error: BusinessError) => { 3845 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3846}); 3847``` 3848 3849### verify<sup>(deprecated)</sup> 3850 3851verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void 3852 3853Verifies the signature of the X.509 CRL. This API uses an asynchronous callback to return the result. The RSA algorithm is supported. 3854 3855> **NOTE** 3856> 3857> This API is deprecated since API version 11. Use [X509CRL.verify](#verify11) instead. 3858 3859**System capability**: SystemCapability.Security.Cert 3860 3861**Parameters** 3862 3863| Name | Type | Mandatory | Description | 3864| -------- | -------------------- | ---- | ------------------------------------------------------------ | 3865| key | [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Yes | Public key used for signature verification. | 3866| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails. | 3867 3868**Error codes** 3869 3870For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 3871 3872| ID | Error Message | 3873| -------- | ----------------------- | 3874| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 3875| 19030001 | crypto operation error. | 3876 3877**Example** 3878 3879```ts 3880import { cert } from '@kit.DeviceCertificateKit'; 3881import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 3882import { BusinessError } from '@kit.BasicServicesKit'; 3883 3884// Convert the string into a Uint8Array. 3885function stringToUint8Array(str: string): Uint8Array { 3886 let arr: Array<number> = []; 3887 for (let i = 0, j = str.length; i < j; i++) { 3888 arr.push(str.charCodeAt(i)); 3889 } 3890 return new Uint8Array(arr); 3891} 3892 3893let crlData = '-----BEGIN X509 CRL-----\n' + 3894 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 3895 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 3896 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 3897 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 3898 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 3899 'eavsH0Q3\n' + 3900 '-----END X509 CRL-----\n'; 3901 3902let pubKeyData = new Uint8Array([ 3903 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 3904 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 3905 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 3906 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 3907 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 3908 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 3909 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 3910 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 3911 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 3912 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 3913 0x00, 0x01 3914]); 3915 3916let priKeyData = new Uint8Array([ 3917 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 3918 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x02, 0x61, 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01, 3919 0x00, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 3920 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 3921 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 3922 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 3923 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 3924 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 3925 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 3926 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 3927 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x5A, 0xCF, 0x0F, 3928 0xF5, 0xA6, 0x1C, 0x19, 0x65, 0x8C, 0x94, 0x40, 0xF6, 0x84, 0x28, 0x74, 0x40, 0x42, 0x34, 0xDE, 3929 0xC3, 0x00, 0x5E, 0x72, 0x4D, 0x96, 0xE9, 0x4C, 0xBD, 0xC9, 0xDB, 0x14, 0x9F, 0xD5, 0xBB, 0xA9, 3930 0x0C, 0x20, 0xC2, 0xBE, 0x7A, 0x80, 0x89, 0xEC, 0x99, 0x04, 0xF0, 0xEE, 0x7B, 0x83, 0x20, 0x1D, 3931 0x37, 0x19, 0x55, 0x85, 0xF6, 0x8E, 0x3B, 0xFB, 0x16, 0xF3, 0xD3, 0x6F, 0xEE, 0x73, 0x12, 0x53, 3932 0xCA, 0x77, 0xD7, 0x6C, 0x29, 0xF5, 0x08, 0xA3, 0x09, 0x01, 0x0B, 0x00, 0x05, 0x57, 0xAD, 0x4D, 3933 0xF0, 0x92, 0xB2, 0x5A, 0x8B, 0x19, 0x09, 0x81, 0x86, 0xFE, 0x66, 0xB9, 0x33, 0x88, 0x28, 0xF3, 3934 0x37, 0x73, 0x09, 0x5F, 0xD7, 0xC9, 0xC6, 0xFA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x89, 0x07, 0x86, 0x64, 0x78, 0x69, 0x20, 3946 0x3F, 0xE0, 0xBF, 0x4C, 0x28, 0xC6, 0x04, 0x4D, 0x4D, 0x82, 0x66, 0x6B, 0xAA, 0x64, 0x20, 0xD6, 3947 0x57, 0x68, 0xC6, 0xA0, 0x02, 0x05, 0xB9, 0x28, 0xFC, 0x98, 0xE3, 0x03, 0x5C, 0x9B, 0xEE, 0x29, 3948 0x43, 0x37, 0xFA, 0x03, 0x55, 0x01, 0x02, 0x40, 0x69, 0x5B, 0x7C, 0x24, 0x10, 0xDB, 0xEB, 0x91, 3949 0x33, 0xEF, 0x3F, 0xF2, 0xE6, 0x73, 0x15, 0xCB, 0xF4, 0xF7, 0x89, 0x7D, 0xBF, 0xC0, 0xEA, 0xD2, 3950 0xF3, 0x2B, 0x20, 0xE9, 0x76, 0x54, 0x55, 0x13, 0x50, 0x42, 0x67, 0xB5, 0xCB, 0x73, 0xC0, 0xF7, 3951 0x75, 0x62, 0x04, 0x30, 0x21, 0xAC, 0xAF, 0xD8, 0x44, 0xF4, 0xE1, 0x04, 0x02, 0x7D, 0x61, 0x92, 3952 0x84, 0x99, 0x02, 0x10, 0x64, 0xCB, 0x1F, 0xE9, 0x02, 0x41, 0x00, 0xAB, 0x4B, 0x7D, 0x90, 0x7C, 3953 0x57, 0x08, 0x6B, 0xC0, 0x43, 0x72, 0x09, 0x8A, 0x18, 0x35, 0x36, 0x64, 0x9D, 0x84, 0x8D, 0xF1, 3954 0x84, 0x94, 0x48, 0xC6, 0x80, 0x9D, 0xB9, 0xA2, 0x58, 0x0A, 0x4D, 0x0A, 0xCA, 0x1E, 0xD6, 0x05, 3955 0x55, 0x5B, 0xFE, 0xD7, 0xAA, 0x70, 0xED, 0x76, 0xB3, 0x40, 0x2E, 0xA0, 0xB3, 0x32, 0x37, 0xB0, 3956 0xA0, 0xB9, 0x96, 0x2D, 0xC4, 0x70, 0xE9, 0x99, 0x10, 0x67, 0x8D 3957]); 3958 3959// Binary data of the CRL, which varies with the service. 3960let encodingBlob: cert.EncodingBlob = { 3961 data: stringToUint8Array(crlData), 3962 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 3963 encodingFormat: cert.EncodingFormat.FORMAT_PEM 3964}; 3965 3966cert.createX509Crl(encodingBlob, (error, x509Crl) => { 3967 if (error) { 3968 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 3969 } else { 3970 console.log('createX509Crl success'); 3971 try { 3972 // Generate the public key by AsyKeyGenerator. 3973 let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); 3974 console.log('createAsyKeyGenerator success'); 3975 let priEncodingBlob: cryptoFramework.DataBlob = { 3976 data: priKeyData, 3977 }; 3978 let pubEncodingBlob: cryptoFramework.DataBlob = { 3979 data: pubKeyData, 3980 }; 3981 keyGenerator.convertKey(pubEncodingBlob, priEncodingBlob, (e, keyPair) => { 3982 if (e) { 3983 console.error('convert key failed, message: ' + e.message + 'code: ' + e.code); 3984 } else { 3985 console.log('convert key success'); 3986 x509Crl.verify(keyPair.pubKey, (err, data) => { 3987 if (err) { 3988 console.error('verify failed, errCode: ' + err.code + ', errMsg: ' + err.message); 3989 } else { 3990 console.log('verify success'); 3991 } 3992 }); 3993 } 3994 }) 3995 } catch (error) { 3996 let e: BusinessError = error as BusinessError; 3997 console.error('get pubKey failed, errCode: ' + e.code + ', errMsg: ' + e.message); 3998 } 3999 } 4000}); 4001``` 4002 4003### verify<sup>(deprecated)</sup> 4004 4005verify(key : cryptoFramework.PubKey) : Promise\<void> 4006 4007Verifies the signature of the X.509 CRL. This API uses a promise to return the result. The RSA algorithm is supported. 4008 4009> **NOTE** 4010> 4011> This API is deprecated since API version 11. Use [X509CRL.verify](#verify11-1) instead. 4012 4013**System capability**: SystemCapability.Security.Cert 4014 4015**Parameters** 4016 4017| Name | Type | Mandatory | Description | 4018| ------ | ------ | ---- | ---------------------- | 4019| key | [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Yes | Public key used for signature verification. | 4020 4021**Return value** 4022 4023| Type | Description | 4024| ---- | ------------------------------------------------------------ | 4025| Promise\<void> | Promise used to return the result. | 4026 4027**Error codes** 4028 4029For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4030 4031| ID | Error Message | 4032| -------- | ----------------------- | 4033| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 4034| 19030001 | crypto operation error. | 4035 4036**Example** 4037 4038```ts 4039import { cert } from '@kit.DeviceCertificateKit'; 4040import { cryptoFramework } from '@kit.CryptoArchitectureKit' 4041import { BusinessError } from '@kit.BasicServicesKit'; 4042 4043// Convert the string into a Uint8Array. 4044function stringToUint8Array(str: string): Uint8Array { 4045 let arr: Array<number> = []; 4046 for (let i = 0, j = str.length; i < j; i++) { 4047 arr.push(str.charCodeAt(i)); 4048 } 4049 return new Uint8Array(arr); 4050} 4051 4052let crlData = '-----BEGIN X509 CRL-----\n' + 4053 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4054 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4055 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4056 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4057 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4058 'eavsH0Q3\n' + 4059 '-----END X509 CRL-----\n'; 4060 4061let pubKeyData = new Uint8Array([ 4062 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 4063 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 4064 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 4065 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 4066 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 4067 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 4068 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 4069 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 4070 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 4071 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 4072 0x00, 0x01 4073]); 4074 4075let priKeyData = new Uint8Array([ 4076 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 4077 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x02, 0x61, 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01, 4078 0x00, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 4079 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 4080 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 4081 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 4082 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 4083 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 4084 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 4085 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 4086 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x5A, 0xCF, 0x0F, 4087 0xF5, 0xA6, 0x1C, 0x19, 0x65, 0x8C, 0x94, 0x40, 0xF6, 0x84, 0x28, 0x74, 0x40, 0x42, 0x34, 0xDE, 4088 0xC3, 0x00, 0x5E, 0x72, 0x4D, 0x96, 0xE9, 0x4C, 0xBD, 0xC9, 0xDB, 0x14, 0x9F, 0xD5, 0xBB, 0xA9, 4089 0x0C, 0x20, 0xC2, 0xBE, 0x7A, 0x80, 0x89, 0xEC, 0x99, 0x04, 0xF0, 0xEE, 0x7B, 0x83, 0x20, 0x1D, 4090 0x37, 0x19, 0x55, 0x85, 0xF6, 0x8E, 0x3B, 0xFB, 0x16, 0xF3, 0xD3, 0x6F, 0xEE, 0x73, 0x12, 0x53, 4091 0xCA, 0x77, 0xD7, 0x6C, 0x29, 0xF5, 0x08, 0xA3, 0x09, 0x01, 0x0B, 0x00, 0x05, 0x57, 0xAD, 0x4D, 4092 0xF0, 0x92, 0xB2, 0x5A, 0x8B, 0x19, 0x09, 0x81, 0x86, 0xFE, 0x66, 0xB9, 0x33, 0x88, 0x28, 0xF3, 4093 0x37, 0x73, 0x09, 0x5F, 0xD7, 0xC9, 0xC6, 0xFA, 0x13, 0x74, 0xFE, 0xAE, 0x53, 0xA9, 0x71, 0x67, 4094 0xCE, 0x3A, 0xE6, 0x8D, 0x35, 0xD1, 0xB8, 0xFD, 0x6F, 0x0D, 0x43, 0xC2, 0xD1, 0x02, 0x41, 0x00, 4095 0xF7, 0x33, 0xE5, 0x6C, 0x29, 0x5A, 0x30, 0x58, 0xA4, 0x52, 0x65, 0xA0, 0x39, 0xC2, 0xE8, 0xAE, 4096 0x5F, 0xA3, 0x2D, 0x0C, 0x65, 0xB1, 0x7B, 0xFD, 0x92, 0xBF, 0x47, 0x87, 0x97, 0x40, 0xCB, 0x54, 4097 0xF9, 0xBB, 0x50, 0x27, 0x70, 0x51, 0xD0, 0xD8, 0x48, 0x0D, 0xC6, 0x47, 0x60, 0xF8, 0x4E, 0x0A, 4098 0x32, 0x76, 0x6D, 0xA4, 0xBA, 0x40, 0xE5, 0x58, 0xF8, 0x4A, 0x39, 0x4E, 0xF8, 0x3F, 0x4E, 0x2D, 4099 0x02, 0x41, 0x00, 0xE4, 0x23, 0x2A, 0x5F, 0x59, 0xCF, 0x7C, 0x91, 0x24, 0x0D, 0xA2, 0x44, 0x17, 4100 0xCD, 0x37, 0xDE, 0x1F, 0x53, 0x4D, 0x33, 0x9F, 0x90, 0x4D, 0xD9, 0x72, 0x64, 0x25, 0xBA, 0xAB, 4101 0x47, 0x91, 0xC4, 0x99, 0x95, 0x86, 0xB5, 0x8A, 0xEA, 0x77, 0xF7, 0x64, 0x72, 0x5E, 0xB7, 0xBB, 4102 0x16, 0xA1, 0x64, 0xA4, 0xE1, 0x2D, 0x76, 0x6D, 0xEF, 0xB1, 0x5E, 0xD6, 0x17, 0xE8, 0xAA, 0xB6, 4103 0xA0, 0xD9, 0x85, 0x02, 0x41, 0x00, 0xDF, 0xC8, 0x5B, 0x28, 0x4F, 0x47, 0x15, 0xFD, 0x28, 0xC4, 4104 0x6E, 0xBB, 0x5D, 0x8E, 0xD4, 0x95, 0x06, 0x7E, 0xF1, 0x89, 0x07, 0x86, 0x64, 0x78, 0x69, 0x20, 4105 0x3F, 0xE0, 0xBF, 0x4C, 0x28, 0xC6, 0x04, 0x4D, 0x4D, 0x82, 0x66, 0x6B, 0xAA, 0x64, 0x20, 0xD6, 4106 0x57, 0x68, 0xC6, 0xA0, 0x02, 0x05, 0xB9, 0x28, 0xFC, 0x98, 0xE3, 0x03, 0x5C, 0x9B, 0xEE, 0x29, 4107 0x43, 0x37, 0xFA, 0x03, 0x55, 0x01, 0x02, 0x40, 0x69, 0x5B, 0x7C, 0x24, 0x10, 0xDB, 0xEB, 0x91, 4108 0x33, 0xEF, 0x3F, 0xF2, 0xE6, 0x73, 0x15, 0xCB, 0xF4, 0xF7, 0x89, 0x7D, 0xBF, 0xC0, 0xEA, 0xD2, 4109 0xF3, 0x2B, 0x20, 0xE9, 0x76, 0x54, 0x55, 0x13, 0x50, 0x42, 0x67, 0xB5, 0xCB, 0x73, 0xC0, 0xF7, 4110 0x75, 0x62, 0x04, 0x30, 0x21, 0xAC, 0xAF, 0xD8, 0x44, 0xF4, 0xE1, 0x04, 0x02, 0x7D, 0x61, 0x92, 4111 0x84, 0x99, 0x02, 0x10, 0x64, 0xCB, 0x1F, 0xE9, 0x02, 0x41, 0x00, 0xAB, 0x4B, 0x7D, 0x90, 0x7C, 4112 0x57, 0x08, 0x6B, 0xC0, 0x43, 0x72, 0x09, 0x8A, 0x18, 0x35, 0x36, 0x64, 0x9D, 0x84, 0x8D, 0xF1, 4113 0x84, 0x94, 0x48, 0xC6, 0x80, 0x9D, 0xB9, 0xA2, 0x58, 0x0A, 0x4D, 0x0A, 0xCA, 0x1E, 0xD6, 0x05, 4114 0x55, 0x5B, 0xFE, 0xD7, 0xAA, 0x70, 0xED, 0x76, 0xB3, 0x40, 0x2E, 0xA0, 0xB3, 0x32, 0x37, 0xB0, 4115 0xA0, 0xB9, 0x96, 0x2D, 0xC4, 0x70, 0xE9, 0x99, 0x10, 0x67, 0x8D 4116]); 4117 4118// Binary data of the CRL, which varies with the service. 4119let encodingBlob: cert.EncodingBlob = { 4120 data: stringToUint8Array(crlData), 4121 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4122 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4123}; 4124 4125cert.createX509Crl(encodingBlob).then(x509Crl => { 4126 console.log('createX509Crl success'); 4127 4128 try { 4129 // Generate a public key object. 4130 let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); 4131 console.log('createAsyKeyGenerator success'); 4132 let priEncodingBlob: cryptoFramework.DataBlob = { 4133 data: priKeyData, 4134 }; 4135 let pubEncodingBlob: cryptoFramework.DataBlob = { 4136 data: pubKeyData, 4137 }; 4138 keyGenerator.convertKey(pubEncodingBlob, priEncodingBlob).then((keyPair) => { 4139 console.log('convert key success'); 4140 x509Crl.verify(keyPair.pubKey).then(result => { 4141 console.log('verify success'); 4142 }).catch((error: BusinessError) => { 4143 console.error('verify failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4144 }); 4145 }).catch((error: BusinessError) => { 4146 console.error('convert key failed, message: ' + error.message + 'code: ' + error.code); 4147 }); 4148 } catch (error) { 4149 let e: BusinessError = error as BusinessError; 4150 console.error('get pubKey failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4151 } 4152}).catch((error: BusinessError) => { 4153 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4154}); 4155``` 4156 4157### getVersion<sup>(deprecated)</sup> 4158 4159getVersion() : number 4160 4161Obtains the version of the X.509 CRL. 4162 4163> **NOTE** 4164> 4165> This API is deprecated since API version 11. Use [X509CRL.getVersion](#getversion11) instead. 4166 4167**System capability**: SystemCapability.Security.Cert 4168 4169**Return value** 4170 4171| Type | Description | 4172| ------ | -------------------------------- | 4173| number | Version of the X.509 CRL obtained. | 4174 4175**Example** 4176 4177```ts 4178import { cert } from '@kit.DeviceCertificateKit'; 4179 4180// Convert the string into a Uint8Array. 4181function stringToUint8Array(str: string): Uint8Array { 4182 let arr: Array<number> = []; 4183 for (let i = 0, j = str.length; i < j; i++) { 4184 arr.push(str.charCodeAt(i)); 4185 } 4186 return new Uint8Array(arr); 4187} 4188 4189let crlData = '-----BEGIN X509 CRL-----\n' + 4190 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4191 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4192 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4193 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4194 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4195 'eavsH0Q3\n' + 4196 '-----END X509 CRL-----\n'; 4197 4198// Binary data of the CRL, which varies with the service. 4199let encodingBlob: cert.EncodingBlob = { 4200 data: stringToUint8Array(crlData), 4201 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4202 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4203}; 4204 4205cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4206 if (error) { 4207 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4208 } else { 4209 console.log('createX509Crl success'); 4210 let version = x509Crl.getVersion(); 4211 } 4212}); 4213``` 4214 4215### getIssuerName<sup>(deprecated)</sup> 4216 4217getIssuerName() : DataBlob 4218 4219Obtains the issuer of the X.509 CRL. 4220 4221> **NOTE** 4222> 4223> This API is deprecated since API version 11. Use [X509CRL.getIssuerName](#getissuername11) instead. 4224 4225**System capability**: SystemCapability.Security.Cert 4226 4227**Return value** 4228 4229| Type | Description | 4230| --------------------- | ------------------------------ | 4231| [DataBlob](#datablob) | Issuer of the X.509 CRL obtained. | 4232 4233**Error codes** 4234 4235For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4236 4237| ID | Error Message | 4238| -------- | ----------------------- | 4239| 19020001 | memory error. | 4240| 19020002 | runtime error. | 4241| 19030001 | crypto operation error. | 4242 4243**Example** 4244 4245```ts 4246import { cert } from '@kit.DeviceCertificateKit'; 4247import { BusinessError } from '@kit.BasicServicesKit'; 4248 4249// Convert the string into a Uint8Array. 4250function stringToUint8Array(str: string): Uint8Array { 4251 let arr: Array<number> = []; 4252 for (let i = 0, j = str.length; i < j; i++) { 4253 arr.push(str.charCodeAt(i)); 4254 } 4255 return new Uint8Array(arr); 4256} 4257 4258let crlData = '-----BEGIN X509 CRL-----\n' + 4259 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4260 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4261 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4262 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4263 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4264 'eavsH0Q3\n' + 4265 '-----END X509 CRL-----\n'; 4266 4267// Binary data of the CRL, which varies with the service. 4268let encodingBlob: cert.EncodingBlob = { 4269 data: stringToUint8Array(crlData), 4270 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4271 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4272}; 4273 4274cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4275 if (error) { 4276 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4277 } else { 4278 console.log('createX509Crl success'); 4279 try { 4280 let issuerName = x509Crl.getIssuerName(); 4281 } catch (err) { 4282 let e: BusinessError = err as BusinessError; 4283 console.error('getIssuerName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4284 } 4285 } 4286}); 4287``` 4288 4289### getLastUpdate<sup>(deprecated)</sup> 4290 4291getLastUpdate() : string 4292 4293Obtains the last update date of this X.509 CRL. 4294 4295> **NOTE** 4296> 4297> This API is deprecated since API version 11. Use [X509CRL.getLastUpdate](#getlastupdate11) instead. 4298 4299**System capability**: SystemCapability.Security.Cert 4300 4301**Return value** 4302 4303| Type | Description | 4304| ------ | ------------------------------------ | 4305| string | Last update date of the X.509 CRL obtained, in ASN.1 format.| 4306 4307**Error codes** 4308 4309For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4310 4311| ID | Error Message | 4312| -------- | ----------------------- | 4313| 19020001 | memory error. | 4314| 19020002 | runtime error. | 4315| 19030001 | crypto operation error. | 4316 4317**Example** 4318 4319```ts 4320import { cert } from '@kit.DeviceCertificateKit'; 4321import { BusinessError } from '@kit.BasicServicesKit'; 4322 4323// Convert the string into a Uint8Array. 4324function stringToUint8Array(str: string): Uint8Array { 4325 let arr: Array<number> = []; 4326 for (let i = 0, j = str.length; i < j; i++) { 4327 arr.push(str.charCodeAt(i)); 4328 } 4329 return new Uint8Array(arr); 4330} 4331 4332let crlData = '-----BEGIN X509 CRL-----\n' + 4333 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4334 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4335 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4336 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4337 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4338 'eavsH0Q3\n' + 4339 '-----END X509 CRL-----\n'; 4340 4341// Binary data of the CRL, which varies with the service. 4342let encodingBlob: cert.EncodingBlob = { 4343 data: stringToUint8Array(crlData), 4344 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4345 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4346}; 4347 4348cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4349 if (error) { 4350 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4351 } else { 4352 console.log('createX509Crl success'); 4353 try { 4354 let lastUpdate = x509Crl.getLastUpdate(); 4355 } catch (err) { 4356 let e: BusinessError = err as BusinessError; 4357 console.error('getLastUpdate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4358 } 4359 } 4360}); 4361``` 4362 4363### getNextUpdate<sup>(deprecated)</sup> 4364 4365getNextUpdate() : string 4366 4367Obtains the next update date of this CRL. 4368 4369> **NOTE** 4370> 4371> This API is deprecated since API version 11. Use [X509CRL.getNextUpdate](#getnextupdate11) instead. 4372 4373**System capability**: SystemCapability.Security.Cert 4374 4375**Return value** 4376 4377| Type | Description | 4378| ------ | ------------------------------------ | 4379| string | Next update date of the CRL obtained, in ASN.1 format.| 4380 4381**Error codes** 4382 4383For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4384 4385| ID | Error Message | 4386| -------- | ----------------------- | 4387| 19020001 | memory error. | 4388| 19020002 | runtime error. | 4389| 19030001 | crypto operation error. | 4390 4391**Example** 4392 4393```ts 4394import { cert } from '@kit.DeviceCertificateKit'; 4395import { BusinessError } from '@kit.BasicServicesKit'; 4396 4397// Convert the string into a Uint8Array. 4398function stringToUint8Array(str: string): Uint8Array { 4399 let arr: Array<number> = []; 4400 for (let i = 0, j = str.length; i < j; i++) { 4401 arr.push(str.charCodeAt(i)); 4402 } 4403 return new Uint8Array(arr); 4404} 4405 4406let crlData = '-----BEGIN X509 CRL-----\n' + 4407 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4408 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4409 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4410 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4411 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4412 'eavsH0Q3\n' + 4413 '-----END X509 CRL-----\n'; 4414 4415// Binary data of the CRL, which varies with the service. 4416let encodingBlob: cert.EncodingBlob = { 4417 data: stringToUint8Array(crlData), 4418 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4419 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4420}; 4421 4422cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4423 if (error) { 4424 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4425 } else { 4426 console.log('createX509Crl success'); 4427 try { 4428 let nextUpdate = x509Crl.getNextUpdate(); 4429 } catch (err) { 4430 let e: BusinessError = err as BusinessError; 4431 console.error('getNextUpdate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4432 } 4433 } 4434}); 4435``` 4436 4437### getRevokedCert<sup>(deprecated)</sup> 4438 4439getRevokedCert(serialNumber : number) : X509CrlEntry 4440 4441Obtains the revoked X.509 certificate based on the specified serial number of the certificate. 4442 4443> **NOTE** 4444> 4445> This API is deprecated since API version 11. Use [X509CRL.getRevokedCert](#getrevokedcert11) instead. 4446 4447**System capability**: SystemCapability.Security.Cert 4448 4449**Parameters** 4450 4451| Name | Type | Mandatory | Description | 4452| ------------ | ------ | ---- | -------------- | 4453| serialNumber | number | Yes | Serial number of the certificate. | 4454 4455**Return value** 4456 4457| Type | Description | 4458| ---------------------- | --------------------- | 4459| [X509CrlEntry](#x509crlentrydeprecated) | Revoked X.509 certificate obtained. | 4460 4461**Error codes** 4462 4463For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4464 4465| ID | Error Message | 4466| -------- | ----------------------- | 4467| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 4468| 19020001 | memory error. | 4469| 19030001 | crypto operation error. | 4470 4471**Example** 4472 4473```ts 4474import { cert } from '@kit.DeviceCertificateKit'; 4475import { BusinessError } from '@kit.BasicServicesKit'; 4476 4477// Convert the string into a Uint8Array. 4478function stringToUint8Array(str: string): Uint8Array { 4479 let arr: Array<number> = []; 4480 for (let i = 0, j = str.length; i < j; i++) { 4481 arr.push(str.charCodeAt(i)); 4482 } 4483 return new Uint8Array(arr); 4484} 4485 4486let crlData = '-----BEGIN X509 CRL-----\n' + 4487 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4488 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4489 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4490 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4491 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4492 'eavsH0Q3\n' + 4493 '-----END X509 CRL-----\n'; 4494 4495// Binary data of the CRL, which varies with the service. 4496let encodingBlob: cert.EncodingBlob = { 4497 data: stringToUint8Array(crlData), 4498 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4499 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4500}; 4501 4502cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4503 if (error) { 4504 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4505 } else { 4506 console.log('createX509Crl success'); 4507 let serialNumber = 1000; 4508 try { 4509 let entry = x509Crl.getRevokedCert(serialNumber); 4510 } catch (error) { 4511 let e: BusinessError = error as BusinessError; 4512 console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4513 } 4514 } 4515}); 4516``` 4517 4518### getRevokedCertWithCert<sup>(deprecated)</sup> 4519 4520getRevokedCertWithCert(cert : X509Cert) : X509CrlEntry 4521 4522Obtains the revoked X.509 certificate based on the specified certificate. 4523 4524> **NOTE** 4525> 4526> This API is deprecated since API version 11. Use [X509CRL.getRevokedCertWithCert](#getrevokedcertwithcert11) instead. 4527 4528**System capability**: SystemCapability.Security.Cert 4529 4530**Parameters** 4531 4532| Name | Type | Mandatory | Description | 4533| ------ | --------------------- | ---- | ------------ | 4534| cert | [X509Cert](#x509cert) | Yes | Certificate based on which the revoked certificate is obtained. | 4535 4536**Return value** 4537 4538| Type | Description | 4539| ------------ | -------------------- | 4540| [X509CrlEntry](#x509crlentrydeprecated) | Revoked X.509 certificate obtained. | 4541 4542**Error codes** 4543 4544For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4545 4546| ID | Error Message | 4547| -------- | ----------------------- | 4548| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 4549| 19020001 | memory error. | 4550| 19030001 | crypto operation error. | 4551 4552**Example** 4553 4554```ts 4555import { cert } from '@kit.DeviceCertificateKit'; 4556import { BusinessError } from '@kit.BasicServicesKit'; 4557 4558// Convert the string into a Uint8Array. 4559function stringToUint8Array(str: string): Uint8Array { 4560 let arr: Array<number> = []; 4561 for (let i = 0, j = str.length; i < j; i++) { 4562 arr.push(str.charCodeAt(i)); 4563 } 4564 return new Uint8Array(arr); 4565} 4566 4567let crlData = '-----BEGIN X509 CRL-----\n' + 4568 'MIIBjjB4AgEBMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNVBAMMB1Jvb3QgQ0EXDTI0\n' + 4569 'MDMxOTAyMDQwN1oXDTI0MDQxODAyMDQwN1owIjAgAgEEFw0yNDAzMTkwMjA0MDZa\n' + 4570 'MAwwCgYDVR0VBAMKAQGgDjAMMAoGA1UdFAQDAgEAMA0GCSqGSIb3DQEBCwUAA4IB\n' + 4571 'AQCbjvmHxC8dW6WCS/ga73kx2b7f8I/2eVuDYyReuBiGWeJ9vDmGqimJ9VwOk+ph\n' + 4572 'LvG/2Zvh9I8qXxnOWeseA2C0bEshJGvXpquIjm00OUyLlK6jdfRbhXT8OyvDjqZs\n' + 4573 'e1IsMV7Zo11SUc8nR2d0QQ7EVDCN/XFKPsmoK7PhJnRh5gc8W3FKQ6b8H9kdjgTa\n' + 4574 'KQUap1OIDReVsjPBmRAbwMMLtbrAMllF7E6x7uHgHTGaK1ZPJDtsnCJ45ur3mk/o\n' + 4575 'HAJFwHNjNDltiEfvMSs76/X0cwitpeW4dFk6c3QtqhxJrHDD4gl8di+xHOyHXpzX\n' + 4576 '+i2osvdPWRia0dJCL1PCA14k\n' + 4577 '-----END X509 CRL-----\n'; 4578 4579// Certificate binary data, which varies with the service. 4580let certData = '-----BEGIN CERTIFICATE-----\n' + 4581 'MIIDTjCCAjagAwIBAgIBBDANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 4582 'IENBMB4XDTI0MDMxOTAyMDQwMVoXDTM0MDMxNzAyMDQwMVowEjEQMA4GA1UEAwwH\n' + 4583 'ZGV2aWNlMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMIXL3e7UE/c\n' + 4584 'Z1dPVgRZ5L8gsQ/azuYVBvoFf7o8ksYrL7G1+qZIJjVRqZkuTirLW4GicbkIkPNW\n' + 4585 'eix5cDhkjkC+q5SBCOrSSTTlvX3xcOY1gMlA5MgeBfGixFusq4d5VPF2KceZ20/a\n' + 4586 'ygwGD0Uv0X81OERyPom/dYdJUvfaD9ifPFJ1fKIj/cPFG3yJK/ojpEfndZNdESQL\n' + 4587 'TkoDekilg2UGOLtY6fb9Ns37ncuIj33gCS/R9m1tgtmqCTcgOQ4hwKhjVF3InmPO\n' + 4588 '2BbWKvD1RUX+rHC2a2HHDQILOOtDTy8dHvE+qZlK0efrpRgoFEERJAGPi1GDGWiA\n' + 4589 '7UX1c4MCxIECAwEAAaOBrjCBqzAJBgNVHRMEAjAAMB0GA1UdDgQWBBQbkAcMT7ND\n' + 4590 'fGp3VPFzYHppZ1zxLTAfBgNVHSMEGDAWgBR0W/koCbvDtFGHUQZLM3j6HKsW2DAd\n' + 4591 'BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwCwYDVR0PBAQDAgeAMDIGCCsG\n' + 4592 'AQUFBwEBBCYwJDAiBggrBgEFBQcwAYYWaHR0cHM6Ly8xMjcuMC4wLjE6OTk5OTAN\n' + 4593 'BgkqhkiG9w0BAQsFAAOCAQEAF1OTzTmbklFOdZCxrF3zg9owUPJR5RB+PbuBlUfI\n' + 4594 '8tkGXkMltQ8PN1dv6Cq+d8BluiJdWEzqVoJa/e5SHHJyYQSOhlurRG0GBXllVQ1I\n' + 4595 'n1PFaI40+9X2X6wrEcdC5nbzogR1jSiksCiTcARMddj0Xrp5FMrFaaGY8M/xqzdW\n' + 4596 'LTDl4nfbuxtA71cIjnE4kOcaemly9/S2wYWdPktsPxQPY1nPUOeJFI7o0sH3rK0c\n' + 4597 'JSqtgAG8vnjK+jbx9RpkgqCsXgUbIahL573VTgxrNrsRjCuVal7XVxl/xOKXr6Er\n' + 4598 'Gpc+OCrXbHNZkUQE5fZH3yL2tXd7EASEb6J3aEWHfF8YBA==\n' + 4599 '-----END CERTIFICATE-----\n'; 4600 4601let certEncodingBlob: cert.EncodingBlob = { 4602 data: stringToUint8Array(certData), 4603 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4604 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4605}; 4606 4607// Binary data of the CRL, which varies with the service. 4608let encodingBlob: cert.EncodingBlob = { 4609 data: stringToUint8Array(crlData), 4610 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4611 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4612}; 4613 4614cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4615 if (error) { 4616 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4617 } else { 4618 console.log('createX509Crl success'); 4619 // Create an X.509 certificate object. 4620 cert.createX509Cert(certEncodingBlob).then((x509Cert) => { 4621 try { 4622 let entry = x509Crl.getRevokedCertWithCert(x509Cert); 4623 console.log('getRevokedCertWithCert success'); 4624 } catch (error) { 4625 let e: BusinessError = error as BusinessError; 4626 console.error('getRevokedCertWithCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4627 } 4628 }).catch((error: BusinessError) => { 4629 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4630 }) 4631 } 4632}); 4633``` 4634 4635### getRevokedCerts<sup>(deprecated)</sup> 4636 4637getRevokedCerts(callback : AsyncCallback<Array\<X509CrlEntry>>) : void 4638 4639Obtains the revoked X.509 certificates. This API uses an asynchronous callback to return the result. 4640 4641> **NOTE** 4642> 4643> This API is deprecated since API version 11. Use [X509CRL.getRevokedCerts](#getrevokedcerts11) instead. 4644 4645**System capability**: SystemCapability.Security.Cert 4646 4647**Parameters** 4648 4649| Name | Type | Mandatory | Description | 4650| -------- | ---------------------------------------------------- | ---- | -------------------------------- | 4651| callback | AsyncCallback<Array\<[X509CrlEntry](#x509crlentrydeprecated)>> | Yes | Callback used to return a list of revoked X.509 certificates. | 4652 4653**Error codes** 4654 4655For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4656 4657| ID | Error Message | 4658| -------- | ----------------------- | 4659| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 4660| 19020001 | memory error. | 4661| 19030001 | crypto operation error. | 4662 4663**Example** 4664 4665```ts 4666import { cert } from '@kit.DeviceCertificateKit'; 4667import { BusinessError } from '@kit.BasicServicesKit'; 4668 4669// Convert the string into a Uint8Array. 4670function stringToUint8Array(str: string): Uint8Array { 4671 let arr: Array<number> = []; 4672 for (let i = 0, j = str.length; i < j; i++) { 4673 arr.push(str.charCodeAt(i)); 4674 } 4675 return new Uint8Array(arr); 4676} 4677 4678let crlData = '-----BEGIN X509 CRL-----\n' + 4679 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4680 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4681 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4682 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4683 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4684 'eavsH0Q3\n' + 4685 '-----END X509 CRL-----\n'; 4686 4687// Binary data of the CRL, which varies with the service. 4688let encodingBlob: cert.EncodingBlob = { 4689 data: stringToUint8Array(crlData), 4690 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4691 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4692}; 4693 4694cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4695 if (error) { 4696 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4697 } else { 4698 console.log('createX509Crl success'); 4699 x509Crl.getRevokedCerts((error, array) => { 4700 if (error) { 4701 console.error('getRevokedCerts failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4702 } else { 4703 console.log('getRevokedCerts success'); 4704 } 4705 }); 4706 } 4707}); 4708``` 4709 4710### getRevokedCerts<sup>(deprecated)</sup> 4711 4712getRevokedCerts() : Promise<Array\<X509CrlEntry>> 4713 4714Obtains the revoked X.509 certificates. This API uses a promise to return the result. 4715 4716> **NOTE** 4717> 4718> This API is deprecated since API version 11. Use [X509CRL.getRevokedCerts](#getrevokedcerts11-1) instead. 4719 4720**System capability**: SystemCapability.Security.Cert 4721 4722**Return value** 4723 4724| Type | Description | 4725| ---------------------------------------------- | ---------------------- | 4726| Promise<Array\<[X509CrlEntry](#x509crlentrydeprecated)>> | Promise used to return a list of revoked X.509 certificates. | 4727 4728**Error codes** 4729 4730For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4731 4732| ID | Error Message | 4733| -------- | ----------------------- | 4734| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 4735| 19020001 | memory error. | 4736| 19030001 | crypto operation error. | 4737 4738**Example** 4739 4740```ts 4741import { cert } from '@kit.DeviceCertificateKit'; 4742import { BusinessError } from '@kit.BasicServicesKit'; 4743 4744// Convert the string into a Uint8Array. 4745function stringToUint8Array(str: string): Uint8Array { 4746 let arr: Array<number> = []; 4747 for (let i = 0, j = str.length; i < j; i++) { 4748 arr.push(str.charCodeAt(i)); 4749 } 4750 return new Uint8Array(arr); 4751} 4752 4753let crlData = '-----BEGIN X509 CRL-----\n' + 4754 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4755 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4756 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4757 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4758 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4759 'eavsH0Q3\n' + 4760 '-----END X509 CRL-----\n'; 4761 4762// Binary data of the CRL, which varies with the service. 4763let encodingBlob: cert.EncodingBlob = { 4764 data: stringToUint8Array(crlData), 4765 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4766 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4767}; 4768 4769cert.createX509Crl(encodingBlob).then(x509Crl => { 4770 console.log('createX509Crl success'); 4771 x509Crl.getRevokedCerts().then(array => { 4772 console.log('getRevokedCerts success'); 4773 }).catch((error: BusinessError) => { 4774 console.error('getRevokedCerts failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4775 }); 4776}).catch((error: BusinessError) => { 4777 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4778}); 4779``` 4780 4781### getTbsInfo<sup>(deprecated)</sup> 4782 4783getTbsInfo() : DataBlob 4784 4785Obtains the DER-encoded CRL information, that is, **tbsCertList** from this CRL. 4786 4787> **NOTE** 4788> 4789> This API is deprecated since API version 11. Use [X509CRL.getTBSInfo](#gettbsinfo11) instead. 4790 4791**System capability**: SystemCapability.Security.Cert 4792 4793**Return value** 4794 4795| Type | Description | 4796| --------------------- | ------------------------------- | 4797| [DataBlob](#datablob) | **tbsCertList** information obtained. | 4798 4799**Error codes** 4800 4801For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4802 4803| ID | Error Message | 4804| -------- | ----------------------- | 4805| 19020001 | memory error. | 4806| 19020002 | runtime error. | 4807| 19030001 | crypto operation error. | 4808 4809**Example** 4810 4811```ts 4812import { cert } from '@kit.DeviceCertificateKit'; 4813import { BusinessError } from '@kit.BasicServicesKit'; 4814 4815// Convert the string into a Uint8Array. 4816function stringToUint8Array(str: string): Uint8Array { 4817 let arr: Array<number> = []; 4818 for (let i = 0, j = str.length; i < j; i++) { 4819 arr.push(str.charCodeAt(i)); 4820 } 4821 return new Uint8Array(arr); 4822} 4823 4824let crlData = '-----BEGIN X509 CRL-----\n' + 4825 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4826 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4827 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4828 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4829 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4830 'eavsH0Q3\n' + 4831 '-----END X509 CRL-----\n'; 4832 4833// Binary data of the CRL, which varies with the service. 4834let encodingBlob: cert.EncodingBlob = { 4835 data: stringToUint8Array(crlData), 4836 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4837 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4838}; 4839 4840cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4841 if (error) { 4842 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4843 } else { 4844 console.log('createX509Crl success'); 4845 try { 4846 let tbsInfo = x509Crl.getTbsInfo(); 4847 } catch (error) { 4848 let e: BusinessError = error as BusinessError; 4849 console.error('getTbsInfo failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4850 } 4851 } 4852}); 4853``` 4854 4855### getSignature<sup>(deprecated)</sup> 4856 4857getSignature() : DataBlob 4858 4859Obtains the signature data of the X.509 CRL. 4860 4861> **NOTE** 4862> 4863> This API is deprecated since API version 11. Use [X509CRL.getSignature](#getsignature11) instead. 4864 4865**System capability**: SystemCapability.Security.Cert 4866 4867**Return value** 4868 4869| Type | Description | 4870| --------------------- | ------------------------------ | 4871| [DataBlob](#datablob) | Signature data of the X.509 CRL obtained. | 4872 4873**Error codes** 4874 4875For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4876 4877| ID | Error Message | 4878| -------- | ----------------------- | 4879| 19020001 | memory error. | 4880| 19020002 | runtime error. | 4881| 19030001 | crypto operation error. | 4882 4883**Example** 4884 4885```ts 4886import { cert } from '@kit.DeviceCertificateKit'; 4887import { BusinessError } from '@kit.BasicServicesKit'; 4888 4889// Convert the string into a Uint8Array. 4890function stringToUint8Array(str: string): Uint8Array { 4891 let arr: Array<number> = []; 4892 for (let i = 0, j = str.length; i < j; i++) { 4893 arr.push(str.charCodeAt(i)); 4894 } 4895 return new Uint8Array(arr); 4896} 4897 4898let crlData = '-----BEGIN X509 CRL-----\n' + 4899 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4900 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4901 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4902 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4903 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4904 'eavsH0Q3\n' + 4905 '-----END X509 CRL-----\n'; 4906 4907// Binary data of the CRL, which varies with the service. 4908let encodingBlob: cert.EncodingBlob = { 4909 data: stringToUint8Array(crlData), 4910 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4911 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4912}; 4913 4914cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4915 if (error) { 4916 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4917 } else { 4918 console.log('createX509Crl success'); 4919 try { 4920 let signature = x509Crl.getSignature(); 4921 } catch (err) { 4922 let e: BusinessError = err as BusinessError; 4923 console.error('getSignature failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4924 } 4925 } 4926}); 4927``` 4928 4929### getSignatureAlgName<sup>(deprecated)</sup> 4930 4931getSignatureAlgName() : string 4932 4933Obtains the signing algorithm of the X.509 CRL. 4934 4935> **NOTE** 4936> 4937> This API is deprecated since API version 11. Use [X509CRL.getSignatureAlgName](#getsignaturealgname11) instead. 4938 4939**System capability**: SystemCapability.Security.Cert 4940 4941**Return value** 4942 4943| Type | Description | 4944| ------ | -------------------------------- | 4945| string | Signing algorithm obtained. | 4946 4947**Error codes** 4948 4949For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 4950 4951| ID | Error Message | 4952| -------- | ----------------------- | 4953| 19020001 | memory error. | 4954| 19020002 | runtime error. | 4955| 19030001 | crypto operation error. | 4956 4957**Example** 4958 4959```ts 4960import { cert } from '@kit.DeviceCertificateKit'; 4961import { BusinessError } from '@kit.BasicServicesKit'; 4962 4963// Convert the string into a Uint8Array. 4964function stringToUint8Array(str: string): Uint8Array { 4965 let arr: Array<number> = []; 4966 for (let i = 0, j = str.length; i < j; i++) { 4967 arr.push(str.charCodeAt(i)); 4968 } 4969 return new Uint8Array(arr); 4970} 4971 4972let crlData = '-----BEGIN X509 CRL-----\n' + 4973 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 4974 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 4975 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 4976 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 4977 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 4978 'eavsH0Q3\n' + 4979 '-----END X509 CRL-----\n'; 4980 4981// Binary data of the CRL, which varies with the service. 4982let encodingBlob: cert.EncodingBlob = { 4983 data: stringToUint8Array(crlData), 4984 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 4985 encodingFormat: cert.EncodingFormat.FORMAT_PEM 4986}; 4987 4988cert.createX509Crl(encodingBlob, (error, x509Crl) => { 4989 if (error) { 4990 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 4991 } else { 4992 console.log('createX509Crl success'); 4993 try { 4994 let sigAlgName = x509Crl.getSignatureAlgName(); 4995 } catch (err) { 4996 let e: BusinessError = err as BusinessError; 4997 console.error('getSignatureAlgName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 4998 } 4999 } 5000}); 5001``` 5002 5003### getSignatureAlgOid<sup>(deprecated)</sup> 5004 5005getSignatureAlgOid() : string 5006 5007Obtains the OID of the X.509 CRL signing algorithm. OIDs are allocated by the International Organization for Standardization (ISO). 5008 5009> **NOTE** 5010> 5011> This API is deprecated since API version 11. Use [X509CRL.getSignatureAlgOid](#getsignaturealgoid11) instead. 5012 5013**System capability**: SystemCapability.Security.Cert 5014 5015**Return value** 5016 5017| Type | Description | 5018| ------ | --------------------------------------------- | 5019| string | OID of the X.509 CRL signing algorithm obtained. | 5020 5021**Error codes** 5022 5023For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5024 5025| ID | Error Message | 5026| -------- | ----------------------- | 5027| 19020001 | memory error. | 5028| 19020002 | runtime error. | 5029| 19030001 | crypto operation error. | 5030 5031**Example** 5032 5033```ts 5034import { cert } from '@kit.DeviceCertificateKit'; 5035import { BusinessError } from '@kit.BasicServicesKit'; 5036 5037// Convert the string into a Uint8Array. 5038function stringToUint8Array(str: string): Uint8Array { 5039 let arr: Array<number> = []; 5040 for (let i = 0, j = str.length; i < j; i++) { 5041 arr.push(str.charCodeAt(i)); 5042 } 5043 return new Uint8Array(arr); 5044} 5045 5046let crlData = '-----BEGIN X509 CRL-----\n' + 5047 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5048 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5049 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5050 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5051 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5052 'eavsH0Q3\n' + 5053 '-----END X509 CRL-----\n'; 5054 5055// Binary data of the CRL, which varies with the service. 5056let encodingBlob: cert.EncodingBlob = { 5057 data: stringToUint8Array(crlData), 5058 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5059 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5060}; 5061 5062cert.createX509Crl(encodingBlob, (error, x509Crl) => { 5063 if (error) { 5064 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5065 } else { 5066 console.log('createX509Crl success'); 5067 try { 5068 let sigAlgOid = x509Crl.getSignatureAlgOid(); 5069 } catch (err) { 5070 let e: BusinessError = err as BusinessError; 5071 console.error('getSignatureAlgOid failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5072 } 5073 } 5074}); 5075``` 5076 5077### getSignatureAlgParams<sup>(deprecated)</sup> 5078 5079getSignatureAlgParams() : DataBlob 5080 5081Obtains the parameters of the X.509 CRL signing algorithm. 5082 5083> **NOTE** 5084> 5085> This API is deprecated since API version 11. Use [X509CRL.getSignatureAlgParams](#getsignaturealgparams11) instead. 5086 5087**System capability**: SystemCapability.Security.Cert 5088 5089**Return value** 5090 5091| Type | Description | 5092| --------------------- | ---------------------------------- | 5093| [DataBlob](#datablob) | Algorithm parameters obtained. | 5094 5095**Error codes** 5096 5097For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5098 5099| ID | Error Message | 5100| -------- | ----------------------- | 5101| 801 | this operation is not supported. | 5102| 19020001 | memory error. | 5103| 19020002 | runtime error. | 5104| 19030001 | crypto operation error. | 5105 5106**Example** 5107 5108```ts 5109import { cert } from '@kit.DeviceCertificateKit'; 5110import { BusinessError } from '@kit.BasicServicesKit'; 5111 5112// Convert the string into a Uint8Array. 5113function stringToUint8Array(str: string): Uint8Array { 5114 let arr: Array<number> = []; 5115 for (let i = 0, j = str.length; i < j; i++) { 5116 arr.push(str.charCodeAt(i)); 5117 } 5118 return new Uint8Array(arr); 5119} 5120 5121let crlData = '-----BEGIN X509 CRL-----\n' + 5122 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5123 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5124 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5125 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5126 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5127 'eavsH0Q3\n' + 5128 '-----END X509 CRL-----\n'; 5129 5130// Binary data of the CRL, which varies with the service. 5131let encodingBlob: cert.EncodingBlob = { 5132 data: stringToUint8Array(crlData), 5133 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5134 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5135}; 5136 5137cert.createX509Crl(encodingBlob, (error, x509Crl) => { 5138 if (error) { 5139 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5140 } else { 5141 console.log('createX509Crl success'); 5142 try { 5143 let sigAlgParams = x509Crl.getSignatureAlgParams(); 5144 } catch (err) { 5145 let e: BusinessError = err as BusinessError; 5146 console.error('getSignatureAlgParams failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5147 } 5148 } 5149}); 5150``` 5151## X509CRL<sup>11+</sup> 5152 5153Provides APIs for managing a CRL object. 5154 5155### isRevoked<sup>11+</sup> 5156 5157isRevoked(cert : X509Cert) : boolean 5158 5159Checks whether an X.509 certificate is revoked. 5160 5161**Atomic service API**: This API can be used in atomic services since API version 12. 5162 5163**System capability**: SystemCapability.Security.Cert 5164 5165**Parameters** 5166 5167| Name | Type | Mandatory | Description | 5168| ------ | -------- | ---- | -------------------- | 5169| cert | [X509Cert](#x509cert) | Yes | X.509 certificate to check. | 5170 5171**Return value** 5172 5173| Type | Description | 5174| ------- | ------------------------------------------------- | 5175| boolean | Returns **true** if the certificate is revoked; returns **false** otherwise. | 5176 5177**Error codes** 5178 5179For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5180 5181| ID | Error Message | 5182| -------- | ----------------------- | 5183| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 5184 5185**Example** 5186 5187```ts 5188import { cert } from '@kit.DeviceCertificateKit'; 5189import { BusinessError } from '@kit.BasicServicesKit'; 5190 5191// Convert the string into a Uint8Array. 5192function stringToUint8Array(str: string): Uint8Array { 5193 let arr: Array<number> = []; 5194 for (let i = 0, j = str.length; i < j; i++) { 5195 arr.push(str.charCodeAt(i)); 5196 } 5197 return new Uint8Array(arr); 5198} 5199 5200let crlData = '-----BEGIN X509 CRL-----\n' + 5201 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5202 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5203 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5204 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5205 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5206 'eavsH0Q3\n' + 5207 '-----END X509 CRL-----\n'; 5208 5209let certData = '-----BEGIN CERTIFICATE-----\n' + 5210 'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' + 5211 'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' + 5212 'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' + 5213 'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' + 5214 'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' + 5215 '0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' + 5216 'BetUokslUfjT6+s/X4ByaxycAA==\n' + 5217 '-----END CERTIFICATE-----\n'; 5218 5219// Binary data of the CRL, which varies with the service. 5220let encodingBlob: cert.EncodingBlob = { 5221 data: stringToUint8Array(crlData), 5222 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5223 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5224}; 5225 5226let certEncodingBlob: cert.EncodingBlob = { 5227 data: stringToUint8Array(certData), 5228 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5229 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5230}; 5231 5232cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5233 if (error) { 5234 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5235 } else { 5236 console.log('createX509CRL success'); 5237 // Create an X509Cert instance. 5238 cert.createX509Cert(certEncodingBlob, (error, x509Cert) => { 5239 if (error) { 5240 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5241 } else { 5242 try { 5243 let revokedFlag = x509CRL.isRevoked(x509Cert); 5244 } catch (error) { 5245 let e: BusinessError = error as BusinessError; 5246 console.error('isRevoked failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5247 } 5248 } 5249 }); 5250 } 5251}); 5252``` 5253 5254### getType<sup>11+</sup> 5255 5256getType() : string 5257 5258Obtains the CRL type. 5259 5260**Atomic service API**: This API can be used in atomic services since API version 12. 5261 5262**System capability**: SystemCapability.Security.Cert 5263 5264**Return value** 5265 5266| Type | Description | 5267| ------ | -------------------- | 5268| string | CRL type obtained. | 5269 5270**Example** 5271 5272```ts 5273import { cert } from '@kit.DeviceCertificateKit'; 5274 5275// Convert the string into a Uint8Array. 5276function stringToUint8Array(str: string): Uint8Array { 5277 let arr: Array<number> = []; 5278 for (let i = 0, j = str.length; i < j; i++) { 5279 arr.push(str.charCodeAt(i)); 5280 } 5281 return new Uint8Array(arr); 5282} 5283 5284let crlData = '-----BEGIN X509 CRL-----\n' + 5285 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5286 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5287 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5288 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5289 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5290 'eavsH0Q3\n' + 5291 '-----END X509 CRL-----\n'; 5292 5293// Binary data of the CRL, which varies with the service. 5294let encodingBlob: cert.EncodingBlob = { 5295 data: stringToUint8Array(crlData), 5296 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5297 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5298}; 5299 5300cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5301 if (error) { 5302 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5303 } else { 5304 console.log('createX509CRL success'); 5305 let type = x509CRL.getType(); 5306 } 5307}); 5308``` 5309 5310### getEncoded<sup>11+</sup> 5311 5312getEncoded(callback : AsyncCallback\<EncodingBlob>) : void 5313 5314Obtains the serialized X.509 CRL data. This API uses an asynchronous callback to return the result. 5315 5316**Atomic service API**: This API can be used in atomic services since API version 12. 5317 5318**System capability**: SystemCapability.Security.Cert 5319 5320**Parameters** 5321 5322| Name | Type | Mandatory | Description | 5323| -------- | --------------------------------------------- | ---- | ------------------------------------------ | 5324| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback used to return the serialized X.509 CRL data obtained. | 5325 5326**Error codes** 5327 5328For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5329 5330| ID | Error Message | 5331| -------- | ----------------------- | 5332| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 5333| 19020001 | memory error. | 5334| 19020002 | runtime error. | 5335| 19030001 | crypto operation error. | 5336 5337**Example** 5338 5339```ts 5340import { cert } from '@kit.DeviceCertificateKit'; 5341 5342// Convert the string into a Uint8Array. 5343function stringToUint8Array(str: string): Uint8Array { 5344 let arr: Array<number> = []; 5345 for (let i = 0, j = str.length; i < j; i++) { 5346 arr.push(str.charCodeAt(i)); 5347 } 5348 return new Uint8Array(arr); 5349} 5350 5351let crlData = '-----BEGIN X509 CRL-----\n' + 5352 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5353 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5354 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5355 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5356 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5357 'eavsH0Q3\n' + 5358 '-----END X509 CRL-----\n'; 5359 5360// Binary data of the CRL, which varies with the service. 5361let encodingBlob: cert.EncodingBlob = { 5362 data: stringToUint8Array(crlData), 5363 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5364 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5365}; 5366 5367cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5368 if (error) { 5369 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5370 } else { 5371 console.log('createX509CRL success'); 5372 x509CRL.getEncoded((error, data) => { 5373 if (error) { 5374 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5375 } else { 5376 console.log('getEncoded success'); 5377 } 5378 }); 5379 } 5380}); 5381``` 5382 5383### getEncoded<sup>11+</sup> 5384 5385getEncoded() : Promise\<EncodingBlob> 5386 5387Obtains the serialized X.509 CRL data. This API uses a promise to return the result. 5388 5389**Atomic service API**: This API can be used in atomic services since API version 12. 5390 5391**System capability**: SystemCapability.Security.Cert 5392 5393**Return value** 5394 5395| Type | Description | 5396| --------------------------------------- | -------------------------------- | 5397| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized X.509 CRL data obtained. | 5398**Error codes** 5399 5400For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5401 5402| ID | Error Message | 5403| -------- | ----------------------- | 5404| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 5405| 19020001 | memory error. | 5406| 19020002 | runtime error. | 5407| 19030001 | crypto operation error. | 5408 5409**Example** 5410 5411```ts 5412import { cert } from '@kit.DeviceCertificateKit'; 5413import { BusinessError } from '@kit.BasicServicesKit'; 5414 5415// Convert the string into a Uint8Array. 5416function stringToUint8Array(str: string): Uint8Array { 5417 let arr: Array<number> = []; 5418 for (let i = 0, j = str.length; i < j; i++) { 5419 arr.push(str.charCodeAt(i)); 5420 } 5421 return new Uint8Array(arr); 5422} 5423 5424let crlData = '-----BEGIN X509 CRL-----\n' + 5425 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5426 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5427 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5428 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5429 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5430 'eavsH0Q3\n' + 5431 '-----END X509 CRL-----\n'; 5432 5433// Binary data of the CRL, which varies with the service. 5434let encodingBlob: cert.EncodingBlob = { 5435 data: stringToUint8Array(crlData), 5436 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5437 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5438}; 5439 5440cert.createX509CRL(encodingBlob).then(x509CRL => { 5441 console.log('createX509CRL success'); 5442 x509CRL.getEncoded().then(result => { 5443 console.log('getEncoded success'); 5444 }).catch((error: BusinessError) => { 5445 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5446 }); 5447}).catch((error: BusinessError) => { 5448 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5449}); 5450``` 5451 5452### verify<sup>11+</sup> 5453 5454verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void 5455 5456Verifies the signature of the X.509 CRL. This API uses an asynchronous callback to return the result. The RSA algorithm is supported. 5457 5458**Atomic service API**: This API can be used in atomic services since API version 12. 5459 5460**System capability**: SystemCapability.Security.Cert 5461 5462**Parameters** 5463 5464| Name | Type | Mandatory | Description | 5465| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 5466| key | [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Yes | Public key used for signature verification. | 5467| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails. | 5468 5469**Error codes** 5470 5471For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5472 5473| ID | Error Message | 5474| -------- | ----------------------- | 5475| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 5476| 19030001 | crypto operation error. | 5477 5478**Example** 5479 5480```ts 5481import { cert } from '@kit.DeviceCertificateKit'; 5482import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 5483import { BusinessError } from '@kit.BasicServicesKit'; 5484 5485// Convert the string into a Uint8Array. 5486function stringToUint8Array(str: string): Uint8Array { 5487 let arr: Array<number> = []; 5488 for (let i = 0, j = str.length; i < j; i++) { 5489 arr.push(str.charCodeAt(i)); 5490 } 5491 return new Uint8Array(arr); 5492} 5493 5494let crlData = '-----BEGIN X509 CRL-----\n' + 5495 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5496 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5497 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5498 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5499 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5500 'eavsH0Q3\n' + 5501 '-----END X509 CRL-----\n'; 5502 5503let pubKeyData = new Uint8Array([ 5504 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 5505 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 5506 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 5507 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 5508 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 5509 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 5510 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 5511 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 5512 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 5513 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 5514 0x00, 0x01 5515]); 5516 5517let priKeyData = new Uint8Array([ 5518 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 5519 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x02, 0x61, 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01, 5520 0x00, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 5521 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 5522 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 5523 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 5524 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 5525 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 5526 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 5527 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 5528 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x5A, 0xCF, 0x0F, 5529 0xF5, 0xA6, 0x1C, 0x19, 0x65, 0x8C, 0x94, 0x40, 0xF6, 0x84, 0x28, 0x74, 0x40, 0x42, 0x34, 0xDE, 5530 0xC3, 0x00, 0x5E, 0x72, 0x4D, 0x96, 0xE9, 0x4C, 0xBD, 0xC9, 0xDB, 0x14, 0x9F, 0xD5, 0xBB, 0xA9, 5531 0x0C, 0x20, 0xC2, 0xBE, 0x7A, 0x80, 0x89, 0xEC, 0x99, 0x04, 0xF0, 0xEE, 0x7B, 0x83, 0x20, 0x1D, 5532 0x37, 0x19, 0x55, 0x85, 0xF6, 0x8E, 0x3B, 0xFB, 0x16, 0xF3, 0xD3, 0x6F, 0xEE, 0x73, 0x12, 0x53, 5533 0xCA, 0x77, 0xD7, 0x6C, 0x29, 0xF5, 0x08, 0xA3, 0x09, 0x01, 0x0B, 0x00, 0x05, 0x57, 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 5545 0xA0, 0xD9, 0x85, 0x02, 0x41, 0x00, 0xDF, 0xC8, 0x5B, 0x28, 0x4F, 0x47, 0x15, 0xFD, 0x28, 0xC4, 5546 0x6E, 0xBB, 0x5D, 0x8E, 0xD4, 0x95, 0x06, 0x7E, 0xF1, 0x89, 0x07, 0x86, 0x64, 0x78, 0x69, 0x20, 5547 0x3F, 0xE0, 0xBF, 0x4C, 0x28, 0xC6, 0x04, 0x4D, 0x4D, 0x82, 0x66, 0x6B, 0xAA, 0x64, 0x20, 0xD6, 5548 0x57, 0x68, 0xC6, 0xA0, 0x02, 0x05, 0xB9, 0x28, 0xFC, 0x98, 0xE3, 0x03, 0x5C, 0x9B, 0xEE, 0x29, 5549 0x43, 0x37, 0xFA, 0x03, 0x55, 0x01, 0x02, 0x40, 0x69, 0x5B, 0x7C, 0x24, 0x10, 0xDB, 0xEB, 0x91, 5550 0x33, 0xEF, 0x3F, 0xF2, 0xE6, 0x73, 0x15, 0xCB, 0xF4, 0xF7, 0x89, 0x7D, 0xBF, 0xC0, 0xEA, 0xD2, 5551 0xF3, 0x2B, 0x20, 0xE9, 0x76, 0x54, 0x55, 0x13, 0x50, 0x42, 0x67, 0xB5, 0xCB, 0x73, 0xC0, 0xF7, 5552 0x75, 0x62, 0x04, 0x30, 0x21, 0xAC, 0xAF, 0xD8, 0x44, 0xF4, 0xE1, 0x04, 0x02, 0x7D, 0x61, 0x92, 5553 0x84, 0x99, 0x02, 0x10, 0x64, 0xCB, 0x1F, 0xE9, 0x02, 0x41, 0x00, 0xAB, 0x4B, 0x7D, 0x90, 0x7C, 5554 0x57, 0x08, 0x6B, 0xC0, 0x43, 0x72, 0x09, 0x8A, 0x18, 0x35, 0x36, 0x64, 0x9D, 0x84, 0x8D, 0xF1, 5555 0x84, 0x94, 0x48, 0xC6, 0x80, 0x9D, 0xB9, 0xA2, 0x58, 0x0A, 0x4D, 0x0A, 0xCA, 0x1E, 0xD6, 0x05, 5556 0x55, 0x5B, 0xFE, 0xD7, 0xAA, 0x70, 0xED, 0x76, 0xB3, 0x40, 0x2E, 0xA0, 0xB3, 0x32, 0x37, 0xB0, 5557 0xA0, 0xB9, 0x96, 0x2D, 0xC4, 0x70, 0xE9, 0x99, 0x10, 0x67, 0x8D 5558]); 5559 5560// Binary data of the CRL, which varies with the service. 5561let encodingBlob: cert.EncodingBlob = { 5562 data: stringToUint8Array(crlData), 5563 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5564 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5565}; 5566 5567cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5568 if (error) { 5569 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5570 } else { 5571 console.log('createX509Crl success'); 5572 try { 5573 // Generate the public key by AsyKeyGenerator. 5574 let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); 5575 console.log('createAsyKeyGenerator success'); 5576 let priEncodingBlob: cryptoFramework.DataBlob = { 5577 data: priKeyData, 5578 }; 5579 let pubEncodingBlob: cryptoFramework.DataBlob = { 5580 data: pubKeyData, 5581 }; 5582 keyGenerator.convertKey(pubEncodingBlob, priEncodingBlob, (e, keyPair) => { 5583 if (e) { 5584 console.error('convert key failed, message: ' + e.message + 'code: ' + e.code); 5585 } else { 5586 console.log('convert key success'); 5587 x509CRL.verify(keyPair.pubKey, (err, data) => { 5588 if (err) { 5589 console.error('verify failed, errCode: ' + err.code + ', errMsg: ' + err.message); 5590 } else { 5591 console.log('verify success'); 5592 } 5593 }); 5594 } 5595 }) 5596 } catch (error) { 5597 let e: BusinessError = error as BusinessError; 5598 console.error('get pubKey failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5599 } 5600 } 5601}); 5602``` 5603 5604### verify<sup>11+</sup> 5605 5606verify(key : cryptoFramework.PubKey) : Promise\<void> 5607 5608Verifies the signature of the X.509 CRL. This API uses a promise to return the result. The RSA algorithm is supported. 5609 5610**Atomic service API**: This API can be used in atomic services since API version 12. 5611 5612**System capability**: SystemCapability.Security.Cert 5613 5614**Parameters** 5615 5616| Name | Type | Mandatory | Description | 5617| ------ | ----------------------------------------------------------- | ---- | ------------------------ | 5618| key | [cryptoFramework.PubKey](../apis-crypto-architecture-kit/js-apis-cryptoFramework.md#pubkey) | Yes | Public key used for signature verification. | 5619 5620**Return value** 5621 5622| Type | Description | 5623| -------------- | ----------- | 5624| Promise\<void> | Promise used to return the result. | 5625 5626**Error codes** 5627 5628For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5629 5630| ID | Error Message | 5631| -------- | ----------------------- | 5632| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 5633| 19030001 | crypto operation error. | 5634 5635**Example** 5636 5637```ts 5638import { cert } from '@kit.DeviceCertificateKit'; 5639import { cryptoFramework } from '@kit.CryptoArchitectureKit' 5640import { BusinessError } from '@kit.BasicServicesKit'; 5641 5642// Convert the string into a Uint8Array. 5643function stringToUint8Array(str: string): Uint8Array { 5644 let arr: Array<number> = []; 5645 for (let i = 0, j = str.length; i < j; i++) { 5646 arr.push(str.charCodeAt(i)); 5647 } 5648 return new Uint8Array(arr); 5649} 5650 5651let crlData = '-----BEGIN X509 CRL-----\n' + 5652 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5653 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5654 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5655 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5656 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5657 'eavsH0Q3\n' + 5658 '-----END X509 CRL-----\n'; 5659 5660let pubKeyData = new Uint8Array([ 5661 0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 5662 0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 5663 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 5664 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 5665 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 5666 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 5667 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 5668 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 5669 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 5670 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 5671 0x00, 0x01 5672]); 5673 5674let priKeyData = new Uint8Array([ 5675 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 5676 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x02, 0x61, 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01, 5677 0x00, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 5678 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 5679 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 5680 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 5681 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 5682 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 5683 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 5684 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 5685 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x5A, 0xCF, 0x0F, 5686 0xF5, 0xA6, 0x1C, 0x19, 0x65, 0x8C, 0x94, 0x40, 0xF6, 0x84, 0x28,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x3F, 0x4E, 0x2D, 5698 0x02, 0x41, 0x00, 0xE4, 0x23, 0x2A, 0x5F, 0x59, 0xCF, 0x7C, 0x91, 0x24, 0x0D, 0xA2, 0x44, 0x17, 5699 0xCD, 0x37, 0xDE, 0x1F, 0x53, 0x4D, 0x33, 0x9F, 0x90, 0x4D, 0xD9, 0x72, 0x64, 0x25, 0xBA, 0xAB, 5700 0x47, 0x91, 0xC4, 0x99, 0x95, 0x86, 0xB5, 0x8A, 0xEA, 0x77, 0xF7, 0x64, 0x72, 0x5E, 0xB7, 0xBB, 5701 0x16, 0xA1, 0x64, 0xA4, 0xE1, 0x2D, 0x76, 0x6D, 0xEF, 0xB1, 0x5E, 0xD6, 0x17, 0xE8, 0xAA, 0xB6, 5702 0xA0, 0xD9, 0x85, 0x02, 0x41, 0x00, 0xDF, 0xC8, 0x5B, 0x28, 0x4F, 0x47, 0x15, 0xFD, 0x28, 0xC4, 5703 0x6E, 0xBB, 0x5D, 0x8E, 0xD4, 0x95, 0x06, 0x7E, 0xF1, 0x89, 0x07, 0x86, 0x64, 0x78, 0x69, 0x20, 5704 0x3F, 0xE0, 0xBF, 0x4C, 0x28, 0xC6, 0x04, 0x4D, 0x4D, 0x82, 0x66, 0x6B, 0xAA, 0x64, 0x20, 0xD6, 5705 0x57, 0x68, 0xC6, 0xA0, 0x02, 0x05, 0xB9, 0x28, 0xFC, 0x98, 0xE3, 0x03, 0x5C, 0x9B, 0xEE, 0x29, 5706 0x43, 0x37, 0xFA, 0x03, 0x55, 0x01, 0x02, 0x40, 0x69, 0x5B, 0x7C, 0x24, 0x10, 0xDB, 0xEB, 0x91, 5707 0x33, 0xEF, 0x3F, 0xF2, 0xE6, 0x73, 0x15, 0xCB, 0xF4, 0xF7, 0x89, 0x7D, 0xBF, 0xC0, 0xEA, 0xD2, 5708 0xF3, 0x2B, 0x20, 0xE9, 0x76, 0x54, 0x55, 0x13, 0x50, 0x42, 0x67, 0xB5, 0xCB, 0x73, 0xC0, 0xF7, 5709 0x75, 0x62, 0x04, 0x30, 0x21, 0xAC, 0xAF, 0xD8, 0x44, 0xF4, 0xE1, 0x04, 0x02, 0x7D, 0x61, 0x92, 5710 0x84, 0x99, 0x02, 0x10, 0x64, 0xCB, 0x1F, 0xE9, 0x02, 0x41, 0x00, 0xAB, 0x4B, 0x7D, 0x90, 0x7C, 5711 0x57, 0x08, 0x6B, 0xC0, 0x43, 0x72, 0x09, 0x8A, 0x18, 0x35, 0x36, 0x64, 0x9D, 0x84, 0x8D, 0xF1, 5712 0x84, 0x94, 0x48, 0xC6, 0x80, 0x9D, 0xB9, 0xA2, 0x58, 0x0A, 0x4D, 0x0A, 0xCA, 0x1E, 0xD6, 0x05, 5713 0x55, 0x5B, 0xFE, 0xD7, 0xAA, 0x70, 0xED, 0x76, 0xB3, 0x40, 0x2E, 0xA0, 0xB3, 0x32, 0x37, 0xB0, 5714 0xA0, 0xB9, 0x96, 0x2D, 0xC4, 0x70, 0xE9, 0x99, 0x10, 0x67, 0x8D 5715]); 5716 5717// Binary data of the CRL, which varies with the service. 5718let encodingBlob: cert.EncodingBlob = { 5719 data: stringToUint8Array(crlData), 5720 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5721 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5722}; 5723 5724cert.createX509CRL(encodingBlob).then(x509CRL => { 5725 console.log('createX509Crl success'); 5726 5727 try { 5728 // Generate a public key object. 5729 let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3'); 5730 console.log('createAsyKeyGenerator success'); 5731 let priEncodingBlob: cryptoFramework.DataBlob = { 5732 data: priKeyData, 5733 }; 5734 let pubEncodingBlob: cryptoFramework.DataBlob = { 5735 data: pubKeyData, 5736 }; 5737 keyGenerator.convertKey(pubEncodingBlob, priEncodingBlob).then((keyPair) => { 5738 console.log('convert key success'); 5739 x509CRL.verify(keyPair.pubKey).then(result => { 5740 console.log('verify success'); 5741 }).catch((error: BusinessError) => { 5742 console.error('verify failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5743 }); 5744 }).catch((error: BusinessError) => { 5745 console.error('convert key failed, message: ' + error.message + 'code: ' + error.code); 5746 }); 5747 } catch (error) { 5748 let e: BusinessError = error as BusinessError; 5749 console.error('get pubKey failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5750 } 5751}).catch((error: BusinessError) => { 5752 console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5753}); 5754``` 5755 5756### getVersion<sup>11+</sup> 5757 5758getVersion() : number 5759 5760Obtains the version of the X.509 CRL. 5761 5762**Atomic service API**: This API can be used in atomic services since API version 12. 5763 5764**System capability**: SystemCapability.Security.Cert 5765 5766**Return value** 5767 5768| Type | Description | 5769| ------ | -------------------------------- | 5770| number | Version of the X.509 CRL obtained. | 5771 5772**Example** 5773 5774```ts 5775import { cert } from '@kit.DeviceCertificateKit'; 5776 5777// Convert the string into a Uint8Array. 5778function stringToUint8Array(str: string): Uint8Array { 5779 let arr: Array<number> = []; 5780 for (let i = 0, j = str.length; i < j; i++) { 5781 arr.push(str.charCodeAt(i)); 5782 } 5783 return new Uint8Array(arr); 5784} 5785 5786let crlData = '-----BEGIN X509 CRL-----\n' + 5787 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5788 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5789 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5790 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5791 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5792 'eavsH0Q3\n' + 5793 '-----END X509 CRL-----\n'; 5794 5795// Binary data of the CRL, which varies with the service. 5796let encodingBlob: cert.EncodingBlob = { 5797 data: stringToUint8Array(crlData), 5798 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5799 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5800}; 5801 5802cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5803 if (error) { 5804 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5805 } else { 5806 console.log('createX509CRL success'); 5807 let version = x509CRL.getVersion(); 5808 } 5809}); 5810``` 5811 5812### getIssuerName<sup>11+</sup> 5813 5814getIssuerName() : DataBlob 5815 5816Obtains the issuer of the X.509 CRL. 5817 5818**Atomic service API**: This API can be used in atomic services since API version 12. 5819 5820**System capability**: SystemCapability.Security.Cert 5821 5822**Return value** 5823 5824| Type | Description | 5825| --------------------- | ------------------------------ | 5826| [DataBlob](#datablob) | Issuer of the X.509 CRL obtained. | 5827 5828**Error codes** 5829 5830For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5831 5832| ID | Error Message | 5833| -------- | ----------------------- | 5834| 19020001 | memory error. | 5835| 19020002 | runtime error. | 5836| 19030001 | crypto operation error. | 5837 5838**Example** 5839 5840```ts 5841import { cert } from '@kit.DeviceCertificateKit'; 5842import { BusinessError } from '@kit.BasicServicesKit'; 5843 5844// Convert the string into a Uint8Array. 5845function stringToUint8Array(str: string): Uint8Array { 5846 let arr: Array<number> = []; 5847 for (let i = 0, j = str.length; i < j; i++) { 5848 arr.push(str.charCodeAt(i)); 5849 } 5850 return new Uint8Array(arr); 5851} 5852 5853let crlData = '-----BEGIN X509 CRL-----\n' + 5854 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5855 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5856 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5857 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5858 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5859 'eavsH0Q3\n' + 5860 '-----END X509 CRL-----\n'; 5861 5862// Binary data of the CRL, which varies with the service. 5863let encodingBlob: cert.EncodingBlob = { 5864 data: stringToUint8Array(crlData), 5865 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5866 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5867}; 5868 5869cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5870 if (error) { 5871 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5872 } else { 5873 console.log('createX509CRL success'); 5874 try { 5875 let issuerName = x509CRL.getIssuerName(); 5876 } catch (err) { 5877 let e: BusinessError = err as BusinessError; 5878 console.error('getIssuerName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5879 } 5880 } 5881}); 5882``` 5883 5884### getLastUpdate<sup>11+</sup> 5885 5886getLastUpdate() : string 5887 5888Obtains the last update date of this X.509 CRL. 5889 5890**Atomic service API**: This API can be used in atomic services since API version 12. 5891 5892**System capability**: SystemCapability.Security.Cert 5893 5894**Return value** 5895 5896| Type | Description | 5897| ------ | ------------------------------------ | 5898| string | Last update date of the X.509 CRL obtained, in ASN.1 format.| 5899 5900**Error codes** 5901 5902For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5903 5904| ID | Error Message | 5905| -------- | ----------------------- | 5906| 19020001 | memory error. | 5907| 19020002 | runtime error. | 5908| 19030001 | crypto operation error. | 5909 5910**Example** 5911 5912```ts 5913import { cert } from '@kit.DeviceCertificateKit'; 5914import { BusinessError } from '@kit.BasicServicesKit'; 5915 5916// Convert the string into a Uint8Array. 5917function stringToUint8Array(str: string): Uint8Array { 5918 let arr: Array<number> = []; 5919 for (let i = 0, j = str.length; i < j; i++) { 5920 arr.push(str.charCodeAt(i)); 5921 } 5922 return new Uint8Array(arr); 5923} 5924 5925let crlData = '-----BEGIN X509 CRL-----\n' + 5926 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5927 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 5928 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 5929 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 5930 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 5931 'eavsH0Q3\n' + 5932 '-----END X509 CRL-----\n'; 5933 5934// Binary data of the CRL, which varies with the service. 5935let encodingBlob: cert.EncodingBlob = { 5936 data: stringToUint8Array(crlData), 5937 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 5938 encodingFormat: cert.EncodingFormat.FORMAT_PEM 5939}; 5940 5941cert.createX509CRL(encodingBlob, (error, x509CRL) => { 5942 if (error) { 5943 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 5944 } else { 5945 console.log('createX509CRL success'); 5946 try { 5947 let lastUpdate = x509CRL.getLastUpdate(); 5948 } catch (err) { 5949 let e: BusinessError = err as BusinessError; 5950 console.error('getLastUpdate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 5951 } 5952 } 5953}); 5954``` 5955 5956### getNextUpdate<sup>11+</sup> 5957 5958getNextUpdate() : string 5959 5960Obtains the next update date of this CRL. 5961 5962**Atomic service API**: This API can be used in atomic services since API version 12. 5963 5964**System capability**: SystemCapability.Security.Cert 5965 5966**Return value** 5967 5968| Type | Description | 5969| ------ | ------------------------------------ | 5970| string | Next update date of the CRL obtained, in ASN.1 format.| 5971 5972**Error codes** 5973 5974For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 5975 5976| ID | Error Message | 5977| -------- | ----------------------- | 5978| 19020001 | memory error. | 5979| 19020002 | runtime error. | 5980| 19030001 | crypto operation error. | 5981 5982**Example** 5983 5984```ts 5985import { cert } from '@kit.DeviceCertificateKit'; 5986import { BusinessError } from '@kit.BasicServicesKit'; 5987 5988// Convert the string into a Uint8Array. 5989function stringToUint8Array(str: string): Uint8Array { 5990 let arr: Array<number> = []; 5991 for (let i = 0, j = str.length; i < j; i++) { 5992 arr.push(str.charCodeAt(i)); 5993 } 5994 return new Uint8Array(arr); 5995} 5996 5997let crlData = '-----BEGIN X509 CRL-----\n' + 5998 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 5999 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6000 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6001 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6002 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6003 'eavsH0Q3\n' + 6004 '-----END X509 CRL-----\n'; 6005 6006// Binary data of the CRL, which varies with the service. 6007let encodingBlob: cert.EncodingBlob = { 6008 data: stringToUint8Array(crlData), 6009 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6010 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6011}; 6012 6013cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6014 if (error) { 6015 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6016 } else { 6017 console.log('createX509CRL success'); 6018 try { 6019 let nextUpdate = x509CRL.getNextUpdate(); 6020 } catch (err) { 6021 let e: BusinessError = err as BusinessError; 6022 console.error('getNextUpdate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6023 } 6024 } 6025}); 6026``` 6027 6028### getRevokedCert<sup>11+</sup> 6029 6030getRevokedCert(serialNumber : bigint) : X509CRLEntry 6031 6032Obtains the revoked X.509 certificate based on the specified serial number of the certificate. 6033 6034**Atomic service API**: This API can be used in atomic services since API version 12. 6035 6036**System capability**: SystemCapability.Security.Cert 6037 6038**Parameters** 6039 6040| Name | Type | Mandatory | Description | 6041| ------------ | ------ | ---- | -------------- | 6042| serialNumber | bigint | Yes | Serial number of the certificate. | 6043 6044**Return value** 6045 6046| Type | Description | 6047| ------------------------------- | ---------------------- | 6048| [X509CRLEntry](#x509crlentry11) | Revoked X.509 certificate obtained. | 6049 6050**Error codes** 6051 6052For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6053 6054| ID | Error Message | 6055| -------- | ----------------------- | 6056| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 6057| 19020001 | memory error. | 6058| 19030001 | crypto operation error. | 6059 6060**Example** 6061 6062```ts 6063import { cert } from '@kit.DeviceCertificateKit'; 6064import { BusinessError } from '@kit.BasicServicesKit'; 6065 6066// Convert the string into a Uint8Array. 6067function stringToUint8Array(str: string): Uint8Array { 6068 let arr: Array<number> = []; 6069 for (let i = 0, j = str.length; i < j; i++) { 6070 arr.push(str.charCodeAt(i)); 6071 } 6072 return new Uint8Array(arr); 6073} 6074 6075let crlData = '-----BEGIN X509 CRL-----\n' + 6076 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6077 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6078 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6079 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6080 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6081 'eavsH0Q3\n' + 6082 '-----END X509 CRL-----\n'; 6083 6084// Binary data of the CRL, which varies with the service. 6085let encodingBlob: cert.EncodingBlob = { 6086 data: stringToUint8Array(crlData), 6087 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6088 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6089}; 6090 6091cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6092 if (error) { 6093 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6094 } else { 6095 console.log('createX509CRL success'); 6096 let serialNumber = BigInt(1000); 6097 try { 6098 let entry = x509CRL.getRevokedCert(serialNumber); 6099 } catch (error) { 6100 let e: BusinessError = error as BusinessError; 6101 console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6102 } 6103 } 6104}); 6105``` 6106 6107### getRevokedCertWithCert<sup>11+</sup> 6108 6109getRevokedCertWithCert(cert : X509Cert) : X509CRLEntry 6110 6111Obtains the revoked X.509 certificate based on the specified certificate. 6112 6113**Atomic service API**: This API can be used in atomic services since API version 12. 6114 6115**System capability**: SystemCapability.Security.Cert 6116 6117**Parameters** 6118 6119| Name | Type | Mandatory | Description | 6120| ------ | --------------------- | ---- | ------------ | 6121| cert | [X509Cert](#x509cert) | Yes | Certificate based on which the revoked certificate is obtained. | 6122 6123**Return value** 6124 6125| Type | Description | 6126| ------------------------------- | ---------------------- | 6127| [X509CRLEntry](#x509crlentry11) | Revoked X.509 certificate obtained. | 6128 6129**Error codes** 6130 6131For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6132 6133| ID | Error Message | 6134| -------- | ----------------------- | 6135| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 6136| 19020001 | memory error. | 6137| 19030001 | crypto operation error. | 6138 6139**Example** 6140 6141```ts 6142import { cert } from '@kit.DeviceCertificateKit'; 6143import { BusinessError } from '@kit.BasicServicesKit'; 6144 6145// Convert the string into a Uint8Array. 6146function stringToUint8Array(str: string): Uint8Array { 6147 let arr: Array<number> = []; 6148 for (let i = 0, j = str.length; i < j; i++) { 6149 arr.push(str.charCodeAt(i)); 6150 } 6151 return new Uint8Array(arr); 6152} 6153 6154let crlData = '-----BEGIN X509 CRL-----\n' + 6155 'MIIBjjB4AgEBMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNVBAMMB1Jvb3QgQ0EXDTI0\n' + 6156 'MDMxOTAyMDQwN1oXDTI0MDQxODAyMDQwN1owIjAgAgEEFw0yNDAzMTkwMjA0MDZa\n' + 6157 'MAwwCgYDVR0VBAMKAQGgDjAMMAoGA1UdFAQDAgEAMA0GCSqGSIb3DQEBCwUAA4IB\n' + 6158 'AQCbjvmHxC8dW6WCS/ga73kx2b7f8I/2eVuDYyReuBiGWeJ9vDmGqimJ9VwOk+ph\n' + 6159 'LvG/2Zvh9I8qXxnOWeseA2C0bEshJGvXpquIjm00OUyLlK6jdfRbhXT8OyvDjqZs\n' + 6160 'e1IsMV7Zo11SUc8nR2d0QQ7EVDCN/XFKPsmoK7PhJnRh5gc8W3FKQ6b8H9kdjgTa\n' + 6161 'KQUap1OIDReVsjPBmRAbwMMLtbrAMllF7E6x7uHgHTGaK1ZPJDtsnCJ45ur3mk/o\n' + 6162 'HAJFwHNjNDltiEfvMSs76/X0cwitpeW4dFk6c3QtqhxJrHDD4gl8di+xHOyHXpzX\n' + 6163 '+i2osvdPWRia0dJCL1PCA14k\n' + 6164 '-----END X509 CRL-----\n'; 6165 6166// Certificate binary data, which varies with the service. 6167let certData = '-----BEGIN CERTIFICATE-----\n' + 6168 'MIIDTjCC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rp5FMrFaaGY8M/xqzdW\n' + 6183 'LTDl4nfbuxtA71cIjnE4kOcaemly9/S2wYWdPktsPxQPY1nPUOeJFI7o0sH3rK0c\n' + 6184 'JSqtgAG8vnjK+jbx9RpkgqCsXgUbIahL573VTgxrNrsRjCuVal7XVxl/xOKXr6Er\n' + 6185 'Gpc+OCrXbHNZkUQE5fZH3yL2tXd7EASEb6J3aEWHfF8YBA==\n' + 6186 '-----END CERTIFICATE-----\n'; 6187 6188let certEncodingBlob: cert.EncodingBlob = { 6189 data: stringToUint8Array(certData), 6190 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6191 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6192}; 6193 6194// Binary data of the CRL, which varies with the service. 6195let encodingBlob: cert.EncodingBlob = { 6196 data: stringToUint8Array(crlData), 6197 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6198 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6199}; 6200 6201cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6202 if (error) { 6203 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6204 } else { 6205 console.log('createX509CRL success'); 6206 // Create an X.509 certificate object. 6207 cert.createX509Cert(certEncodingBlob).then((x509Cert) => { 6208 try { 6209 let entry = x509CRL.getRevokedCertWithCert(x509Cert); 6210 console.log('getRevokedCertWithCert success'); 6211 } catch (error) { 6212 let e: BusinessError = error as BusinessError; 6213 console.error('getRevokedCertWithCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6214 } 6215 }).catch((error: BusinessError) => { 6216 console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6217 }) 6218 } 6219}); 6220``` 6221 6222### getRevokedCerts<sup>11+</sup> 6223 6224getRevokedCerts(callback : AsyncCallback<Array\<X509CRLEntry>>) : void 6225 6226Obtains the revoked X.509 certificates. This API uses an asynchronous callback to return the result. 6227 6228**Atomic service API**: This API can be used in atomic services since API version 12. 6229 6230**System capability**: SystemCapability.Security.Cert 6231 6232**Parameters** 6233 6234| Name | Type | Mandatory | Description | 6235| -------- | ------------------------------------------------------ | ---- | -------------------------------- | 6236| callback | AsyncCallback<Array\<[X509CRLEntry](#x509crlentry11)>> | Yes | Callback used to return a list of revoked X.509 certificates. | 6237 6238**Error codes** 6239 6240For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6241 6242| ID | Error Message | 6243| -------- | ----------------------- | 6244| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 6245| 19020001 | memory error. | 6246| 19030001 | crypto operation error. | 6247 6248**Example** 6249 6250```ts 6251import { cert } from '@kit.DeviceCertificateKit'; 6252import { BusinessError } from '@kit.BasicServicesKit'; 6253 6254// Convert the string into a Uint8Array. 6255function stringToUint8Array(str: string): Uint8Array { 6256 let arr: Array<number> = []; 6257 for (let i = 0, j = str.length; i < j; i++) { 6258 arr.push(str.charCodeAt(i)); 6259 } 6260 return new Uint8Array(arr); 6261} 6262 6263let crlData = '-----BEGIN X509 CRL-----\n' + 6264 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6265 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6266 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6267 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6268 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6269 'eavsH0Q3\n' + 6270 '-----END X509 CRL-----\n'; 6271 6272// Binary data of the CRL, which varies with the service. 6273let encodingBlob: cert.EncodingBlob = { 6274 data: stringToUint8Array(crlData), 6275 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6276 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6277}; 6278 6279cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6280 if (error) { 6281 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6282 } else { 6283 console.log('createX509CRL success'); 6284 x509CRL.getRevokedCerts((error, array) => { 6285 if (error) { 6286 console.error('getRevokedCerts failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6287 } else { 6288 console.log('getRevokedCerts success'); 6289 } 6290 }); 6291 } 6292}); 6293``` 6294 6295### getRevokedCerts<sup>11+</sup> 6296 6297getRevokedCerts() : Promise<Array\<X509CRLEntry>> 6298 6299Obtains the revoked X.509 certificates. This API uses a promise to return the result. 6300 6301**Atomic service API**: This API can be used in atomic services since API version 12. 6302 6303**System capability**: SystemCapability.Security.Cert 6304 6305**Return value** 6306 6307| Type | Description | 6308| ------------------------------------------------ | ---------------------- | 6309| Promise<Array\<[X509CRLEntry](#x509crlentry11)>> | Promise used to return a list of revoked X.509 certificates. | 6310 6311**Error codes** 6312 6313For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6314 6315| ID | Error Message | 6316| -------- | ----------------------- | 6317| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 6318| 19020001 | memory error. | 6319| 19030001 | crypto operation error. | 6320 6321**Example** 6322 6323```ts 6324import { cert } from '@kit.DeviceCertificateKit'; 6325import { BusinessError } from '@kit.BasicServicesKit'; 6326 6327// Convert the string into a Uint8Array. 6328function stringToUint8Array(str: string): Uint8Array { 6329 let arr: Array<number> = []; 6330 for (let i = 0, j = str.length; i < j; i++) { 6331 arr.push(str.charCodeAt(i)); 6332 } 6333 return new Uint8Array(arr); 6334} 6335 6336let crlData = '-----BEGIN X509 CRL-----\n' + 6337 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6338 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6339 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6340 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6341 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6342 'eavsH0Q3\n' + 6343 '-----END X509 CRL-----\n'; 6344 6345// Binary data of the CRL, which varies with the service. 6346let encodingBlob: cert.EncodingBlob = { 6347 data: stringToUint8Array(crlData), 6348 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6349 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6350}; 6351 6352cert.createX509CRL(encodingBlob).then(x509CRL => { 6353 console.log('createX509CRL success'); 6354 x509CRL.getRevokedCerts().then(array => { 6355 console.log('getRevokedCerts success'); 6356 }).catch((error: BusinessError) => { 6357 console.error('getRevokedCerts failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6358 }); 6359}).catch((error: BusinessError) => { 6360 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6361}); 6362``` 6363 6364### getSignature<sup>11+</sup> 6365 6366getSignature() : DataBlob 6367 6368Obtains the signature data of the X.509 CRL. 6369 6370**Atomic service API**: This API can be used in atomic services since API version 12. 6371 6372**System capability**: SystemCapability.Security.Cert 6373 6374**Return value** 6375 6376| Type | Description | 6377| --------------------- | ------------------------------ | 6378| [DataBlob](#datablob) | Signature data of the X.509 CRL obtained. | 6379 6380**Error codes** 6381 6382For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6383 6384| ID | Error Message | 6385| -------- | ----------------------- | 6386| 19020001 | memory error. | 6387| 19020002 | runtime error. | 6388| 19030001 | crypto operation error. | 6389 6390**Example** 6391 6392```ts 6393import { cert } from '@kit.DeviceCertificateKit'; 6394import { BusinessError } from '@kit.BasicServicesKit'; 6395 6396// Convert the string into a Uint8Array. 6397function stringToUint8Array(str: string): Uint8Array { 6398 let arr: Array<number> = []; 6399 for (let i = 0, j = str.length; i < j; i++) { 6400 arr.push(str.charCodeAt(i)); 6401 } 6402 return new Uint8Array(arr); 6403} 6404 6405let crlData = '-----BEGIN X509 CRL-----\n' + 6406 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6407 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6408 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6409 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6410 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6411 'eavsH0Q3\n' + 6412 '-----END X509 CRL-----\n'; 6413 6414// Binary data of the CRL, which varies with the service. 6415let encodingBlob: cert.EncodingBlob = { 6416 data: stringToUint8Array(crlData), 6417 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6418 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6419}; 6420 6421cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6422 if (error) { 6423 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6424 } else { 6425 console.log('createX509CRL success'); 6426 try { 6427 let signature = x509CRL.getSignature(); 6428 } catch (err) { 6429 let e: BusinessError = err as BusinessError; 6430 console.error('getSignature failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6431 } 6432 } 6433}); 6434``` 6435 6436### getSignatureAlgName<sup>11+</sup> 6437 6438getSignatureAlgName() : string 6439 6440Obtains the signing algorithm of the X.509 CRL. 6441 6442**Atomic service API**: This API can be used in atomic services since API version 12. 6443 6444**System capability**: SystemCapability.Security.Cert 6445 6446**Return value** 6447 6448| Type | Description | 6449| ------ | -------------------------------- | 6450| string | Signing algorithm obtained. | 6451 6452**Error codes** 6453 6454For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6455 6456| ID | Error Message | 6457| -------- | ----------------------- | 6458| 19020001 | memory error. | 6459| 19020002 | runtime error. | 6460| 19030001 | crypto operation error. | 6461 6462**Example** 6463 6464```ts 6465import { cert } from '@kit.DeviceCertificateKit'; 6466import { BusinessError } from '@kit.BasicServicesKit'; 6467 6468// Convert the string into a Uint8Array. 6469function stringToUint8Array(str: string): Uint8Array { 6470 let arr: Array<number> = []; 6471 for (let i = 0, j = str.length; i < j; i++) { 6472 arr.push(str.charCodeAt(i)); 6473 } 6474 return new Uint8Array(arr); 6475} 6476 6477let crlData = '-----BEGIN X509 CRL-----\n' + 6478 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6479 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6480 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6481 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6482 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6483 'eavsH0Q3\n' + 6484 '-----END X509 CRL-----\n'; 6485 6486// Binary data of the CRL, which varies with the service. 6487let encodingBlob: cert.EncodingBlob = { 6488 data: stringToUint8Array(crlData), 6489 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6490 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6491}; 6492 6493cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6494 if (error) { 6495 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6496 } else { 6497 console.log('createX509CRL success'); 6498 try { 6499 let sigAlgName = x509CRL.getSignatureAlgName(); 6500 } catch (err) { 6501 let e: BusinessError = err as BusinessError; 6502 console.error('getSignatureAlgName failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6503 } 6504 } 6505}); 6506``` 6507 6508### getSignatureAlgOid<sup>11+</sup> 6509 6510getSignatureAlgOid() : string 6511 6512Obtains the OID of the X.509 CRL signing algorithm. OIDs are allocated by the International Organization for Standardization (ISO). 6513 6514**Atomic service API**: This API can be used in atomic services since API version 12. 6515 6516**System capability**: SystemCapability.Security.Cert 6517 6518**Return value** 6519 6520| Type | Description | 6521| ------ | --------------------------------------------- | 6522| string | OID of the X.509 CRL signing algorithm obtained. | 6523 6524**Error codes** 6525 6526For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6527 6528| ID | Error Message | 6529| -------- | ----------------------- | 6530| 19020001 | memory error. | 6531| 19020002 | runtime error. | 6532| 19030001 | crypto operation error. | 6533 6534**Example** 6535 6536```ts 6537import { cert } from '@kit.DeviceCertificateKit'; 6538import { BusinessError } from '@kit.BasicServicesKit'; 6539 6540// Convert the string into a Uint8Array. 6541function stringToUint8Array(str: string): Uint8Array { 6542 let arr: Array<number> = []; 6543 for (let i = 0, j = str.length; i < j; i++) { 6544 arr.push(str.charCodeAt(i)); 6545 } 6546 return new Uint8Array(arr); 6547} 6548 6549let crlData = '-----BEGIN X509 CRL-----\n' + 6550 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6551 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6552 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6553 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6554 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6555 'eavsH0Q3\n' + 6556 '-----END X509 CRL-----\n'; 6557 6558// Binary data of the CRL, which varies with the service. 6559let encodingBlob: cert.EncodingBlob = { 6560 data: stringToUint8Array(crlData), 6561 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6562 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6563}; 6564 6565cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6566 if (error) { 6567 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6568 } else { 6569 console.log('createX509CRL success'); 6570 try { 6571 let sigAlgOid = x509CRL.getSignatureAlgOid(); 6572 } catch (err) { 6573 let e: BusinessError = err as BusinessError; 6574 console.error('getSignatureAlgOid failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6575 } 6576 } 6577}); 6578``` 6579 6580### getSignatureAlgParams<sup>11+</sup> 6581 6582getSignatureAlgParams() : DataBlob 6583 6584Obtains the parameters of the X.509 CRL signing algorithm. 6585 6586**Atomic service API**: This API can be used in atomic services since API version 12. 6587 6588**System capability**: SystemCapability.Security.Cert 6589 6590**Return value** 6591 6592| Type | Description | 6593| --------------------- | ---------------------------------- | 6594| [DataBlob](#datablob) | Algorithm parameters obtained. | 6595 6596**Error codes** 6597 6598For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6599 6600| ID | Error Message | 6601| -------- | ----------------------- | 6602| 801 | this operation is not supported. | 6603| 19020001 | memory error. | 6604| 19020002 | runtime error. | 6605| 19030001 | crypto operation error. | 6606 6607**Example** 6608 6609```ts 6610import { cert } from '@kit.DeviceCertificateKit'; 6611import { BusinessError } from '@kit.BasicServicesKit'; 6612 6613// Convert the string into a Uint8Array. 6614function stringToUint8Array(str: string): Uint8Array { 6615 let arr: Array<number> = []; 6616 for (let i = 0, j = str.length; i < j; i++) { 6617 arr.push(str.charCodeAt(i)); 6618 } 6619 return new Uint8Array(arr); 6620} 6621 6622let crlData = '-----BEGIN X509 CRL-----\n' + 6623 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6624 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6625 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6626 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6627 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6628 'eavsH0Q3\n' + 6629 '-----END X509 CRL-----\n'; 6630 6631// Binary data of the CRL, which varies with the service. 6632let encodingBlob: cert.EncodingBlob = { 6633 data: stringToUint8Array(crlData), 6634 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6635 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6636}; 6637 6638cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6639 if (error) { 6640 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6641 } else { 6642 console.log('createX509CRL success'); 6643 try { 6644 let sigAlgParams = x509CRL.getSignatureAlgParams(); 6645 } catch (err) { 6646 let e: BusinessError = err as BusinessError; 6647 console.error('getSignatureAlgParams failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6648 } 6649 } 6650}); 6651``` 6652 6653### getTBSInfo<sup>11+</sup> 6654 6655getTBSInfo() : DataBlob 6656 6657Obtains the DER-encoded CRL information, that is, **tbsCertList** from this CRL. 6658 6659**Atomic service API**: This API can be used in atomic services since API version 12. 6660 6661**System capability**: SystemCapability.Security.Cert 6662 6663**Return value** 6664 6665| Type | Description | 6666| --------------------- | --------------------------------- | 6667| [DataBlob](#datablob) | **tbsCertList** information obtained. | 6668 6669**Error codes** 6670 6671For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6672 6673| ID | Error Message | 6674| -------- | ----------------------- | 6675| 19020001 | memory error. | 6676| 19020002 | runtime error. | 6677| 19030001 | crypto operation error. | 6678 6679**Example** 6680 6681```ts 6682import { cert } from '@kit.DeviceCertificateKit'; 6683import { BusinessError } from '@kit.BasicServicesKit'; 6684 6685// Convert the string into a Uint8Array. 6686function stringToUint8Array(str: string): Uint8Array { 6687 let arr: Array<number> = []; 6688 for (let i = 0, j = str.length; i < j; i++) { 6689 arr.push(str.charCodeAt(i)); 6690 } 6691 return new Uint8Array(arr); 6692} 6693 6694let crlData = '-----BEGIN X509 CRL-----\n' + 6695 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6696 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6697 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6698 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6699 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6700 'eavsH0Q3\n' + 6701 '-----END X509 CRL-----\n'; 6702 6703// Binary data of the CRL, which varies with the service. 6704let encodingBlob: cert.EncodingBlob = { 6705 data: stringToUint8Array(crlData), 6706 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6707 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6708}; 6709 6710cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6711 if (error) { 6712 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6713 } else { 6714 console.log('createX509CRL success'); 6715 try { 6716 let tbsInfo = x509CRL.getTBSInfo(); 6717 } catch (error) { 6718 let e: BusinessError = error as BusinessError; 6719 console.error('getTBSInfo failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6720 } 6721 } 6722}); 6723``` 6724 6725### getExtensions<sup>11+</sup> 6726 6727getExtensions(): DataBlob 6728 6729Obtains the CRL extensions. 6730 6731**Atomic service API**: This API can be used in atomic services since API version 12. 6732 6733**System capability**: SystemCapability.Security.Cert 6734 6735**Return value** 6736 6737| Type | Description | 6738| --------------------- | ------------------- | 6739| [DataBlob](#datablob) | X.509 CRL extensions obtained. | 6740 6741**Error codes** 6742 6743For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6744 6745| ID | Error Message | 6746| -------- | ----------------------- | 6747| 19020001 | memory error. | 6748| 19020002 | runtime error. | 6749| 19030001 | crypto operation error. | 6750 6751**Example** 6752 6753```ts 6754import { cert } from '@kit.DeviceCertificateKit'; 6755import { BusinessError } from '@kit.BasicServicesKit'; 6756 6757// Convert the string into a Uint8Array. 6758function stringToUint8Array(str: string): Uint8Array { 6759 let arr: Array<number> = []; 6760 for (let i = 0, j = str.length; i < j; i++) { 6761 arr.push(str.charCodeAt(i)); 6762 } 6763 return new Uint8Array(arr); 6764} 6765 6766let crlData = '-----BEGIN X509 CRL-----\n' + 6767 'MIIBjjB4AgEBMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNVBAMMB1Jvb3QgQ0EXDTI0\n' + 6768 'MDMxOTAyMDQwN1oXDTI0MDQxODAyMDQwN1owIjAgAgEEFw0yNDAzMTkwMjA0MDZa\n' + 6769 'MAwwCgYDVR0VBAMKAQGgDjAMMAoGA1UdFAQDAgEAMA0GCSqGSIb3DQEBCwUAA4IB\n' + 6770 'AQCbjvmHxC8dW6WCS/ga73kx2b7f8I/2eVuDYyReuBiGWeJ9vDmGqimJ9VwOk+ph\n' + 6771 'LvG/2Zvh9I8qXxnOWeseA2C0bEshJGvXpquIjm00OUyLlK6jdfRbhXT8OyvDjqZs\n' + 6772 'e1IsMV7Zo11SUc8nR2d0QQ7EVDCN/XFKPsmoK7PhJnRh5gc8W3FKQ6b8H9kdjgTa\n' + 6773 'KQUap1OIDReVsjPBmRAbwMMLtbrAMllF7E6x7uHgHTGaK1ZPJDtsnCJ45ur3mk/o\n' + 6774 'HAJFwHNjNDltiEfvMSs76/X0cwitpeW4dFk6c3QtqhxJrHDD4gl8di+xHOyHXpzX\n' + 6775 '+i2osvdPWRia0dJCL1PCA14k\n' + 6776 '-----END X509 CRL-----\n'; 6777 6778// Binary data of the CRL, which varies with the service. 6779let encodingBlob: cert.EncodingBlob = { 6780 data: stringToUint8Array(crlData), 6781 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6782 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6783}; 6784 6785cert.createX509CRL(encodingBlob, (error, x509CRL) => { 6786 if (error) { 6787 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6788 } else { 6789 console.log('createX509CRL success'); 6790 try { 6791 let extensions = x509CRL.getExtensions(); 6792 } catch (error) { 6793 let e: BusinessError = error as BusinessError; 6794 console.error('getExtensions failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6795 } 6796 } 6797}); 6798``` 6799 6800### match<sup>11+</sup> 6801 6802match(param: X509CRLMatchParameters): boolean 6803 6804Checks whether this CRL matches the specified parameters. 6805 6806**Atomic service API**: This API can be used in atomic services since API version 12. 6807 6808**System capability**: SystemCapability.Security.Cert 6809 6810**Parameters** 6811 6812| Name | Type | Mandatory | Description | 6813| --------- | ------ | ---- | ------------------------------------------ | 6814| param | [X509CRLMatchParameters](#x509crlmatchparameters11)| Yes | Parameters specified for matching the CRL. | 6815 6816**Return value** 6817 6818| Type | Description | 6819| --------------------- | ----------------------------------------- | 6820| boolean | Returns **true** if the CRL matches the parameters specified; returns **false** otherwise. | 6821 6822**Error codes** 6823 6824For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6825 6826| ID | Error Message | 6827| -------- | -------------- | 6828| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 6829| 19020001 | memory error. | 6830| 19030001 | crypto operation error. | 6831 6832**Example** 6833 6834```ts 6835import { cert } from '@kit.DeviceCertificateKit'; 6836import { BusinessError } from '@kit.BasicServicesKit'; 6837 6838// Convert the string into a Uint8Array. 6839function stringToUint8Array(str: string): Uint8Array { 6840 let arr: Array<number> = []; 6841 for (let i = 0, j = str.length; i < j; i++) { 6842 arr.push(str.charCodeAt(i)); 6843 } 6844 return new Uint8Array(arr); 6845} 6846 6847let crlData = '-----BEGIN X509 CRL-----\n' + 6848 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6849 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6850 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6851 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6852 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6853 'eavsH0Q3\n' + 6854 '-----END X509 CRL-----\n'; 6855 6856// Binary data of the CRL, which varies with the service. 6857let crlEncodingBlob: cert.EncodingBlob = { 6858 data: stringToUint8Array(crlData), 6859 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6860 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6861}; 6862 6863const certData = "-----BEGIN CERTIFICATE-----\r\n" + 6864 "MIIC8TCCAdmgAwIBAgIIFB75m06RTHwwDQYJKoZIhvcNAQELBQAwW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wvsPhyumYhaBqAgSy\r\n" + 6879 "Up2BImymAqPi157q9EeYcQz170TtDZHGmjYzdQxhOAHRb6/IdQ==\r\n" + 6880 "-----END CERTIFICATE-----\r\n"; 6881const certEncodingBlob: cert.EncodingBlob = { 6882 data: stringToUint8Array(certData), 6883 encodingFormat: cert.EncodingFormat.FORMAT_PEM, 6884}; 6885 6886async function crlMatch() { 6887 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 6888 try { 6889 x509Cert = await cert.createX509Cert(certEncodingBlob); 6890 console.log('createX509Cert success'); 6891 } catch (err) { 6892 console.error('createX509Cert failed'); 6893 } 6894 6895 cert.createX509CRL(crlEncodingBlob, (error, x509CRL) => { 6896 if (error) { 6897 console.error('createX509CRL failed, errCode: ' + error.code + ', errMsg: ' + error.message); 6898 } else { 6899 console.log('createX509CRL success'); 6900 try { 6901 const param: cert.X509CRLMatchParameters = { 6902 issuer: [new Uint8Array([0x30, 0x58, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4E, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x4A, 0x69, 0x61, 0x6E, 0x67, 0x73, 0x75, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x4E, 0x61, 0x6E, 0x6A, 0x69, 0x6E, 0x67, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x02, 0x74, 0x73, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x02, 0x74, 0x73, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x02, 0x74, 0x73])], 6903 x509Cert: x509Cert 6904 } 6905 const result = x509CRL.match(param); 6906 } catch (error) { 6907 let e: BusinessError = error as BusinessError; 6908 console.error('x509CRL match failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6909 } 6910 } 6911 }); 6912} 6913``` 6914 6915### getIssuerX500DistinguishedName<sup>12+</sup> 6916 6917getIssuerX500DistinguishedName(): X500DistinguishedName 6918 6919Obtains the DN of the X.509 certificate issuer. 6920 6921**Atomic service API**: This API can be used in atomic services since API version 12. 6922 6923**System capability**: SystemCapability.Security.Cert 6924 6925**Return value** 6926 6927| Type | Description | 6928| --------------------- | ----------------------------------------- | 6929| [X500DistinguishedName](#x500distinguishedname12) | DN object obtained. | 6930 6931**Error codes** 6932 6933For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 6934 6935| ID | Error Message | 6936| -------- | -------------- | 6937| 19020001 | memory error. | 6938| 19020002 | runtime error. | 6939| 19030001 | crypto operation error. | 6940 6941**Example** 6942 6943```ts 6944import { cert } from '@kit.DeviceCertificateKit'; 6945import { BusinessError } from '@kit.BasicServicesKit'; 6946 6947// Convert the string into a Uint8Array. 6948function stringToUint8Array(str: string): Uint8Array { 6949 let arr: Array<number> = []; 6950 for (let i = 0, j = str.length; i < j; i++) { 6951 arr.push(str.charCodeAt(i)); 6952 } 6953 return new Uint8Array(arr); 6954} 6955 6956let crlData = '-----BEGIN X509 CRL-----\n' + 6957 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 6958 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 6959 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 6960 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 6961 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 6962 'eavsH0Q3\n' + 6963 '-----END X509 CRL-----\n'; 6964 6965// Binary data of the CRL, which varies with the service. 6966let crlEncodingBlob: cert.EncodingBlob = { 6967 data: stringToUint8Array(crlData), 6968 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 6969 encodingFormat: cert.EncodingFormat.FORMAT_PEM 6970}; 6971 6972async function crlGetIssuerX500DistinguishedName() { 6973 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 6974 try { 6975 x509Crl = await cert.createX509CRL(crlEncodingBlob); 6976 console.log('createX509CRL success'); 6977 let name = x509Crl.getIssuerX500DistinguishedName(); 6978 } catch (err) { 6979 let e: BusinessError = err as BusinessError; 6980 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 6981 } 6982} 6983``` 6984 6985### toString<sup>12+</sup> 6986 6987toString(): string 6988 6989Converts the object data into a string. 6990 6991**Atomic service API**: This API can be used in atomic services since API version 12. 6992 6993**System capability**: SystemCapability.Security.Cert 6994 6995**Return value** 6996 6997| Type | Description | 6998| --------------------- | ----------------------------------------- | 6999| string | String obtained. | 7000 7001**Error codes** 7002 7003For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7004 7005| ID | Error Message | 7006| -------- | -------------- | 7007| 19020001 | memory error. | 7008| 19020002 | runtime error. | 7009| 19030001 | crypto operation error. | 7010 7011**Example** 7012 7013```ts 7014import { cert } from '@kit.DeviceCertificateKit'; 7015import { BusinessError } from '@kit.BasicServicesKit'; 7016 7017// Convert the string into a Uint8Array. 7018function stringToUint8Array(str: string): Uint8Array { 7019 let arr: Array<number> = []; 7020 for (let i = 0, j = str.length; i < j; i++) { 7021 arr.push(str.charCodeAt(i)); 7022 } 7023 return new Uint8Array(arr); 7024} 7025 7026let crlData = '-----BEGIN X509 CRL-----\n' + 7027 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7028 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7029 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7030 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7031 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7032 'eavsH0Q3\n' + 7033 '-----END X509 CRL-----\n'; 7034 7035// Binary data of the CRL, which varies with the service. 7036let crlEncodingBlob: cert.EncodingBlob = { 7037 data: stringToUint8Array(crlData), 7038 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7039 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7040}; 7041 7042async function crlToString() { 7043 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 7044 try { 7045 x509Crl = await cert.createX509CRL(crlEncodingBlob); 7046 console.log('createX509CRL success'); 7047 console.info('crlToString success: ' + JSON.stringify(x509Crl.toString())); 7048 } catch (err) { 7049 let e: BusinessError = err as BusinessError; 7050 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7051 } 7052} 7053``` 7054 7055### hashCode<sup>12+</sup> 7056 7057hashCode(): Uint8Array 7058 7059Obtains the hash value of the data in DER format. 7060 7061**Atomic service API**: This API can be used in atomic services since API version 12. 7062 7063**System capability**: SystemCapability.Security.Cert 7064 7065**Return value** 7066 7067| Type | Description | 7068| --------------------- | ----------------------------------------- | 7069| Uint8Array | Hash value obtained. | 7070 7071**Error codes** 7072 7073For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7074 7075| ID | Error Message | 7076| -------- | -------------- | 7077| 19020001 | memory error. | 7078| 19020002 | runtime error. | 7079| 19030001 | crypto operation error. | 7080 7081**Example** 7082 7083```ts 7084import { cert } from '@kit.DeviceCertificateKit'; 7085import { BusinessError } from '@kit.BasicServicesKit'; 7086 7087// Convert the string into a Uint8Array. 7088function stringToUint8Array(str: string): Uint8Array { 7089 let arr: Array<number> = []; 7090 for (let i = 0, j = str.length; i < j; i++) { 7091 arr.push(str.charCodeAt(i)); 7092 } 7093 return new Uint8Array(arr); 7094} 7095 7096let crlData = '-----BEGIN X509 CRL-----\n' + 7097 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7098 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7099 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7100 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7101 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7102 'eavsH0Q3\n' + 7103 '-----END X509 CRL-----\n'; 7104 7105// Binary data of the CRL, which varies with the service. 7106let crlEncodingBlob: cert.EncodingBlob = { 7107 data: stringToUint8Array(crlData), 7108 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7109 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7110}; 7111 7112async function crlHashCode() { 7113 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 7114 try { 7115 x509Crl = await cert.createX509CRL(crlEncodingBlob); 7116 console.log('createX509CRL success'); 7117 console.info('crlHashCode success: ' + JSON.stringify(x509Crl.hashCode())); 7118 } catch (err) { 7119 let e: BusinessError = err as BusinessError; 7120 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7121 } 7122} 7123``` 7124 7125### getExtensionsObject<sup>12+</sup> 7126 7127getExtensionsObject(): CertExtension 7128 7129Obtains the certification extensions in DER format. 7130 7131**Atomic service API**: This API can be used in atomic services since API version 12. 7132 7133**System capability**: SystemCapability.Security.Cert 7134 7135**Return value** 7136 7137| Type | Description | 7138| --------------------- | ----------------------------------------- | 7139| [CertExtension](#certextension10) | Certificate extensions object obtained.| 7140 7141**Error codes** 7142 7143For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7144 7145| ID | Error Message | 7146| -------- | -------------- | 7147| 19020001 | memory error. | 7148| 19020002 | runtime error. | 7149| 19030001 | crypto operation error. | 7150 7151**Example** 7152 7153```ts 7154import { cert } from '@kit.DeviceCertificateKit'; 7155import { BusinessError } from '@kit.BasicServicesKit'; 7156 7157// Convert the string into a Uint8Array. 7158function stringToUint8Array(str: string): Uint8Array { 7159 let arr: Array<number> = []; 7160 for (let i = 0, j = str.length; i < j; i++) { 7161 arr.push(str.charCodeAt(i)); 7162 } 7163 return new Uint8Array(arr); 7164} 7165 7166let crlData = '-----BEGIN X509 CRL-----\n' + 7167 'MIIB6DCB0QIBATANBgkqhkiG9w0BAQsFADCBjjELMAkGA1UEBhMCUlUxFTATBgNV\n' + 7168 'BAgMDNCc0L7RgdC60LLQsDELMAkGA1UECgwC0K8xCzAJBgNVBAsMAtCvMSowKAYD\n' + 7169 'VQQDDCHQlNC80LjRgtGA0LjQuSDQkdC10LvRj9Cy0YHQutC40LkxIjAgBgkqhkiG\n' + 7170 '9w0BCQEWE2JlbGRtaXRAZXhhbXBsZS5jb20XDTE3MDQyNDEzMjUzMVoXDTE3MDUy\n' + 7171 'NDEzMjUzMVqgDjAMMAoGA1UdFAQDAgEBMA0GCSqGSIb3DQEBCwUAA4IBAQCF5eX+\n' + 7172 '1BM/BxoHU2/3pQHJgPSKevN0/K/daiFHiJl7Kb9GCwKY14B1RvbN2rUP/58Mt+aq\n' + 7173 'jvauf1yBzlaJQeJKZcsCmG9p6Tr1y0BJXhrq5kC0SLyNDsfGUTfuxnwmo+clHXRU\n' + 7174 '+gKuk+h0WkJL022ZYbJ38w588k4NT3CWVHeE23EDC264p942mlDE7en6MyL152Pe\n' + 7175 'Ld9YrWiq5iOIOrIbQLErq0EjwxvHG9sMiYFUa6VrwmRf26nyZ7u9RKJDP+o2dltw\n' + 7176 'diBaSXC3Qt3pZ8BIfv/l81lwp8Dr63SwCII2pIRplyICdQqmX/a+1q8kThXIP2Kx\n' + 7177 '+X48g7VE2o2X4cfy\n' + 7178 '-----END X509 CRL-----\n'; 7179 7180// Binary data of the CRL, which varies with the service. 7181let crlEncodingBlob: cert.EncodingBlob = { 7182 data: stringToUint8Array(crlData), 7183 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7184 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7185}; 7186 7187async function crlHashCode() { 7188 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 7189 try { 7190 x509Crl = await cert.createX509CRL(crlEncodingBlob); 7191 console.log('createX509CRL success'); 7192 let object = x509Crl.getExtensionsObject(); 7193 } catch (err) { 7194 let e: BusinessError = err as BusinessError; 7195 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7196 } 7197} 7198``` 7199 7200## cert.createCertChainValidator 7201 7202createCertChainValidator(algorithm :string) : CertChainValidator 7203 7204Creates a **CertChainValidator** object. 7205 7206**Atomic service API**: This API can be used in atomic services since API version 12. 7207 7208**System capability**: SystemCapability.Security.Cert 7209 7210**Parameters** 7211 7212| Name | Type | Mandatory | Description | 7213| --------- | ------ | ---- | ------------------------------------------ | 7214| algorithm | string | Yes | Certificate chain validator algorithm. Currently, only **PKIX** is supported. | 7215 7216**Return value** 7217 7218| Type | Description | 7219| ------------------ | -------------------- | 7220| [CertChainValidator](#certchainvalidator) | **CertChainValidator** object created. | 7221 7222**Error codes** 7223 7224For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7225 7226| ID | Error Message | 7227| -------- | ----------------------- | 7228| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 7229| 801 | this operation is not supported. | 7230| 19020001 | memory error. | 7231| 19020002 | runtime error. | 7232| 19030001 | crypto operation error. | 7233 7234**Example** 7235 7236```ts 7237import { cert } from '@kit.DeviceCertificateKit'; 7238import { BusinessError } from '@kit.BasicServicesKit'; 7239 7240try { 7241 let validator = cert.createCertChainValidator('PKIX'); 7242} catch (error) { 7243 let e: BusinessError = error as BusinessError; 7244 console.error('createCertChainValidator failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7245} 7246``` 7247 7248## CertChainValidator 7249 7250Provides APIs for certificate chain validator operations. 7251 7252 7253### Properties 7254 7255**Atomic service API**: This API can be used in atomic services since API version 12. 7256 7257**System capability**: SystemCapability.Security.Cert 7258 7259| Name | Type | Readable | Writable | Description | 7260| ------- | ------ | ---- | ---- | -------------------------- | 7261| algorithm | string | Yes | No | Algorithm used by the X509 certificate chain validator. | 7262 7263 7264### validate 7265 7266validate(certChain : CertChainData, callback : AsyncCallback\<void>) : void 7267 7268Validates an X.509 certificate chain. This API uses an asynchronous callback to return the result. 7269The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details about certificate specifications, see [Certificate Specifications](../../security/DeviceCertificateKit/certificate-framework-overview.md#certificate-specifications). 7270 7271**Atomic service API**: This API can be used in atomic services since API version 12. 7272 7273**System capability**: SystemCapability.Security.Cert 7274 7275**Parameters** 7276 7277| Name | Type | Mandatory | Description | 7278| --------- | ------------------------------- | ---- | ------------------------------------------------------------ | 7279| certChain | [CertChainData](#certchaindata) | Yes | Serialized X.509 certificate chain data. | 7280| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If **error** is **null**, the X.509 certificate chain is valid. If **error** is not **null**, the X.509 certificate chain is not valid. | 7281 7282**Error codes** 7283 7284For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7285 7286| ID | Error Message | 7287| -------- | ------------------------------------------------- | 7288| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 7289| 19020001 | memory error. | 7290| 19020002 | runtime error. | 7291| 19030001 | crypto operation error. | 7292| 19030002 | the certificate signature verification failed. | 7293| 19030003 | the certificate has not taken effect. | 7294| 19030004 | the certificate has expired. | 7295| 19030005 | failed to obtain the certificate issuer. | 7296| 19030006 | the key cannot be used for signing a certificate. | 7297| 19030007 | the key cannot be used for digital signature. | 7298 7299**Example** 7300 7301```ts 7302import { cert } from '@kit.DeviceCertificateKit'; 7303import { BusinessError } from '@kit.BasicServicesKit'; 7304 7305// Convert the string into a Uint8Array. 7306function stringToUint8Array(str: string): Uint8Array { 7307 let arr: Array<number> = []; 7308 for (let i = 0, j = str.length; i < j; i++) { 7309 arr.push(str.charCodeAt(i)); 7310 } 7311 return new Uint8Array(arr); 7312} 7313 7314// Binary data of the certificate chain. 7315let certPem = '-----BEGIN CERTIFICATE-----\n' + 7316 'MIIDTjCCAjagAwIBAgIBBDANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 7317 'IENBMB4XDTI0MDMxOTAyMDQwMVoXDTM0MDMxNzAyMDQwMVowEjEQMA4GA1UEAwwH\n' + 7318 'ZGV2aWNlMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMIXL3e7UE/c\n' + 7319 'Z1dPVgRZ5L8gsQ/azuYVBvoFf7o8ksYrL7G1+qZIJjVRqZkuTirLW4GicbkIkPNW\n' + 7320 'eix5cDhkjkC+q5SBCOrSSTTlvX3xcOY1gMlA5MgeBfGixFusq4d5VPF2KceZ20/a\n' + 7321 'ygwGD0Uv0X81OERyPom/dYdJUvfaD9ifPFJ1fKIj/cPFG3yJK/ojpEfndZNdESQL\n' + 7322 'TkoDekilg2UGOLtY6fb9Ns37ncuIj33gCS/R9m1tgtmqCTcgOQ4hwKhjVF3InmPO\n' + 7323 '2BbWKvD1RUX+rHC2a2HHDQILOOtDTy8dHvE+qZlK0efrpRgoFEERJAGPi1GDGWiA\n' + 7324 '7UX1c4MCxIECAwEAAaOBrjCBqzAJBgNVHRMEAjAAMB0GA1UdDgQWBBQbkAcMT7ND\n' + 7325 'fGp3VPFzYHppZ1zxLTAfBgNVHSMEGDAWgBR0W/koCbvDtFGHUQZLM3j6HKsW2DAd\n' + 7326 'BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwCwYDVR0PBAQDAgeAMDIGCCsG\n' + 7327 'AQUFBwEBBCYwJDAiBggrBgEFBQcwAYYWaHR0cHM6Ly8xMjcuMC4wLjE6OTk5OTAN\n' + 7328 'BgkqhkiG9w0BAQsFAAOCAQEAF1OTzTmbklFOdZCxrF3zg9owUPJR5RB+PbuBlUfI\n' + 7329 '8tkGXkMltQ8PN1dv6Cq+d8BluiJdWEzqVoJa/e5SHHJyYQSOhlurRG0GBXllVQ1I\n' + 7330 'n1PFaI40+9X2X6wrEcdC5nbzogR1jSiksCiTcARMddj0Xrp5FMrFaaGY8M/xqzdW\n' + 7331 'LTDl4nfbuxtA71cIjnE4kOcaemly9/S2wYWdPktsPxQPY1nPUOeJFI7o0sH3rK0c\n' + 7332 'JSqtgAG8vnjK+jbx9RpkgqCsXgUbIahL573VTgxrNrsRjCuVal7XVxl/xOKXr6Er\n' + 7333 'Gpc+OCrXbHNZkUQE5fZH3yL2tXd7EASEb6J3aEWHfF8YBA==\n' + 7334 '-----END CERTIFICATE-----'; 7335 7336let caPem = '-----BEGIN CERTIFICATE-----\n' + 7337'MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 7338'IENBMB4XDTI0MDMxOTAyMDIyNFoXDTM0MDMxNzAyMDIyNFowEjEQMA4GA1UEAwwH\n' + 7339'Um9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALxI5SDvRfKU\n' + 7340'6XaTeyh2LHlUK0rVSeYfXkYf5Mc3Pgucg+ewzQjxkACMx5NYaW1zfGDNPG1i5IZl\n' + 7341'cPeWNz1Tm2g6wTd+LyNoNOOmwfLV8pLXSfAukgNrBREf3BzVrbu7hvPd2MmLH23H\n' + 7342'OBM9uDPTIqu3n2CDN2EzwULjaSk2g+jvhVKsDLInu5uKPmZBFhs1FWKgcnVnlbi1\n' + 7343'AyAx4efheits6EO70oV6UufCEtS1VsBXQHZRAG4ogshWldRBVNxkU6yHAfg0mM/5\n' + 7344'EhrZsfh51fWqlrhNWrInjgNV3xIt5ebTIgKZWUlSVHEA/UqDoGfY+CsAJdteZWOW\n' + 7345'KjsrC/DK2O0CAwEAAaNgMF4wHQYDVR0OBBYEFHRb+SgJu8O0UYdRBkszePocqxbY\n' + 7346'MB8GA1UdIwQYMBaAFHRb+SgJu8O0UYdRBkszePocqxbYMA8GA1UdEwEB/wQFMAMB\n' + 7347'Af8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQAKOT1ObfQNMN2wdfHq\n' + 7348'PQgFDDp6rBMbZe70LswPirSXljo4S/vfbG+gBoWCdu/SfsV+lyP75kg1wX0IQvzW\n' + 7349'xYNh864dgqPmGd0v8TIfM0UT0PpnowUyBHQ+E7LNYIOh/kjHbl3oERdEFA2PUyE9\n' + 7350'j3GLdg8oe/LqhEQCSAlH+v2RQgBZ9eVN+mSdUxwywm9U3acb0uqVkGiWK/ywumpg\n' + 7351'AmIZLMJtMVvg8uDkfy16Z4lChTEdNaJVUqPczUNk2kHXIF4we4be9HoOuTVz/SD/\n' + 7352'IsOhXn/BjS3jnhyS9fxo+opJf9zVTWI02Hlh1WVVtH/m3nIZblyAJhcjCHA2wZSz\n' + 7353'sSus\n' + 7354'-----END CERTIFICATE-----'; 7355 7356let certPemData = stringToUint8Array(certPem); 7357let caPemData = stringToUint8Array(caPem); 7358 7359let certPemDataLenData = new Uint8Array(new Uint16Array([certPemData.length]).buffer) 7360let caPemDataLenData = new Uint8Array(new Uint16Array([caPemData.length]).buffer) 7361 7362let certChainBuff = new Uint8Array(certPemDataLenData.length + certPemData.length + caPemDataLenData.length + caPemData.length) 7363certChainBuff.set(certPemDataLenData) 7364certChainBuff.set(certPemData, certPemDataLenData.length) 7365certChainBuff.set(caPemDataLenData, certPemDataLenData.length + certPemData.length) 7366certChainBuff.set(caPemData, certPemDataLenData.length + certPemData.length + caPemDataLenData.length) 7367 7368let certChainData: cert.CertChainData = { 7369 data: certChainBuff, 7370 // Number of certificates in the certificate chain. It must be set based on the service. 7371 count: 2, 7372 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7373 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7374}; 7375 7376try { 7377 let validator = cert.createCertChainValidator('PKIX'); 7378 validator.validate(certChainData, (error, data) => { 7379 if (error) { 7380 console.error('validate failed, errCode: ' + error.code + ', errMsg: ' + error.message); 7381 } else { 7382 console.log('validate success'); 7383 } 7384 }); 7385} catch (error) { 7386 let e: BusinessError = error as BusinessError; 7387 console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7388} 7389``` 7390 7391### validate 7392 7393validate(certChain : CertChainData) : Promise\<void> 7394 7395Validates an X.509 certificate chain. This API uses a promise to return the result. 7396The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details about certificate specifications, see [Certificate Specifications](../../security/DeviceCertificateKit/certificate-framework-overview.md#certificate-specifications). 7397 7398**Atomic service API**: This API can be used in atomic services since API version 12. 7399 7400**System capability**: SystemCapability.Security.Cert 7401 7402**Parameters** 7403 7404| Name | Type | Mandatory | Description | 7405| --------- | ------------------------------- | ---- | -------------------------- | 7406| certChain | [CertChainData](#certchaindata) | Yes | Serialized X.509 certificate chain data. | 7407 7408**Return value** 7409 7410| Type | Description | 7411| -------------- | ----------- | 7412| Promise\<void> | Promise used to return the result. | 7413 7414**Error codes** 7415 7416For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7417 7418| ID | Error Message | 7419| -------- | ------------------------------------------------- | 7420| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 7421| 19020001 | memory error. | 7422| 19020002 | runtime error. | 7423| 19030001 | crypto operation error. | 7424| 19030002 | the certificate signature verification failed. | 7425| 19030003 | the certificate has not taken effect. | 7426| 19030004 | the certificate has expired. | 7427| 19030005 | failed to obtain the certificate issuer. | 7428| 19030006 | the key cannot be used for signing a certificate. | 7429| 19030007 | the key cannot be used for digital signature. | 7430 7431**Example** 7432 7433```ts 7434import { cert } from '@kit.DeviceCertificateKit'; 7435import { BusinessError } from '@kit.BasicServicesKit'; 7436 7437// Convert the string into a Uint8Array. 7438function stringToUint8Array(str: string): Uint8Array { 7439 let arr: Array<number> = []; 7440 for (let i = 0, j = str.length; i < j; i++) { 7441 arr.push(str.charCodeAt(i)); 7442 } 7443 return new Uint8Array(arr); 7444} 7445 7446// Certificate chain data. 7447let certPem = '-----BEGIN CERTIFICATE-----\n' + 7448 'MIIDTjCCAjagAwIBAgIBBDANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 7449 'IENBMB4XDTI0MDMxOTAyMDQwMVoXDTM0MDMxNzAyMDQwMVowEjEQMA4GA1UEAwwH\n' + 7450 'ZGV2aWNlMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMIXL3e7UE/c\n' + 7451 'Z1dPVgRZ5L8gsQ/azuYVBvoFf7o8ksYrL7G1+qZIJjVRqZkuTirLW4GicbkIkPNW\n' + 7452 'eix5cDhkjkC+q5SBCOrSSTTlvX3xcOY1gMlA5MgeBfGixFusq4d5VPF2KceZ20/a\n' + 7453 'ygwGD0Uv0X81OERyPom/dYdJUvfaD9ifPFJ1fKIj/cPFG3yJK/ojpEfndZNdESQL\n' + 7454 'TkoDekilg2UGOLtY6fb9Ns37ncuIj33gCS/R9m1tgtmqCTcgOQ4hwKhjVF3InmPO\n' + 7455 '2BbWKvD1RUX+rHC2a2HHDQILOOtDTy8dHvE+qZlK0efrpRgoFEERJAGPi1GDGWiA\n' + 7456 '7UX1c4MCxIECAwEAAaOBrjCBqzAJBgNVHRMEAjAAMB0GA1UdDgQWBBQbkAcMT7ND\n' + 7457 'fGp3VPFzYHppZ1zxLTAfBgNVHSMEGDAWgBR0W/koCbvDtFGHUQZLM3j6HKsW2DAd\n' + 7458 'BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwCwYDVR0PBAQDAgeAMDIGCCsG\n' + 7459 'AQUFBwEBBCYwJDAiBggrBgEFBQcwAYYWaHR0cHM6Ly8xMjcuMC4wLjE6OTk5OTAN\n' + 7460 'BgkqhkiG9w0BAQsFAAOCAQEAF1OTzTmbklFOdZCxrF3zg9owUPJR5RB+PbuBlUfI\n' + 7461 '8tkGXkMltQ8PN1dv6Cq+d8BluiJdWEzqVoJa/e5SHHJyYQSOhlurRG0GBXllVQ1I\n' + 7462 'n1PFaI40+9X2X6wrEcdC5nbzogR1jSiksCiTcARMddj0Xrp5FMrFaaGY8M/xqzdW\n' + 7463 'LTDl4nfbuxtA71cIjnE4kOcaemly9/S2wYWdPktsPxQPY1nPUOeJFI7o0sH3rK0c\n' + 7464 'JSqtgAG8vnjK+jbx9RpkgqCsXgUbIahL573VTgxrNrsRjCuVal7XVxl/xOKXr6Er\n' + 7465 'Gpc+OCrXbHNZkUQE5fZH3yL2tXd7EASEb6J3aEWHfF8YBA==\n' + 7466 '-----END CERTIFICATE-----'; 7467 7468let caPem = '-----BEGIN CERTIFICATE-----\n' + 7469'MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 7470'IENBMB4XDTI0MDMxOTAyMDIyNFoXDTM0MDMxNzAyMDIyNFowEjEQMA4GA1UEAwwH\n' + 7471'Um9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALxI5SDvRfKU\n' + 7472'6XaTeyh2LHlUK0rVSeYfXkYf5Mc3Pgucg+ewzQjxkACMx5NYaW1zfGDNPG1i5IZl\n' + 7473'cPeWNz1Tm2g6wTd+LyNoNOOmwfLV8pLXSfAukgNrBREf3BzVrbu7hvPd2MmLH23H\n' + 7474'OBM9uDPTIqu3n2CDN2EzwULjaSk2g+jvhVKsDLInu5uKPmZBFhs1FWKgcnVnlbi1\n' + 7475'AyAx4efheits6EO70oV6UufCEtS1VsBXQHZRAG4ogshWldRBVNxkU6yHAfg0mM/5\n' + 7476'EhrZsfh51fWqlrhNWrInjgNV3xIt5ebTIgKZWUlSVHEA/UqDoGfY+CsAJdteZWOW\n' + 7477'KjsrC/DK2O0CAwEAAaNgMF4wHQYDVR0OBBYEFHRb+SgJu8O0UYdRBkszePocqxbY\n' + 7478'MB8GA1UdIwQYMBaAFHRb+SgJu8O0UYdRBkszePocqxbYMA8GA1UdEwEB/wQFMAMB\n' + 7479'Af8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQAKOT1ObfQNMN2wdfHq\n' + 7480'PQgFDDp6rBMbZe70LswPirSXljo4S/vfbG+gBoWCdu/SfsV+lyP75kg1wX0IQvzW\n' + 7481'xYNh864dgqPmGd0v8TIfM0UT0PpnowUyBHQ+E7LNYIOh/kjHbl3oERdEFA2PUyE9\n' + 7482'j3GLdg8oe/LqhEQCSAlH+v2RQgBZ9eVN+mSdUxwywm9U3acb0uqVkGiWK/ywumpg\n' + 7483'AmIZLMJtMVvg8uDkfy16Z4lChTEdNaJVUqPczUNk2kHXIF4we4be9HoOuTVz/SD/\n' + 7484'IsOhXn/BjS3jnhyS9fxo+opJf9zVTWI02Hlh1WVVtH/m3nIZblyAJhcjCHA2wZSz\n' + 7485'sSus\n' + 7486'-----END CERTIFICATE-----'; 7487 7488let certPemData = stringToUint8Array(certPem); 7489let caPemData = stringToUint8Array(caPem); 7490 7491let certPemDataLenData = new Uint8Array(new Uint16Array([certPemData.length]).buffer) 7492let caPemDataLenData = new Uint8Array(new Uint16Array([caPemData.length]).buffer) 7493 7494let certChainBuff = new Uint8Array(certPemDataLenData.length + certPemData.length + caPemDataLenData.length + caPemData.length) 7495certChainBuff.set(certPemDataLenData) 7496certChainBuff.set(certPemData, certPemDataLenData.length) 7497certChainBuff.set(caPemDataLenData, certPemDataLenData.length + certPemData.length) 7498certChainBuff.set(caPemData, certPemDataLenData.length + certPemData.length + caPemDataLenData.length) 7499 7500let certChainData: cert.CertChainData = { 7501 data: certChainBuff, 7502 // Number of certificates in the certificate chain. It must be set based on the service. 7503 count: 2, 7504 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7505 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7506}; 7507 7508try { 7509 let validator = cert.createCertChainValidator('PKIX'); 7510 validator.validate(certChainData).then(result => { 7511 console.log('validate success'); 7512 }).catch((error: BusinessError) => { 7513 console.error('validate failed, errCode: ' + error.code + ', errMsg: ' + error.message); 7514 }); 7515} catch (error) { 7516 let e: BusinessError = error as BusinessError; 7517 console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7518} 7519``` 7520 7521 7522## X509CrlEntry<sup>(deprecated)</sup> 7523 7524Provides APIs for operating the revoked certificates. 7525 7526> **NOTE** 7527> 7528> This API is deprecated since API version 11. Use [X509CrlEntry](#x509crlentry11) instead. 7529 7530### getEncoded<sup>(deprecated)</sup> 7531 7532getEncoded(callback : AsyncCallback\<EncodingBlob>) : void 7533 7534Obtains the serialized data of the revoked certificate. This API uses an asynchronous callback to return the result. 7535 7536> **NOTE** 7537> 7538> This API is deprecated since API version 11. Use [X509CRLEntry.getEncoded](#getencoded11-2) instead. 7539 7540**System capability**: SystemCapability.Security.Cert 7541 7542**Parameters** 7543 7544| Name | Type | Mandatory | Description | 7545| -------- | --------------------------------------------- | ---- | ------------------------------------ | 7546| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback used to return the serialized data of the revoked certificate obtained. | 7547 7548**Error codes** 7549 7550For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7551 7552| ID | Error Message | 7553| -------- | ----------------------- | 7554| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 7555| 19020001 | memory error. | 7556| 19020002 | runtime error. | 7557| 19030001 | crypto operation error. | 7558 7559**Example** 7560 7561```ts 7562import { cert } from '@kit.DeviceCertificateKit'; 7563import { BusinessError } from '@kit.BasicServicesKit'; 7564 7565// Convert the string into a Uint8Array. 7566function stringToUint8Array(str: string): Uint8Array { 7567 let arr: Array<number> = []; 7568 for (let i = 0, j = str.length; i < j; i++) { 7569 arr.push(str.charCodeAt(i)); 7570 } 7571 return new Uint8Array(arr); 7572} 7573 7574let crlData = '-----BEGIN X509 CRL-----\n' + 7575 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7576 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7577 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7578 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7579 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7580 'eavsH0Q3\n' + 7581 '-----END X509 CRL-----\n' 7582 7583let encodingBlob: cert.EncodingBlob = { 7584 data: stringToUint8Array(crlData), 7585 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7586 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7587}; 7588 7589cert.createX509Crl(encodingBlob, (err, x509Crl) => { 7590 if (err) { 7591 console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message); 7592 } else { 7593 console.log('create x509 crl success'); 7594 7595 try { 7596 let serialNumber = 1000; 7597 let crlEntry = x509Crl.getRevokedCert(serialNumber); 7598 crlEntry.getEncoded((error, data) => { 7599 if (error) { 7600 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 7601 } else { 7602 console.log('getEncoded success'); 7603 } 7604 }); 7605 } catch (error) { 7606 let e: BusinessError = error as BusinessError; 7607 console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7608 } 7609 } 7610}) 7611``` 7612 7613### getEncoded<sup>(deprecated)</sup> 7614 7615getEncoded() : Promise\<EncodingBlob> 7616 7617Obtains the serialized data of the revoked certificate. This API uses a promise to return the result. 7618 7619> **NOTE** 7620> 7621> This API is deprecated since API version 11. Use [X509CRLEntry.getEncoded](#getencoded11-3) instead. 7622 7623**System capability**: SystemCapability.Security.Cert 7624 7625**Return value** 7626 7627| Type | Description | 7628| --------------------------------------- | -------------------------- | 7629| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized data of the revoked certificate obtained. | 7630 7631**Error codes** 7632 7633For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7634 7635| ID | Error Message | 7636| -------- | ----------------------- | 7637| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 7638| 19020001 | memory error. | 7639| 19020002 | runtime error. | 7640| 19030001 | crypto operation error. | 7641 7642**Example** 7643 7644```ts 7645import { cert } from '@kit.DeviceCertificateKit'; 7646import { BusinessError } from '@kit.BasicServicesKit'; 7647 7648// Convert the string into a Uint8Array. 7649function stringToUint8Array(str: string): Uint8Array { 7650 let arr: Array<number> = []; 7651 for (let i = 0, j = str.length; i < j; i++) { 7652 arr.push(str.charCodeAt(i)); 7653 } 7654 return new Uint8Array(arr); 7655} 7656 7657let crlData = '-----BEGIN X509 CRL-----\n' + 7658 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7659 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7660 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7661 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7662 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7663 'eavsH0Q3\n' + 7664 '-----END X509 CRL-----\n' 7665 7666let encodingBlob: cert.EncodingBlob = { 7667 data: stringToUint8Array(crlData), 7668 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7669 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7670}; 7671 7672cert.createX509Crl(encodingBlob, (err, x509Crl) => { 7673 if (err) { 7674 console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message); 7675 } else { 7676 console.log('create x509 crl success'); 7677 7678 try { 7679 let serialNumber = 1000; 7680 let crlEntry = x509Crl.getRevokedCert(serialNumber); 7681 crlEntry.getEncoded().then(result => { 7682 console.log('getEncoded success'); 7683 }).catch((error: BusinessError) => { 7684 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 7685 }); 7686 } catch (error) { 7687 let e: BusinessError = error as BusinessError; 7688 console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7689 } 7690 } 7691}) 7692``` 7693 7694### getSerialNumber<sup>(deprecated)</sup> 7695 7696getSerialNumber() : number 7697 7698Obtains the serial number of this revoked certificate. 7699 7700> **NOTE** 7701> 7702> This API is deprecated since API version 11. Use [X509CRLEntry.getSerialNumber](#getserialnumber11) instead. 7703 7704**System capability**: SystemCapability.Security.Cert 7705 7706**Return value** 7707 7708| Type | Description | 7709| ------ | ---------------------- | 7710| number | Serial number of the revoked certificate obtained. | 7711 7712**Example** 7713 7714```ts 7715import { cert } from '@kit.DeviceCertificateKit'; 7716import { BusinessError } from '@kit.BasicServicesKit'; 7717 7718// Convert the string into a Uint8Array. 7719function stringToUint8Array(str: string): Uint8Array { 7720 let arr: Array<number> = []; 7721 for (let i = 0, j = str.length; i < j; i++) { 7722 arr.push(str.charCodeAt(i)); 7723 } 7724 return new Uint8Array(arr); 7725} 7726 7727let crlData = '-----BEGIN X509 CRL-----\n' + 7728 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7729 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7730 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7731 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7732 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7733 'eavsH0Q3\n' + 7734 '-----END X509 CRL-----\n' 7735 7736let encodingBlob: cert.EncodingBlob = { 7737 data: stringToUint8Array(crlData), 7738 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7739 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7740}; 7741 7742cert.createX509Crl(encodingBlob, (err, x509Crl) => { 7743 if (err) { 7744 console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message); 7745 } else { 7746 console.log('create x509 crl success'); 7747 7748 try { 7749 let serialNumber = 1000; 7750 let crlEntry = x509Crl.getRevokedCert(serialNumber); 7751 serialNumber = crlEntry.getSerialNumber(); 7752 } catch (error) { 7753 let e: BusinessError = error as BusinessError; 7754 console.error('getRevokedCert or getSerialNumber failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7755 } 7756 } 7757}) 7758``` 7759 7760### getCertIssuer<sup>(deprecated)</sup> 7761 7762getCertIssuer() : DataBlob 7763 7764Obtains the issuer of this revoked certificate. This API uses an asynchronous callback to return the result. 7765 7766> **NOTE** 7767> 7768> This API is deprecated since API version 11. Use [X509CRLEntry.getCertIssuer](#getcertissuer11) instead. 7769 7770**System capability**: SystemCapability.Security.Cert 7771 7772**Return value** 7773 7774| Type | Description | 7775| --------------------- | ----------------------- | 7776| [DataBlob](#datablob) | Issuer of the revoked certificate obtained. | 7777 7778**Error codes** 7779 7780For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7781 7782| ID | Error Message | 7783| -------- | -------------- | 7784| 801 | this operation is not supported. | 7785| 19020001 | memory error. | 7786| 19020002 | runtime error. | 7787 7788**Example** 7789 7790```ts 7791import { cert } from '@kit.DeviceCertificateKit'; 7792import { BusinessError } from '@kit.BasicServicesKit'; 7793 7794// Convert the string into a Uint8Array. 7795function stringToUint8Array(str: string): Uint8Array { 7796 let arr: Array<number> = []; 7797 for (let i = 0, j = str.length; i < j; i++) { 7798 arr.push(str.charCodeAt(i)); 7799 } 7800 return new Uint8Array(arr); 7801} 7802 7803let crlData = '-----BEGIN X509 CRL-----\n' + 7804 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7805 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7806 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7807 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7808 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7809 'eavsH0Q3\n' + 7810 '-----END X509 CRL-----\n' 7811 7812let encodingBlob: cert.EncodingBlob = { 7813 data: stringToUint8Array(crlData), 7814 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7815 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7816}; 7817 7818cert.createX509Crl(encodingBlob, (err, x509Crl) => { 7819 if (err) { 7820 console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message); 7821 } else { 7822 console.log('create x509 crl success'); 7823 7824 try { 7825 let serialNumber = 1000; 7826 let crlEntry = x509Crl.getRevokedCert(serialNumber); 7827 let issuer = crlEntry.getCertIssuer(); 7828 } catch (error) { 7829 let e: BusinessError = error as BusinessError; 7830 console.error('getRevokedCert or getCertIssuer failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7831 } 7832 } 7833}) 7834``` 7835 7836### getRevocationDate<sup>(deprecated)</sup> 7837 7838getRevocationDate() : string 7839 7840Obtains the date when the certificate is revoked. 7841 7842> **NOTE** 7843> 7844> This API is deprecated since API version 11. Use [X509CRLEntry.getRevocationDate](#getrevocationdate11) instead. 7845 7846**System capability**: SystemCapability.Security.Cert 7847 7848**Return value** 7849 7850| Type | Description | 7851| ------ | ------------------ | 7852| string | Certificate revocation date obtained, in ASN.1 format.| 7853 7854**Error codes** 7855 7856For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7857 7858| ID | Error Message | 7859| -------- | ----------------------- | 7860| 19020001 | memory error. | 7861| 19020002 | runtime error. | 7862| 19030001 | crypto operation error. | 7863 7864**Example** 7865 7866```ts 7867import { cert } from '@kit.DeviceCertificateKit'; 7868import { BusinessError } from '@kit.BasicServicesKit'; 7869 7870// Convert the string into a Uint8Array. 7871function stringToUint8Array(str: string): Uint8Array { 7872 let arr: Array<number> = []; 7873 for (let i = 0, j = str.length; i < j; i++) { 7874 arr.push(str.charCodeAt(i)); 7875 } 7876 return new Uint8Array(arr); 7877} 7878 7879let crlData = '-----BEGIN X509 CRL-----\n' + 7880 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7881 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7882 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7883 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7884 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7885 'eavsH0Q3\n' + 7886 '-----END X509 CRL-----\n' 7887 7888let encodingBlob: cert.EncodingBlob = { 7889 data: stringToUint8Array(crlData), 7890 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7891 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7892}; 7893 7894cert.createX509Crl(encodingBlob, (err, x509Crl) => { 7895 if (err) { 7896 console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message); 7897 } else { 7898 console.log('create x509 crl success'); 7899 7900 try { 7901 let serialNumber = 1000; 7902 let crlEntry = x509Crl.getRevokedCert(serialNumber); 7903 let date = crlEntry.getRevocationDate(); 7904 } catch (error) { 7905 let e: BusinessError = error as BusinessError; 7906 console.error('getRevokedCert or getRevocationDate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7907 } 7908 } 7909}) 7910``` 7911 7912## X509CRLEntry<sup>11+</sup> 7913 7914Provides APIs for operating the revoked certificates. 7915 7916### getEncoded<sup>11+</sup> 7917 7918getEncoded(callback : AsyncCallback\<EncodingBlob>) : void 7919 7920Obtains the serialized data of the revoked certificate. This API uses an asynchronous callback to return the result. 7921 7922**Atomic service API**: This API can be used in atomic services since API version 12. 7923 7924**System capability**: SystemCapability.Security.Cert 7925 7926**Parameters** 7927 7928| Name | Type | Mandatory | Description | 7929| -------- | --------------------------------------------- | ---- | ------------------------------------ | 7930| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback used to return the serialized data of the revoked certificate obtained. | 7931 7932**Error codes** 7933 7934For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 7935 7936| ID | Error Message | 7937| -------- | ----------------------- | 7938| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 7939| 19020001 | memory error. | 7940| 19020002 | runtime error. | 7941| 19030001 | crypto operation error. | 7942 7943**Example** 7944 7945```ts 7946import { cert } from '@kit.DeviceCertificateKit'; 7947import { BusinessError } from '@kit.BasicServicesKit'; 7948 7949// Convert the string into a Uint8Array. 7950function stringToUint8Array(str: string): Uint8Array { 7951 let arr: Array<number> = []; 7952 for (let i = 0, j = str.length; i < j; i++) { 7953 arr.push(str.charCodeAt(i)); 7954 } 7955 return new Uint8Array(arr); 7956} 7957 7958let crlData = '-----BEGIN X509 CRL-----\n' + 7959 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 7960 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 7961 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 7962 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 7963 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 7964 'eavsH0Q3\n' + 7965 '-----END X509 CRL-----\n' 7966 7967let encodingBlob: cert.EncodingBlob = { 7968 data: stringToUint8Array(crlData), 7969 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 7970 encodingFormat: cert.EncodingFormat.FORMAT_PEM 7971}; 7972 7973cert.createX509CRL(encodingBlob, (err, x509CRL) => { 7974 if (err) { 7975 console.error('createX509CRL failed, errCode: ' + err.code + ', errMsg: ' + err.message); 7976 } else { 7977 console.log('create x509 CRL success'); 7978 7979 try { 7980 let serialNumber = BigInt(1000); 7981 let crlEntry = x509CRL.getRevokedCert(serialNumber); 7982 crlEntry.getEncoded((error, data) => { 7983 if (error) { 7984 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 7985 } else { 7986 console.log('getEncoded success'); 7987 } 7988 }); 7989 } catch (error) { 7990 let e: BusinessError = error as BusinessError; 7991 console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 7992 } 7993 } 7994}) 7995``` 7996 7997### getEncoded<sup>11+</sup> 7998 7999getEncoded() : Promise\<EncodingBlob> 8000 8001Obtains the serialized data of the revoked certificate. This API uses a promise to return the result. 8002 8003**Atomic service API**: This API can be used in atomic services since API version 12. 8004 8005**System capability**: SystemCapability.Security.Cert 8006 8007**Return value** 8008 8009| Type | Description | 8010| --------------------------------------- | -------------------------- | 8011| Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized data of the revoked certificate obtained. | 8012 8013**Error codes** 8014 8015For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8016 8017| ID | Error Message | 8018| -------- | ----------------------- | 8019| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types.| 8020| 19020001 | memory error. | 8021| 19020002 | runtime error. | 8022| 19030001 | crypto operation error. | 8023 8024**Example** 8025 8026```ts 8027import { cert } from '@kit.DeviceCertificateKit'; 8028import { BusinessError } from '@kit.BasicServicesKit'; 8029 8030// Convert the string into a Uint8Array. 8031function stringToUint8Array(str: string): Uint8Array { 8032 let arr: Array<number> = []; 8033 for (let i = 0, j = str.length; i < j; i++) { 8034 arr.push(str.charCodeAt(i)); 8035 } 8036 return new Uint8Array(arr); 8037} 8038 8039let crlData = '-----BEGIN X509 CRL-----\n' + 8040 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8041 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8042 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8043 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8044 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8045 'eavsH0Q3\n' + 8046 '-----END X509 CRL-----\n' 8047 8048let encodingBlob: cert.EncodingBlob = { 8049 data: stringToUint8Array(crlData), 8050 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8051 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8052}; 8053 8054cert.createX509CRL(encodingBlob, (err, x509CRL) => { 8055 if (err) { 8056 console.error('createX509CRL failed, errCode: ' + err.code + ', errMsg: ' + err.message); 8057 } else { 8058 console.log('create x509 CRL success'); 8059 8060 try { 8061 let serialNumber = BigInt(1000); 8062 let crlEntry = x509CRL.getRevokedCert(serialNumber); 8063 crlEntry.getEncoded().then(result => { 8064 console.log('getEncoded success'); 8065 }).catch((error: BusinessError) => { 8066 console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message); 8067 }); 8068 } catch (error) { 8069 let e: BusinessError = error as BusinessError; 8070 console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8071 } 8072 } 8073}) 8074``` 8075 8076### getSerialNumber<sup>11+</sup> 8077 8078getSerialNumber() : bigint 8079 8080Obtains the serial number of this revoked certificate. 8081 8082**Atomic service API**: This API can be used in atomic services since API version 12. 8083 8084**System capability**: SystemCapability.Security.Cert 8085 8086**Return value** 8087 8088| Type | Description | 8089| ------ | ---------------------- | 8090| bigint | Serial number of the revoked certificate obtained. | 8091 8092**Error codes** 8093 8094For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8095 8096| ID | Error Message | 8097| -------- | ----------------------- | 8098| 19020001 | memory error. | 8099| 19020002 | runtime error. | 8100| 19030001 | crypto operation error. | 8101 8102**Example** 8103 8104```ts 8105import { cert } from '@kit.DeviceCertificateKit'; 8106import { BusinessError } from '@kit.BasicServicesKit'; 8107 8108// Convert the string into a Uint8Array. 8109function stringToUint8Array(str: string): Uint8Array { 8110 let arr: Array<number> = []; 8111 for (let i = 0, j = str.length; i < j; i++) { 8112 arr.push(str.charCodeAt(i)); 8113 } 8114 return new Uint8Array(arr); 8115} 8116 8117let crlData = '-----BEGIN X509 CRL-----\n' + 8118 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8119 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8120 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8121 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8122 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8123 'eavsH0Q3\n' + 8124 '-----END X509 CRL-----\n' 8125 8126let encodingBlob: cert.EncodingBlob = { 8127 data: stringToUint8Array(crlData), 8128 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8129 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8130}; 8131 8132cert.createX509CRL(encodingBlob, (err, x509CRL) => { 8133 if (err) { 8134 console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message); 8135 } else { 8136 console.log('create x509 crl success'); 8137 8138 try { 8139 let serialNumber = BigInt(1000); 8140 let crlEntry = x509CRL.getRevokedCert(serialNumber); 8141 serialNumber = crlEntry.getSerialNumber(); 8142 } catch (error) { 8143 let e: BusinessError = error as BusinessError; 8144 console.error('getRevokedCert or getSerialNumber failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8145 } 8146 } 8147}) 8148``` 8149 8150### getCertIssuer<sup>11+</sup> 8151 8152getCertIssuer() : DataBlob 8153 8154Obtains the issuer of this revoked certificate. 8155 8156**Atomic service API**: This API can be used in atomic services since API version 12. 8157 8158**System capability**: SystemCapability.Security.Cert 8159 8160**Return value** 8161 8162| Type | Description | 8163| --------------------- | -------------------------- | 8164| [DataBlob](#datablob) | Issuer of the revoked certificate obtained. | 8165 8166**Error codes** 8167 8168For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8169 8170| ID | Error Message | 8171| -------- | ----------------------- | 8172| 801 | this operation is not supported. | 8173| 19020001 | memory error. | 8174| 19020002 | runtime error. | 8175| 19030001 | crypto operation error. | 8176 8177**Example** 8178 8179```ts 8180import { cert } from '@kit.DeviceCertificateKit'; 8181import { BusinessError } from '@kit.BasicServicesKit'; 8182 8183// Convert the string into a Uint8Array. 8184function stringToUint8Array(str: string): Uint8Array { 8185 let arr: Array<number> = []; 8186 for (let i = 0, j = str.length; i < j; i++) { 8187 arr.push(str.charCodeAt(i)); 8188 } 8189 return new Uint8Array(arr); 8190} 8191 8192let crlData = '-----BEGIN X509 CRL-----\n' + 8193 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8194 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8195 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8196 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8197 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8198 'eavsH0Q3\n' + 8199 '-----END X509 CRL-----\n' 8200 8201let encodingBlob: cert.EncodingBlob = { 8202 data: stringToUint8Array(crlData), 8203 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8204 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8205}; 8206 8207cert.createX509CRL(encodingBlob, (err, x509CRL) => { 8208 if (err) { 8209 console.error('createX509CRL failed, errCode: ' + err.code + ', errMsg: ' + err.message); 8210 } else { 8211 console.log('create x509 CRL success'); 8212 8213 try { 8214 let serialNumber = BigInt(1000); 8215 let crlEntry = x509CRL.getRevokedCert(serialNumber); 8216 let issuer = crlEntry.getCertIssuer(); 8217 } catch (error) { 8218 let e: BusinessError = error as BusinessError; 8219 console.error('getRevokedCert or getCertIssuer failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8220 } 8221 } 8222}) 8223``` 8224 8225### getRevocationDate<sup>11+</sup> 8226 8227getRevocationDate() : string 8228 8229Obtains the date when the certificate is revoked. 8230 8231**Atomic service API**: This API can be used in atomic services since API version 12. 8232 8233**System capability**: SystemCapability.Security.Cert 8234 8235**Return value** 8236 8237| Type | Description | 8238| ------ | -------------------- | 8239| string | Certificate revocation date obtained, in ASN.1 format.| 8240 8241**Error codes** 8242 8243For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8244 8245| ID | Error Message | 8246| -------- | ----------------------- | 8247| 19020001 | memory error. | 8248| 19020002 | runtime error. | 8249| 19030001 | crypto operation error. | 8250 8251**Example** 8252 8253```ts 8254import { cert } from '@kit.DeviceCertificateKit'; 8255import { BusinessError } from '@kit.BasicServicesKit'; 8256 8257// Convert the string into a Uint8Array. 8258function stringToUint8Array(str: string): Uint8Array { 8259 let arr: Array<number> = []; 8260 for (let i = 0, j = str.length; i < j; i++) { 8261 arr.push(str.charCodeAt(i)); 8262 } 8263 return new Uint8Array(arr); 8264} 8265 8266let crlData = '-----BEGIN X509 CRL-----\n' + 8267 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8268 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8269 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8270 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8271 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8272 'eavsH0Q3\n' + 8273 '-----END X509 CRL-----\n' 8274 8275let encodingBlob: cert.EncodingBlob = { 8276 data: stringToUint8Array(crlData), 8277 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8278 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8279}; 8280 8281cert.createX509CRL(encodingBlob, (err, x509CRL) => { 8282 if (err) { 8283 console.error('createX509CRL failed, errCode: ' + err.code + ', errMsg: ' + err.message); 8284 } else { 8285 console.log('create x509 CRL success'); 8286 8287 try { 8288 let serialNumber = BigInt(1000); 8289 let crlEntry = x509CRL.getRevokedCert(serialNumber); 8290 let date = crlEntry.getRevocationDate(); 8291 } catch (error) { 8292 let e: BusinessError = error as BusinessError; 8293 console.error('getRevokedCert or getRevocationDate failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8294 } 8295 } 8296}) 8297``` 8298 8299### getExtensions<sup>11+</sup> 8300 8301getExtensions(): DataBlob 8302 8303Obtains the CRL extensions. 8304 8305**Atomic service API**: This API can be used in atomic services since API version 12. 8306 8307**System capability**: SystemCapability.Security.Cert 8308 8309**Return value** 8310 8311| Type | Description | 8312| --------------------- | ------------------------ | 8313| [DataBlob](#datablob) | CRL extensions obtained. | 8314 8315**Error codes** 8316 8317For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8318 8319| ID | Error Message | 8320| -------- | ----------------------- | 8321| 19020001 | memory error. | 8322| 19020002 | runtime error. | 8323| 19030001 | crypto operation error. | 8324 8325**Example** 8326 8327```ts 8328import { cert } from '@kit.DeviceCertificateKit'; 8329import { BusinessError } from '@kit.BasicServicesKit'; 8330 8331// Convert the string into a Uint8Array. 8332function stringToUint8Array(str: string): Uint8Array { 8333 let arr: Array<number> = []; 8334 for (let i = 0, j = str.length; i < j; i++) { 8335 arr.push(str.charCodeAt(i)); 8336 } 8337 return new Uint8Array(arr); 8338} 8339 8340let crlData = '-----BEGIN X509 CRL-----\n' + 8341 'MIIBjjB4AgEBMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNVBAMMB1Jvb3QgQ0EXDTI0\n' + 8342 'MDMxOTAyMDQwN1oXDTI0MDQxODAyMDQwN1owIjAgAgEEFw0yNDAzMTkwMjA0MDZa\n' + 8343 'MAwwCgYDVR0VBAMKAQGgDjAMMAoGA1UdFAQDAgEAMA0GCSqGSIb3DQEBCwUAA4IB\n' + 8344 'AQCbjvmHxC8dW6WCS/ga73kx2b7f8I/2eVuDYyReuBiGWeJ9vDmGqimJ9VwOk+ph\n' + 8345 'LvG/2Zvh9I8qXxnOWeseA2C0bEshJGvXpquIjm00OUyLlK6jdfRbhXT8OyvDjqZs\n' + 8346 'e1IsMV7Zo11SUc8nR2d0QQ7EVDCN/XFKPsmoK7PhJnRh5gc8W3FKQ6b8H9kdjgTa\n' + 8347 'KQUap1OIDReVsjPBmRAbwMMLtbrAMllF7E6x7uHgHTGaK1ZPJDtsnCJ45ur3mk/o\n' + 8348 'HAJFwHNjNDltiEfvMSs76/X0cwitpeW4dFk6c3QtqhxJrHDD4gl8di+xHOyHXpzX\n' + 8349 '+i2osvdPWRia0dJCL1PCA14k\n' + 8350 '-----END X509 CRL-----\n'; 8351 8352let encodingBlob: cert.EncodingBlob = { 8353 data: stringToUint8Array(crlData), 8354 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8355 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8356}; 8357 8358cert.createX509CRL(encodingBlob, (err, x509CRL) => { 8359 if (err) { 8360 console.error('createX509CRL failed, errCode: ' + err.code + ', errMsg: ' + err.message); 8361 } else { 8362 console.log('create x509 CRL success'); 8363 8364 try { 8365 let serialNumber = BigInt(4); 8366 let crlEntry = x509CRL.getRevokedCert(serialNumber); 8367 let extensions = crlEntry.getExtensions(); 8368 } catch (error) { 8369 let e: BusinessError = error as BusinessError; 8370 console.error('getRevokedCert or getExtensions failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8371 } 8372 } 8373}) 8374``` 8375 8376### hasExtensions<sup>11+</sup> 8377 8378hasExtensions(): boolean 8379 8380Checks whether this CRL entry has extensions. 8381 8382**Atomic service API**: This API can be used in atomic services since API version 12. 8383 8384**System capability**: SystemCapability.Security.Cert 8385 8386**Return value** 8387 8388| Type | Description | 8389| ------- | ---------------------------------------------------- | 8390| boolean | Returns **true** if the CRL entry has extension; returns **false** otherwise. | 8391 8392**Error codes** 8393 8394For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8395 8396| ID | Error Message | 8397| -------- | ----------------------- | 8398| 19020001 | memory error. | 8399| 19020002 | runtime error. | 8400| 19030001 | crypto operation error. | 8401 8402**Example** 8403 8404```ts 8405import { cert } from '@kit.DeviceCertificateKit'; 8406import { BusinessError } from '@kit.BasicServicesKit'; 8407 8408// Convert the string into a Uint8Array. 8409function stringToUint8Array(str: string): Uint8Array { 8410 let arr: Array<number> = []; 8411 for (let i = 0, j = str.length; i < j; i++) { 8412 arr.push(str.charCodeAt(i)); 8413 } 8414 return new Uint8Array(arr); 8415} 8416 8417let crlData = '-----BEGIN X509 CRL-----\n' + 8418 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8419 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8420 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8421 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8422 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8423 'eavsH0Q3\n' + 8424 '-----END X509 CRL-----\n' 8425 8426let encodingBlob: cert.EncodingBlob = { 8427 data: stringToUint8Array(crlData), 8428 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8429 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8430}; 8431 8432cert.createX509CRL(encodingBlob, (err, x509CRL) => { 8433 if (err) { 8434 console.error('createX509CRL failed, errCode: ' + err.code + ', errMsg: ' + err.message); 8435 } else { 8436 console.log('create x509 CRL success'); 8437 8438 try { 8439 let serialNumber = BigInt(1000); 8440 let crlEntry = x509CRL.getRevokedCert(serialNumber); 8441 let hasExtensions = crlEntry.hasExtensions(); 8442 } catch (error) { 8443 let e: BusinessError = error as BusinessError; 8444 console.error('getRevokedCert or hasExtensions failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8445 } 8446 } 8447}) 8448``` 8449 8450### getCertIssuerX500DistinguishedName<sup>12+</sup> 8451 8452getCertIssuerX500DistinguishedName(): X500DistinguishedName 8453 8454Obtains the DN of the certificate issuer. 8455 8456**Atomic service API**: This API can be used in atomic services since API version 12. 8457 8458**System capability**: SystemCapability.Security.Cert 8459 8460**Return value** 8461 8462| Type | Description | 8463| ------- | ---------------------------------------------------- | 8464| [X500DistinguishedName](#x500distinguishedname12) | DN object obtained.| 8465 8466**Error codes** 8467 8468For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8469 8470| ID | Error Message | 8471| -------- | ----------------------- | 8472| 19020001 | memory error. | 8473| 19020002 | runtime error. | 8474| 19030001 | crypto operation error. | 8475 8476**Example** 8477 8478```ts 8479import { cert } from '@kit.DeviceCertificateKit'; 8480import { BusinessError } from '@kit.BasicServicesKit'; 8481 8482// Convert the string into a Uint8Array. 8483function stringToUint8Array(str: string): Uint8Array { 8484 let arr: Array<number> = []; 8485 for (let i = 0, j = str.length; i < j; i++) { 8486 arr.push(str.charCodeAt(i)); 8487 } 8488 return new Uint8Array(arr); 8489} 8490 8491let crlData = '-----BEGIN X509 CRL-----\n' + 8492 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8493 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8494 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8495 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8496 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8497 'eavsH0Q3\n' + 8498 '-----END X509 CRL-----\n' 8499 8500let encodingBlob: cert.EncodingBlob = { 8501 data: stringToUint8Array(crlData), 8502 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8503 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8504}; 8505 8506async function certGetCertIssuerX500DistinguishedName() { 8507 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 8508 try { 8509 x509Crl = await cert.createX509CRL(encodingBlob); 8510 console.log('createX509CRL success'); 8511 let name = x509Crl.getRevokedCert(BigInt(1000)).getCertIssuerX500DistinguishedName(); 8512 } catch (error) { 8513 let e: BusinessError = error as BusinessError; 8514 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8515 } 8516} 8517``` 8518 8519### toString<sup>12+</sup> 8520 8521toString(): string 8522 8523Converts the object data into a string. 8524 8525**Atomic service API**: This API can be used in atomic services since API version 12. 8526 8527**System capability**: SystemCapability.Security.Cert 8528 8529**Return value** 8530 8531| Type | Description | 8532| ------- | ---------------------------------------------------- | 8533| string | String obtained.| 8534 8535**Error codes** 8536 8537For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8538 8539| ID | Error Message | 8540| -------- | ----------------------- | 8541| 19020001 | memory error. | 8542| 19020002 | runtime error. | 8543| 19030001 | crypto operation error. | 8544 8545**Example** 8546 8547```ts 8548import { cert } from '@kit.DeviceCertificateKit'; 8549import { BusinessError } from '@kit.BasicServicesKit'; 8550 8551// Convert the string into a Uint8Array. 8552function stringToUint8Array(str: string): Uint8Array { 8553 let arr: Array<number> = []; 8554 for (let i = 0, j = str.length; i < j; i++) { 8555 arr.push(str.charCodeAt(i)); 8556 } 8557 return new Uint8Array(arr); 8558} 8559 8560let crlData = '-----BEGIN X509 CRL-----\n' + 8561 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8562 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8563 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8564 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8565 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8566 'eavsH0Q3\n' + 8567 '-----END X509 CRL-----\n' 8568 8569let encodingBlob: cert.EncodingBlob = { 8570 data: stringToUint8Array(crlData), 8571 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8572 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8573}; 8574 8575async function certToString() { 8576 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 8577 try { 8578 x509Crl = await cert.createX509CRL(encodingBlob); 8579 console.log('createX509CRL success'); 8580 console.info('toString success: ' + JSON.stringify(x509Crl.getRevokedCert(BigInt(1000)).toString())); 8581 } catch (error) { 8582 let e: BusinessError = error as BusinessError; 8583 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8584 } 8585} 8586``` 8587 8588### hashCode<sup>12+</sup> 8589 8590hashCode(): Uint8Array 8591 8592Obtains the hash value of the data in DER format. 8593 8594**Atomic service API**: This API can be used in atomic services since API version 12. 8595 8596**System capability**: SystemCapability.Security.Cert 8597 8598**Return value** 8599 8600| Type | Description | 8601| ------- | ---------------------------------------------------- | 8602| Uint8Array | Hash value obtained.| 8603 8604**Error codes** 8605 8606For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8607 8608| ID | Error Message | 8609| -------- | ----------------------- | 8610| 19020001 | memory error. | 8611| 19020002 | runtime error. | 8612| 19030001 | crypto operation error. | 8613 8614**Example** 8615 8616```ts 8617import { cert } from '@kit.DeviceCertificateKit'; 8618import { BusinessError } from '@kit.BasicServicesKit'; 8619 8620// Convert the string into a Uint8Array. 8621function stringToUint8Array(str: string): Uint8Array { 8622 let arr: Array<number> = []; 8623 for (let i = 0, j = str.length; i < j; i++) { 8624 arr.push(str.charCodeAt(i)); 8625 } 8626 return new Uint8Array(arr); 8627} 8628 8629let crlData = '-----BEGIN X509 CRL-----\n' + 8630 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8631 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8632 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8633 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8634 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8635 'eavsH0Q3\n' + 8636 '-----END X509 CRL-----\n' 8637 8638let encodingBlob: cert.EncodingBlob = { 8639 data: stringToUint8Array(crlData), 8640 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8641 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8642}; 8643 8644async function certHashCode() { 8645 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 8646 try { 8647 x509Crl = await cert.createX509CRL(encodingBlob); 8648 console.log('createX509CRL success'); 8649 console.info('hashCode success: ' + JSON.stringify(x509Crl.getRevokedCert(BigInt(1000)).hashCode())); 8650 } catch (error) { 8651 let e: BusinessError = error as BusinessError; 8652 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8653 } 8654} 8655``` 8656 8657### getExtensionsObject<sup>12+</sup> 8658 8659getExtensionsObject(): CertExtension 8660 8661Obtains the certification extensions in DER format. 8662 8663**Atomic service API**: This API can be used in atomic services since API version 12. 8664 8665**System capability**: SystemCapability.Security.Cert 8666 8667**Return value** 8668 8669| Type | Description | 8670| ------- | ---------------------------------------------------- | 8671| [CertExtension](#certextension10) | Certificate extensions object obtained.| 8672 8673**Error codes** 8674 8675For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8676 8677| ID | Error Message | 8678| -------- | ----------------------- | 8679| 19020001 | memory error. | 8680| 19020002 | runtime error. | 8681| 19030001 | crypto operation error. | 8682 8683**Example** 8684 8685```ts 8686import { cert } from '@kit.DeviceCertificateKit'; 8687import { BusinessError } from '@kit.BasicServicesKit'; 8688 8689// Convert the string into a Uint8Array. 8690function stringToUint8Array(str: string): Uint8Array { 8691 let arr: Array<number> = []; 8692 for (let i = 0, j = str.length; i < j; i++) { 8693 arr.push(str.charCodeAt(i)); 8694 } 8695 return new Uint8Array(arr); 8696} 8697 8698let crlData = '-----BEGIN X509 CRL-----\n' + 8699 'MIINlTCCDH0CAQEwDQYJKoZIhvcNAQELBQAwTDELMAkGA1UEBhMCVVMxFTATBgNV\n' + 8700 'BAoTDERpZ2lDZXJ0IEluYzEmMCQGA1UEAxMdRGlnaUNl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8rMclE9gxamaa14\n' + 8759 'xBcNMjMxMjIwMTc0ODM2WjAhAhAOnKUlrCaxs+lRqLrBmk2PFw0yNDAxMzAxOTMw\n' + 8760 'MTVaMCECEAtYs/5ZRsrMAxQVDA44eWYXDTI0MDIwNjA2MjYwMFowIQIQDjrMV1d3\n' + 8761 '0NhxngX5rqqxjBcNMjQwMjIxMDc0ODEwWjAhAhAPGohz3+JyS6H4JzHCjLrXFw0y\n' + 8762 'NDAyMjgyMDQxMjZaMC8CEAqZ2QktAMprzZmtolbOXlgXDTI0MDIyOTE4MDYzMVow\n' + 8763 'DDAKBgNVHRUEAwoBBDAhAhAMAHgNfiburtKDp8OJuzRCFw0yNDAzMDQwNjA3MzJa\n' + 8764 'MCECEA/HgrXcSBqkb2JdfrFDAfgXDTI0MDMwNDA2MDczMlqgMDAuMB8GA1UdIwQY\n' + 8765 'MBaAFETZyEozjtNSjaeSlGEfmsilt+zLMAsGA1UdFAQEAgIFrDANBgkqhkiG9w0B\n' + 8766 'AQsFAAOCAQEAJ5rSr0Av5sH59J2LXW5hZ8SJTzDbR8ADdi/CCLolbUUnE0oaAZ+2\n' + 8767 '9z0niAD5m8HQikNz8K+FKAsQatN/CAj4bzRMeF37hQCiZpqNtxP69JDGeWpGPiH2\n' + 8768 'K/YfpzL9iSbBOxFmosxUX8J/iX36mCUl+3OUHh+qSYeElboxeAmTCnY5Pl5Bq9is\n' + 8769 'gp0MmzNYCo7GEFrtS03p2msK25uRqQl6Qn0NZS0yGjdUG7RTZe4xua5drjEkB1o/\n' + 8770 '15f+mtYj6DtWM1twi1q3VYVxhRSsk6XmmS0BViTEl+MT0BRAPwBSdlyt++1Pnnrd\n' + 8771 'BsQoO8O2EVpJ54fxKMCSDOkJf1hNCxi3eQ==\n' + 8772 '-----END X509 CRL-----\n'; 8773 8774let encodingBlob: cert.EncodingBlob = { 8775 data: stringToUint8Array(crlData), 8776 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8777 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8778}; 8779 8780async function certGetExtensionsObject() { 8781 let x509Crl: cert.X509CRL = {} as cert.X509CRL; 8782 try { 8783 x509Crl = await cert.createX509CRL(encodingBlob); 8784 console.log('createX509CRL success'); 8785 let object = x509Crl.getRevokedCert(BigInt('14091103387070223745671018446433705560')).getExtensionsObject(); 8786 } catch (error) { 8787 let e: BusinessError = error as BusinessError; 8788 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8789 } 8790} 8791``` 8792 8793## cert.createCertCRLCollection<sup>11+</sup> 8794 8795createCertCRLCollection(certs: Array\<X509Cert>, crls?: Array\<X509CRL>): CertCRLCollection 8796 8797Creates an object for a collection of X.509 certificates and CRLs. 8798 8799**Atomic service API**: This API can be used in atomic services since API version 12. 8800 8801**System capability**: SystemCapability.Security.Cert 8802 8803**Parameters** 8804 8805| Name | Type | Mandatory | Description | 8806| -------- | ------------------------------------- | ---- | ------------------------------ | 8807| certs | Array\<[X509Cert](#x509cert)> | Yes | X.509 certificates. | 8808| crls | Array\<[X509CRL](#x509crl11)> | No | X.509 CRLs. | 8809 8810**Return value** 8811 8812| Type | Description | 8813| ------------------ | -------------------- | 8814| [CertCRLCollection](#certcrlcollection11) | **CertCRLCollection** object created. | 8815 8816**Error codes** 8817 8818For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8819 8820| ID | Error Message | 8821| -------- | ----------------------- | 8822| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 8823| 19020001 | memory error. | 8824 8825**Example** 8826 8827```ts 8828import { cert } from '@kit.DeviceCertificateKit'; 8829import { BusinessError } from '@kit.BasicServicesKit'; 8830 8831// Convert the string into a Uint8Array. 8832function stringToUint8Array(str: string): Uint8Array { 8833 let arr: Array<number> = []; 8834 for (let i = 0, j = str.length; i < j; i++) { 8835 arr.push(str.charCodeAt(i)); 8836 } 8837 return new Uint8Array(arr); 8838} 8839 8840async function createX509CRL(): Promise<cert.X509CRL> { 8841 let crlData = '-----BEGIN X509 CRL-----\n' + 8842 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 8843 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 8844 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 8845 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 8846 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 8847 'eavsH0Q3\n' + 8848 '-----END X509 CRL-----\n'; 8849 8850 // Binary data of the CRL, which varies with the service. 8851 let encodingBlob: cert.EncodingBlob = { 8852 data: stringToUint8Array(crlData), 8853 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8854 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8855 }; 8856 let x509CRL: cert.X509CRL = {} as cert.X509CRL; 8857 try { 8858 x509CRL = await cert.createX509CRL(encodingBlob); 8859 } catch (err) { 8860 let e: BusinessError = err as BusinessError; 8861 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8862 } 8863 return x509CRL; 8864} 8865 8866async function createX509Cert(): Promise<cert.X509Cert> { 8867 let certData = '-----BEGIN CERTIFICATE-----\n' + 8868 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 8869 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 8870 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 8871 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 8872 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 8873 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 8874 'Qw==\n' + 8875 '-----END CERTIFICATE-----\n'; 8876 8877 let encodingBlob: cert.EncodingBlob = { 8878 data: stringToUint8Array(certData), 8879 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8880 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8881 }; 8882 8883 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 8884 try { 8885 x509Cert = await cert.createX509Cert(encodingBlob); 8886 } catch (err) { 8887 let e: BusinessError = err as BusinessError; 8888 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8889 } 8890 return x509Cert; 8891} 8892 8893async function createCollection() { 8894 const x509Cert = await createX509Cert(); 8895 const x509CRL = await createX509CRL(); 8896 try { 8897 const collection: cert.CertCRLCollection = cert.createCertCRLCollection([x509Cert], [x509CRL]); 8898 console.log('createCertCRLCollection success'); 8899 } catch (err) { 8900 console.error('createCertCRLCollection failed'); 8901 } 8902} 8903``` 8904 8905## CertCRLCollection<sup>11+</sup> 8906 8907Provides APIs for locating certificates or CRLs in a **CertCRLCollection** object. 8908 8909### selectCerts<sup>11+</sup> 8910 8911selectCerts(param: X509CertMatchParameters): Promise\<Array\<X509Cert>> 8912 8913Selects certificates that match the specified parameters. This API uses a promise to return the result. 8914 8915**Atomic service API**: This API can be used in atomic services since API version 12. 8916 8917**System capability**: SystemCapability.Security.Cert 8918 8919**Parameters** 8920 8921| Name | Type | Mandatory | Description | 8922| --------- | ------------------------------- | ---- | ------------ | 8923| param | [X509CertMatchParameters](#x509certmatchparameters11) | Yes | Parameters used to match the certificates. | 8924 8925**Return value** 8926 8927| Type | Description | 8928| --------------------------------------- | --------------------------------------- | 8929| Promise\<Array\<[X509Cert](#x509cert)>> | Promise used to return the matched certificates. | 8930 8931**Error codes** 8932 8933For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 8934 8935| ID | Error Message | 8936| -------- | ----------------------- | 8937| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 8938| 19020001 | memory error. | 8939| 19030001 | crypto operation error. | 8940 8941**Example** 8942 8943```ts 8944import { cert } from '@kit.DeviceCertificateKit'; 8945import { BusinessError } from '@kit.BasicServicesKit'; 8946 8947// Convert the string into a Uint8Array. 8948function stringToUint8Array(str: string): Uint8Array { 8949 let arr: Array<number> = []; 8950 for (let i = 0, j = str.length; i < j; i++) { 8951 arr.push(str.charCodeAt(i)); 8952 } 8953 return new Uint8Array(arr); 8954} 8955 8956async function createX509Cert(): Promise<cert.X509Cert> { 8957 let certData = '-----BEGIN CERTIFICATE-----\n' + 8958 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 8959 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 8960 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 8961 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 8962 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 8963 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 8964 'Qw==\n' + 8965 '-----END CERTIFICATE-----\n'; 8966 8967 let encodingBlob: cert.EncodingBlob = { 8968 data: stringToUint8Array(certData), 8969 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 8970 encodingFormat: cert.EncodingFormat.FORMAT_PEM 8971 }; 8972 8973 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 8974 try { 8975 x509Cert = await cert.createX509Cert(encodingBlob); 8976 } catch (err) { 8977 let e: BusinessError = err as BusinessError; 8978 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 8979 } 8980 return x509Cert; 8981} 8982 8983async function selectCerts() { 8984 const x509Cert = await createX509Cert(); 8985 const collection = cert.createCertCRLCollection([x509Cert]); 8986 8987 try { 8988 const param: cert.X509CertMatchParameters = { 8989 x509Cert, 8990 validDate: '20231121074700Z', 8991 issuer: new Uint8Array([0x30, 0x1a, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x45, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41]), 8992 subject: new Uint8Array([0x30, 0x1a, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x45, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41]), 8993 publicKeyAlgID: '1.2.840.10045.2.1' 8994 }; 8995 const certs = await collection.selectCerts(param); 8996 console.log('call selectCerts success'); 8997 } catch (err) { 8998 console.error('call selectCerts failed'); 8999 } 9000} 9001``` 9002 9003### selectCerts<sup>11+</sup> 9004 9005selectCerts(param: X509CertMatchParameters, callback: AsyncCallback\<Array\<X509Cert>>): void 9006 9007Selects certificates that match the specified parameters. This API uses an asynchronous callback to return the result. 9008 9009**Atomic service API**: This API can be used in atomic services since API version 12. 9010 9011**System capability**: SystemCapability.Security.Cert 9012 9013**Parameters** 9014 9015| Name | Type | Mandatory | Description | 9016| --------- | ------------------------------- | ---- | ----------------- | 9017| param | [X509CertMatchParameters](#x509certmatchparameters11) | Yes | Parameters used to match the certificates. | 9018| callback | AsyncCallback\<Array\<[X509Cert](#x509cert)>> | Yes | Callback used to return the matched certificates. | 9019 9020**Error codes** 9021 9022For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9023 9024| ID | Error Message | 9025| -------- | ----------------------- | 9026| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9027| 19020001 | memory error. | 9028| 19030001 | crypto operation error. | 9029 9030**Example** 9031 9032```ts 9033import { cert } from '@kit.DeviceCertificateKit'; 9034import { BusinessError } from '@kit.BasicServicesKit'; 9035 9036// Convert the string into a Uint8Array. 9037function stringToUint8Array(str: string): Uint8Array { 9038 let arr: Array<number> = []; 9039 for (let i = 0, j = str.length; i < j; i++) { 9040 arr.push(str.charCodeAt(i)); 9041 } 9042 return new Uint8Array(arr); 9043} 9044 9045async function createX509Cert(): Promise<cert.X509Cert> { 9046 let certData = '-----BEGIN CERTIFICATE-----\n' + 9047 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 9048 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 9049 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 9050 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 9051 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 9052 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 9053 'Qw==\n' + 9054 '-----END CERTIFICATE-----\n'; 9055 9056 let encodingBlob: cert.EncodingBlob = { 9057 data: stringToUint8Array(certData), 9058 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 9059 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9060 }; 9061 9062 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 9063 try { 9064 x509Cert = await cert.createX509Cert(encodingBlob); 9065 } catch (err) { 9066 let e: BusinessError = err as BusinessError; 9067 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9068 } 9069 return x509Cert; 9070} 9071 9072async function selectCerts() { 9073 const x509Cert = await createX509Cert(); 9074 const collection = cert.createCertCRLCollection([x509Cert]); 9075 // The value varies with the service. 9076 const param: cert.X509CertMatchParameters = { 9077 x509Cert, 9078 validDate: '20231121074700Z', 9079 issuer: new Uint8Array([0x30, 0x1a, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x45, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41]), 9080 subject: new Uint8Array([0x30, 0x1a, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0F, 0x45, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41]), 9081 publicKeyAlgID: '1.2.840.10045.2.1' 9082 }; 9083 collection.selectCerts(param, (err, certs) => { 9084 if (err) { 9085 console.error('selectCerts failed, errCode: ' + err.code + ', errMsg: ' + err.message); 9086 } else { 9087 console.log('selectCerts success'); 9088 } 9089 }); 9090} 9091``` 9092 9093### selectCRLs<sup>11+</sup> 9094 9095selectCRLs(param: X509CRLMatchParameters): Promise\<Array\<X509CRL>> 9096 9097Selects CRLs that match the specified parameters. This API uses a promise to return the result. 9098 9099**Atomic service API**: This API can be used in atomic services since API version 12. 9100 9101**System capability**: SystemCapability.Security.Cert 9102 9103**Parameters** 9104 9105| Name | Type | Mandatory | Description | 9106| --------- | ------------------------------- | ---- | ------------ | 9107| param | [X509CRLMatchParameters](#x509crlmatchparameters11) | Yes | Parameters used to match the CRLs. | 9108 9109**Return value** 9110 9111| Type | Description | 9112| -------------- | ----------- | 9113| Promise\<Array\<[X509CRL](#x509crl11)>> | Promise used to return the matched CRLs. | 9114 9115**Error codes** 9116 9117For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9118 9119| ID | Error Message | 9120| -------- | ----------------------- | 9121| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9122| 19020001 | memory error. | 9123| 19030001 | crypto operation error. | 9124 9125**Example** 9126 9127```ts 9128import { cert } from '@kit.DeviceCertificateKit'; 9129import { BusinessError } from '@kit.BasicServicesKit'; 9130 9131// Convert the string into a Uint8Array. 9132function stringToUint8Array(str: string): Uint8Array { 9133 let arr: Array<number> = []; 9134 for (let i = 0, j = str.length; i < j; i++) { 9135 arr.push(str.charCodeAt(i)); 9136 } 9137 return new Uint8Array(arr); 9138} 9139 9140async function createX509CRL(): Promise<cert.X509CRL> { 9141 let crlData = '-----BEGIN X509 CRL-----\n' + 9142 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 9143 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 9144 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 9145 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 9146 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 9147 'eavsH0Q3\n' + 9148 '-----END X509 CRL-----\n'; 9149 9150 // Binary data of the CRL, which varies with the service. 9151 let encodingBlob: cert.EncodingBlob = { 9152 data: stringToUint8Array(crlData), 9153 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 9154 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9155 }; 9156 let x509CRL: cert.X509CRL = {} as cert.X509CRL; 9157 try { 9158 x509CRL = await cert.createX509CRL(encodingBlob); 9159 } catch (err) { 9160 let e: BusinessError = err as BusinessError; 9161 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9162 } 9163 return x509CRL; 9164} 9165 9166async function createX509Cert(): Promise<cert.X509Cert> { 9167 const certData = "-----BEGIN CERTIFICATE-----\r\n" + 9168 "MIIC8TCCAdmgAwIBAgIIFB75m06RTHwwDQYJKoZIhvcNAQELBQAwWDELMAkGA1UE\r\n" + 9169 "BhMCQ04xEDAOBgNVBAgTB0ppYW5nc3UxEDAOBgNVBAcTB05hbmppbmcxCzAJBgNV\r\n" + 9170 "BAoTAnRzMQswCQYDVQQLEwJ0czELMAkGA1UEAxMCdHMwHhcNMjMxMTIzMDMzMjAw\r\n" + 9171 "WhcNMjQxMTIzMDMzMjAwWjBhMQswCQYDVQQGEwJDTjEQMA4GA1UECBMHSmlhbmdz\r\n" + 9172 "dTEQMA4GA1UEBxMHTmFuamluZzEMMAoGA1UEChMDdHMxMQwwCgYDVQQLEwN0czEx\r\n" + 9173 "EjAQBgNVBAMTCTEyNy4wLjAuMTAqMAUGAytlcAMhALsWnY9cMNC6jzduM69vI3Ej\r\n" + 9174 "pUlgHtEHS8kRfmYBupJSo4GvMIGsMAwGA1UdEwEB/wQCMAAwHQYDVR0OBBYEFNSg\r\n" + 9175 "poQvfxR8A1Y4St8NjOHkRpm4MAsGA1UdDwQEAwID+DAnBgNVHSUEIDAeBggrBgEF\r\n" + 9176 "BQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEyNy4wLjAuMTAR\r\n" + 9177 "BglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0\r\n" + 9178 "ZTANBgkqhkiG9w0BAQsFAAOCAQEAfnLmPF6BtAUCZ9pjt1ITdXc5M4LJfMw5IPcv\r\n" + 9179 "fUAvhdaUXtqBQcjGCWtDdhyb1n5Xp+N7oKz/Cnn0NGFTwVArtFiQ5NEP2CmrckLh\r\n" + 9180 "Da4VnsDFU+zx2Bbfwo5Ms7iArxyx0fArbMZzN9D1lZcVjiIxp1+3k1/0sdCemcY/\r\n" + 9181 "y7mw5NwkcczLWLBZl1/Ho8b4dlo1wTA7TZk9uu8UwYBwXDrQe6S9rMcvMcRKiJ9e\r\n" + 9182 "V4SYZIO7ihr8+n4LQDQP+spvX4cf925a3kyZrftfvGCJ2ZNwvsPhyumYhaBqAgSy\r\n" + 9183 "Up2BImymAqPi157q9EeYcQz170TtDZHGmjYzdQxhOAHRb6/IdQ==\r\n" + 9184 "-----END CERTIFICATE-----\r\n"; 9185 const certEncodingBlob: cert.EncodingBlob = { 9186 data: stringToUint8Array(certData), 9187 encodingFormat: cert.EncodingFormat.FORMAT_PEM, 9188 }; 9189 9190 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 9191 try { 9192 x509Cert = await cert.createX509Cert(certEncodingBlob); 9193 console.log('createX509Cert success'); 9194 } catch (err) { 9195 console.error('createX509Cert failed'); 9196 } 9197 return x509Cert; 9198} 9199 9200async function selectCRLs() { 9201 const x509CRL = await createX509CRL(); 9202 const x509Cert = await createX509Cert(); 9203 const collection = cert.createCertCRLCollection([], [x509CRL]); 9204 9205 const param: cert.X509CRLMatchParameters = { 9206 issuer: [new Uint8Array([0x30, 0x58, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4E, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x4A, 0x69, 0x61, 0x6E, 0x67, 0x73, 0x75, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x4E, 0x61, 0x6E, 0x6A, 0x69, 0x6E, 0x67, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x02, 0x74, 0x73, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x02, 0x74, 0x73, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x02, 0x74, 0x73])], 9207 x509Cert: x509Cert 9208 } 9209 try { 9210 const crls = await collection.selectCRLs(param); 9211 console.log('selectCRLs success'); 9212 } catch (err) { 9213 console.error('selectCRLs failed'); 9214 } 9215} 9216``` 9217 9218### selectCRLs<sup>11+</sup> 9219 9220selectCRLs(param: X509CRLMatchParameters, callback: AsyncCallback\<Array\<X509CRL>>): void 9221 9222Selects CRLs that match the specified parameters. This API uses an asynchronous callback to return the result. 9223 9224**Atomic service API**: This API can be used in atomic services since API version 12. 9225 9226**System capability**: SystemCapability.Security.Cert 9227 9228**Parameters** 9229 9230| Name | Type | Mandatory | Description | 9231| --------- | ------------------------------- | ---- | ----------------- | 9232| param | [X509CRLMatchParameters](#x509crlmatchparameters11) | Yes | Parameters used to match the CRLs. | 9233| callback | AsyncCallback\<Array\<[X509CRL](#x509crl11)>> | Yes | Callback used to return the matched CRLs. | 9234 9235**Error codes** 9236 9237For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9238 9239| ID | Error Message | 9240| -------- | ----------------------- | 9241| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9242| 19020001 | memory error. | 9243| 19030001 | crypto operation error. | 9244 9245**Example** 9246 9247```ts 9248import { cert } from '@kit.DeviceCertificateKit'; 9249import { BusinessError } from '@kit.BasicServicesKit'; 9250 9251// Convert the string into a Uint8Array. 9252function stringToUint8Array(str: string): Uint8Array { 9253 let arr: Array<number> = []; 9254 for (let i = 0, j = str.length; i < j; i++) { 9255 arr.push(str.charCodeAt(i)); 9256 } 9257 return new Uint8Array(arr); 9258} 9259 9260async function createX509CRL(): Promise<cert.X509CRL> { 9261 let crlData = '-----BEGIN X509 CRL-----\n' + 9262 'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' + 9263 'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' + 9264 'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' + 9265 'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' + 9266 '5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' + 9267 'eavsH0Q3\n' + 9268 '-----END X509 CRL-----\n'; 9269 9270 // Binary data of the CRL, which varies with the service. 9271 let encodingBlob: cert.EncodingBlob = { 9272 data: stringToUint8Array(crlData), 9273 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 9274 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9275 }; 9276 let x509CRL: cert.X509CRL = {} as cert.X509CRL; 9277 try { 9278 x509CRL = await cert.createX509CRL(encodingBlob); 9279 } catch (err) { 9280 let e: BusinessError = err as BusinessError; 9281 console.error('createX509CRL failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9282 } 9283 return x509CRL; 9284} 9285 9286async function createX509Cert(): Promise<cert.X509Cert> { 9287 const certData = "-----BEGIN CERTIFICATE-----\r\n" + 9288 "MIIC8TCCAdmgAwIBAgIIFB75m06RTHwwDQYJKoZIhvcNAQELBQAwWDELMAkGA1UE\r\n" + 9289 "BhMCQ04xEDAOBgNVBAgTB0ppYW5nc3UxEDAOBgNVBAcTB05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/IdQ==\r\n" + 9304 "-----END CERTIFICATE-----\r\n"; 9305 const certEncodingBlob: cert.EncodingBlob = { 9306 data: stringToUint8Array(certData), 9307 encodingFormat: cert.EncodingFormat.FORMAT_PEM, 9308 }; 9309 9310 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 9311 try { 9312 x509Cert = await cert.createX509Cert(certEncodingBlob); 9313 console.log('createX509Cert success'); 9314 } catch (err) { 9315 console.error('createX509Cert failed'); 9316 } 9317 return x509Cert; 9318} 9319 9320async function selectCRLs() { 9321 const x509CRL = await createX509CRL(); 9322 const x509Cert = await createX509Cert(); 9323 const collection = cert.createCertCRLCollection([], [x509CRL]); 9324 9325 const param: cert.X509CRLMatchParameters = { 9326 issuer: [new Uint8Array([0x30, 0x58, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x43, 0x4E, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x4A, 0x69, 0x61, 0x6E, 0x67, 0x73, 0x75, 0x31, 0x10, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x07, 0x4E, 0x61, 0x6E, 0x6A, 0x69, 0x6E, 0x67, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x02, 0x74, 0x73, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x02, 0x74, 0x73, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x02, 0x74, 0x73])], 9327 x509Cert: x509Cert 9328 } 9329 collection.selectCRLs(param, (err, crls) => { 9330 if (err) { 9331 console.error('selectCRLs failed, errCode: ' + err.code + ', errMsg: ' + err.message); 9332 } else { 9333 console.log('selectCRLs success'); 9334 } 9335 }); 9336} 9337``` 9338 9339## cert.createX509CertChain<sup>11+</sup> 9340 9341createX509CertChain(inStream: EncodingBlob): Promise\<X509CertChain> 9342 9343Creates an X.509 certificate chain instance. This API uses a promise to return the result. 9344 9345**Atomic service API**: This API can be used in atomic services since API version 12. 9346 9347**System capability**: SystemCapability.Security.Cert 9348 9349**Parameters** 9350 9351| Name | Type | Mandatory | Description | 9352| -------- | ----------------------------- | ---- | -------------------- | 9353| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data. | 9354 9355**Return value** 9356 9357| Type | Description | 9358| ------------------------------- | ---------------- | 9359| Promise\<[X509CertChain](#x509certchain11)> | Promise used to return the **X509CertChain** object created. | 9360 9361**Error codes** 9362 9363For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9364 9365| ID | Error Message | 9366| -------- | ------------- | 9367| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9368| 19020001 | memory error. | 9369| 19030001 | crypto operation error. | 9370 9371**Example** 9372 9373```ts 9374import { cert } from '@kit.DeviceCertificateKit'; 9375import { BusinessError } from '@kit.BasicServicesKit'; 9376 9377// Convert the string into a Uint8Array. 9378function stringToUint8Array(str: string): Uint8Array { 9379 let arr: Array<number> = []; 9380 for (let i = 0, j = str.length; i < j; i++) { 9381 arr.push(str.charCodeAt(i)); 9382 } 9383 return new Uint8Array(arr); 9384} 9385 9386async function createX509CertChain(): Promise<cert.X509CertChain> { 9387 let certChainData = "-----BEGIN CERTIFICATE-----\n" + 9388 "MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n" + 9389 "BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n" + 9390 "ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n" + 9391 "MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRA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NMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n" + 9407 "DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n" + 9408 "iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n" + 9409 "-----END CERTIFICATE-----\n" + 9410 "-----BEGIN CERTIFICATE-----\n" + 9411 "MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 9412 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 9413 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n" + 9414 "OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 9415 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n" + 9416 "AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n" + 9417 "YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n" + 9418 "SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n" + 9419 "TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n" + 9420 "STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n" + 9421 "nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n" + 9422 "pBUM2DuBKwIDAQ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CgSbQroAR2mV\n" + 9439 "xjoE\n" + 9440 "-----END CERTIFICATE-----\n"; 9441 9442 // Certificate chain binary data, which varies with the service. 9443 let encodingBlob: cert.EncodingBlob = { 9444 data: stringToUint8Array(certChainData), 9445 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 9446 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9447 }; 9448 let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; 9449 try { 9450 x509CertChain = await cert.createX509CertChain(encodingBlob); 9451 } catch (error) { 9452 let e: BusinessError = error as BusinessError; 9453 console.error('createX509CertChain failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9454 } 9455 return x509CertChain; 9456} 9457 9458createX509CertChain(); 9459``` 9460 9461## cert.createX509CertChain<sup>11+</sup> 9462 9463createX509CertChain(inStream: EncodingBlob, callback: AsyncCallback\<X509CertChain>): void 9464 9465Creates an X.509 certificate chain instance. This API uses an asynchronous callback to return the result. 9466 9467**Atomic service API**: This API can be used in atomic services since API version 12. 9468 9469**System capability**: SystemCapability.Security.Cert 9470 9471**Parameters** 9472 9473| Name | Type | Mandatory | Description | 9474| -------- | ------------------------------------- | ---- | -------------------------- | 9475| inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data. | 9476| callback | AsyncCallback\<[X509CertChain](#x509certchain11)> | Yes | Callback used to return the **X509CertChain** object created. | 9477 9478**Error codes** 9479 9480For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9481 9482| ID | Error Message | 9483| -------- | ------------- | 9484| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9485| 19020001 | memory error. | 9486| 19030001 | crypto operation error. | 9487 9488**Example** 9489 9490```ts 9491import { cert } from '@kit.DeviceCertificateKit'; 9492 9493// Convert the string into a Uint8Array. 9494function stringToUint8Array(str: string): Uint8Array { 9495 let arr: Array<number> = []; 9496 for (let i = 0, j = str.length; i < j; i++) { 9497 arr.push(str.charCodeAt(i)); 9498 } 9499 return new Uint8Array(arr); 9500} 9501 9502let certChainData = "-----BEGIN CERTIFICATE-----\n" + 9503 "MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n" + 9504 "BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n" + 9505 "ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n" + 9506 "MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n" + 9507 "Z3N1MRAwDgYDVQQHEwdOYW5qaW5nMQwwCgYDVQQKEwN0czMxDDAKBgNVBAsTA3Rz\n" + 9508 "MzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" + 9509 "CgKCAQEAtt+2QxUevbolYLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLR\n" + 9510 "p26LFV/F8ebwPyo8YEBKSwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmc\n" + 9511 "rVvLBNMeVnxY86xHpo0MTNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0j\n" + 9512 "zT9GjeUP6JLdLFUZJKUPSTK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/U\n" + 9513 "T+p5ThAMH593zszlz330nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI3\n" + 9514 "8MFQFJKvRHfgTAvVsvAvpBUM2DuBKwIDAQABo4GsMIGpMAkGA1UdEwQCMAAwHQYD\n" + 9515 "VR0OBBYEFDfsHTMZwoA6eaDFlBUyDpka+sYtMAsGA1UdDwQEAwID+DAnBgNVHSUE\n" + 9516 "IDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEy\n" + 9517 "Ny4wLjAuMTARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBj\n" + 9518 "ZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEAp5vTvXrt8ZpgRJVtzv9ss0lJ\n" + 9519 "izp1fJf+ft5cDXrs7TSD5oHrSW2vk/ZieIMhexU4LFwhs4OE7jK6pgI48Dseqxx7\n" + 9520 "B/KktxhVMJUmVXd9Ayjp6f+BtZlIk0cArPuoXToXjsV8caTGBXHRdzxpAk/w9syc\n" + 9521 "GYrbH9TrdNMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n" + 9522 "DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n" + 9523 "iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n" + 9524 "-----END CERTIFICATE-----\n" + 9525 "-----BEGIN CERTIFICATE-----\n" + 9526 "MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 9527 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 9528 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n" + 9529 "OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 9530 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n" + 9531 "AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n" + 9532 "YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n" + 9533 "SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n" + 9534 "TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n" + 9535 "STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n" + 9536 "nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n" + 9537 "pBUM2DuBKwIDAQABo28wbTAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBQ37B0zGcKA\n" + 9538 "OnmgxZQVMg6ZGvrGLTALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEBBAQDAgAHMB4G\n" + 9539 "CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n" + 9540 "b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n" + 9541 "uKPWR9dKBA==\n" + 9542 "-----END CERTIFICATE-----\n" + 9543 "-----BEGIN CERTIFICATE-----\n" + 9544 "MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 9545 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 9546 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n" + 9547 "MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 9548 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n" + 9549 "AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n" + 9550 "klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n" + 9551 "St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n" + 9552 "AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n" + 9553 "KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n" + 9554 "xjoE\n" + 9555 "-----END CERTIFICATE-----\n"; 9556 9557// Certificate chain binary data, which varies with the service. 9558let encodingBlob: cert.EncodingBlob = { 9559 data: stringToUint8Array(certChainData), 9560 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 9561 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9562}; 9563 9564cert.createX509CertChain(encodingBlob, (err, certChain) => { 9565 if (err) { 9566 console.error('createX509CertChain failed, errCode: ' + err.code + ', errMsg: ' + err.message); 9567 } else { 9568 console.log('createX509CertChain success'); 9569 } 9570}); 9571``` 9572 9573## cert.createX509CertChain<sup>11+</sup> 9574 9575createX509CertChain(certs: Array\<X509Cert>): X509CertChain 9576 9577Creates an X.509 certificate chain object based on the specified certificates. This API returns the result synchronously. 9578 9579**Atomic service API**: This API can be used in atomic services since API version 12. 9580 9581**System capability**: SystemCapability.Security.Cert 9582 9583**Parameters** 9584 9585| Name | Type | Mandatory | Description | 9586| -------- | -------------------- | ---- | -------------------------- | 9587| certs | Array\<[X509Cert](#x509cert)> | Yes | Array of X.509 certificates. | 9588 9589**Return value** 9590 9591| Type | Description | 9592| --------------------------------- | -------------------- | 9593| [X509CertChain](#x509certchain11) | **X509CertChain** object created. | 9594 9595**Error codes** 9596 9597For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9598 9599| ID | Error Message | 9600| -------- | ------------- | 9601| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9602| 19020001 | memory error. | 9603| 19030001 | crypto operation error. | 9604 9605**Example** 9606 9607```ts 9608import { cert } from '@kit.DeviceCertificateKit'; 9609import { BusinessError } from '@kit.BasicServicesKit'; 9610 9611// Convert the string into a Uint8Array. 9612function stringToUint8Array(str: string): Uint8Array { 9613 let arr: Array<number> = []; 9614 for (let i = 0, j = str.length; i < j; i++) { 9615 arr.push(str.charCodeAt(i)); 9616 } 9617 return new Uint8Array(arr); 9618} 9619 9620async function createX509Cert(): Promise<cert.X509Cert> { 9621 let certData = '-----BEGIN CERTIFICATE-----\n' + 9622 'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' + 9623 'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' + 9624 'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' + 9625 'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' + 9626 'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' + 9627 'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' + 9628 'Qw==\n' + 9629 '-----END CERTIFICATE-----\n'; 9630 9631 // Certificate binary data, which varies with the service. 9632 let encodingBlob: cert.EncodingBlob = { 9633 data: stringToUint8Array(certData), 9634 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 9635 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9636 }; 9637 9638 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 9639 try { 9640 x509Cert = await cert.createX509Cert(encodingBlob); 9641 } catch (error) { 9642 let e: BusinessError = error as BusinessError; 9643 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9644 } 9645 return x509Cert; 9646} 9647 9648async function createX509CertChain(): Promise<cert.X509CertChain> { 9649 const x509Cert = await createX509Cert(); 9650 let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; 9651 try { 9652 x509CertChain = cert.createX509CertChain([x509Cert]); 9653 } catch (error) { 9654 let e: BusinessError = error as BusinessError; 9655 console.error('createX509CertChain failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9656 } 9657 return x509CertChain; 9658} 9659 9660createX509CertChain(); 9661``` 9662 9663## cert.buildX509CertChain<sup>12+</sup> 9664 9665buildX509CertChain(param: [CertChainBuildParameters](#certchainbuildparameters12)): Promise\<CertChainBuildResult> 9666 9667Builds an X.509 certificate chain with a **CertChainBuildParameters** object. This API uses a promise to return the result. 9668 9669**Atomic service API**: This API can be used in atomic services since API version 12. 9670 9671**System capability**: SystemCapability.Security.Cert 9672 9673**Parameters** 9674 9675| Name | Type | Mandatory | Description | 9676| -------- | -------------------- | ---- | -------------------------- | 9677| param | [CertChainBuildParameters](#certchainbuildparameters12) | Yes | Object used to build the certificate chain. | 9678 9679**Return value** 9680 9681| Type | Description | 9682| --------------------------------- | -------------------- | 9683| [CertChainBuildResult](#certchainbuildresult12) | **X509CertChain** object created. | 9684 9685**Error codes** 9686 9687For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9688 9689| ID | Error Message | 9690| -------- | ------------------------------------------------- | 9691| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9692| 19020001 | memory error. | 9693| 19020002 | runtime error. | 9694| 19030001 | crypto operation error. | 9695| 19030002 | the certificate signature verification failed. | 9696| 19030003 | the certificate has not taken effect. | 9697| 19030004 | the certificate has expired. | 9698| 19030005 | failed to obtain the certificate issuer. | 9699| 19030006 | the key cannot be used for signing a certificate. | 9700| 19030007 | the key cannot be used for digital signature. | 9701 9702**Example** 9703 9704```ts 9705import { cert } from '@kit.DeviceCertificateKit'; 9706import { BusinessError } from '@kit.BasicServicesKit'; 9707 9708// Convert the string into a Uint8Array. 9709function stringToUint8Array(str: string): Uint8Array { 9710 let arr: Array<number> = []; 9711 for (let i = 0, j = str.length; i < j; i++) { 9712 arr.push(str.charCodeAt(i)); 9713 } 9714 return new Uint8Array(arr); 9715} 9716 9717// Certificate chain data. 9718let certPem = '-----BEGIN CERTIFICATE-----\n' + 9719 'MIIDTjCCAjagAwIBAgIBBDANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 9720 'IENBMB4XDTI0MDMxOTAyMDQwMVoXDTM0MDMxNzAyMDQwMVowEjEQMA4GA1UEAwwH\n' + 9721 'ZGV2aWNlMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMIXL3e7UE/c\n' + 9722 'Z1dPVgRZ5L8gsQ/azuYVBvoFf7o8ksYrL7G1+qZIJjVRqZkuTirLW4GicbkIkPNW\n' + 9723 'eix5cDhkjkC+q5SBCOrSSTTlvX3xcOY1gMlA5MgeBfGixFusq4d5VPF2KceZ20/a\n' + 9724 'ygwGD0Uv0X81OERyPom/dYdJUvfaD9ifPFJ1fKIj/cPFG3yJK/ojpEfndZNdESQL\n' + 9725 'TkoDekilg2UGOLtY6fb9Ns37ncuIj33gCS/R9m1tgtmqCTcgOQ4hwKhjVF3InmPO\n' + 9726 '2BbWKvD1RUX+rHC2a2HHDQILOOtDTy8dHvE+qZlK0efrpRgoFEERJAGPi1GDGWiA\n' + 9727 '7UX1c4MCxIECAwEAAaOBrjCBqzAJBgNVHRMEAjAAMB0GA1UdDgQWBBQbkAcMT7ND\n' + 9728 'fGp3VPFzYHppZ1zxLTAfBgNVHSMEGDAWgBR0W/koCbvDtFGHUQZLM3j6HKsW2DAd\n' + 9729 'BgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwCwYDVR0PBAQDAgeAMDIGCCsG\n' + 9730 'AQUFBwEBBCYwJDAiBggrBgEFBQcwAYYWaHR0cHM6Ly8xMjcuMC4wLjE6OTk5OTAN\n' + 9731 'BgkqhkiG9w0BAQsFAAOCAQEAF1OTzTmbklFOdZCxrF3zg9owUPJR5RB+PbuBlUfI\n' + 9732 '8tkGXkMltQ8PN1dv6Cq+d8BluiJdWEzqVoJa/e5SHHJyYQSOhlurRG0GBXllVQ1I\n' + 9733 'n1PFaI40+9X2X6wrEcdC5nbzogR1jSiksCiTcARMddj0Xrp5FMrFaaGY8M/xqzdW\n' + 9734 'LTDl4nfbuxtA71cIjnE4kOcaemly9/S2wYWdPktsPxQPY1nPUOeJFI7o0sH3rK0c\n' + 9735 'JSqtgAG8vnjK+jbx9RpkgqCsXgUbIahL573VTgxrNrsRjCuVal7XVxl/xOKXr6Er\n' + 9736 'Gpc+OCrXbHNZkUQE5fZH3yL2tXd7EASEb6J3aEWHfF8YBA==\n' + 9737 '-----END CERTIFICATE-----'; 9738 9739let caPem = '-----BEGIN CERTIFICATE-----\n' + 9740'MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdSb290\n' + 9741'IENBMB4XDTI0MDMxOTAyMDIyNFoXDTM0MDMxNzAyMDIyNFowEjEQMA4GA1UEAwwH\n' + 9742'Um9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALxI5SDvRfKU\n' + 9743'6XaTeyh2LHlUK0rVSeYfXkYf5Mc3Pgucg+ewzQjxkACMx5NYaW1zfGDNPG1i5IZl\n' + 9744'cPeWNz1Tm2g6wTd+LyNoNOOmwfLV8pLXSfAukgNrBREf3BzVrbu7hvPd2MmLH23H\n' + 9745'OBM9uDPTIqu3n2CDN2EzwULjaSk2g+jvhVKsDLInu5uKPmZBFhs1FWKgcnVnlbi1\n' + 9746'AyAx4efheits6EO70oV6UufCEtS1VsBXQHZRAG4ogshWldRBVNxkU6yHAfg0mM/5\n' + 9747'EhrZsfh51fWqlrhNWrInjgNV3xIt5ebTIgKZWUlSVHEA/UqDoGfY+CsAJdteZWOW\n' + 9748'KjsrC/DK2O0CAwEAAaNgMF4wHQYDVR0OBBYEFHRb+SgJu8O0UYdRBkszePocqxbY\n' + 9749'MB8GA1UdIwQYMBaAFHRb+SgJu8O0UYdRBkszePocqxbYMA8GA1UdEwEB/wQFMAMB\n' + 9750'Af8wCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBCwUAA4IBAQAKOT1ObfQNMN2wdfHq\n' + 9751'PQgFDDp6rBMbZe70LswPirSXljo4S/vfbG+gBoWCdu/SfsV+lyP75kg1wX0IQvzW\n' + 9752'xYNh864dgqPmGd0v8TIfM0UT0PpnowUyBHQ+E7LNYIOh/kjHbl3oERdEFA2PUyE9\n' + 9753'j3GLdg8oe/LqhEQCSAlH+v2RQgBZ9eVN+mSdUxwywm9U3acb0uqVkGiWK/ywumpg\n' + 9754'AmIZLMJtMVvg8uDkfy16Z4lChTEdNaJVUqPczUNk2kHXIF4we4be9HoOuTVz/SD/\n' + 9755'IsOhXn/BjS3jnhyS9fxo+opJf9zVTWI02Hlh1WVVtH/m3nIZblyAJhcjCHA2wZSz\n' + 9756'sSus\n' + 9757'-----END CERTIFICATE-----'; 9758 9759async function createX509Cert(certData: string): Promise<cert.X509Cert> { 9760 // Certificate binary data, which varies with the service. 9761 let encodingBlob: cert.EncodingBlob = { 9762 data: stringToUint8Array(certData), 9763 // Set the encoding format, which can be FORMAT_PEM or FORMAT_DER. 9764 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9765 }; 9766 9767 let x509Cert: cert.X509Cert = {} as cert.X509Cert; 9768 try { 9769 x509Cert = await cert.createX509Cert(encodingBlob); 9770 } catch (error) { 9771 let e: BusinessError = error as BusinessError; 9772 console.error('createX509Cert failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9773 } 9774 return x509Cert; 9775} 9776 9777async function buildX509CertChain() { 9778 try { 9779 const caCert = await createX509Cert(caPem); 9780 const x509Cert = await createX509Cert(certPem); 9781 let certCrlCollection = await cert.createCertCRLCollection([x509Cert]); 9782 let param: cert.CertChainBuildParameters = { 9783 certMatchParameters: {validDate:'20240812080000Z'}, 9784 maxLength: 3, 9785 validationParameters: { 9786 date: '20240812080000Z', 9787 certCRLs: [certCrlCollection], 9788 trustAnchors: [{CACert:caCert}, {CACert:caCert}], 9789 } 9790 } 9791 let certChainBuildResult = await cert.buildX509CertChain(param); 9792 console.info("cert issuer name: " + certChainBuildResult.validationResult.entityCert.getIssuerName().data) 9793 console.info("ca subject name: " + certChainBuildResult.validationResult.trustAnchor.CACert?.getSubjectName().data) 9794 } catch (error) { 9795 let e: BusinessError = error as BusinessError; 9796 console.error('createX509CertChain failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9797 } 9798} 9799 9800buildX509CertChain(); 9801``` 9802 9803## cert.createTrustAnchorsWithKeyStore<sup>12+</sup> 9804 9805createTrustAnchorsWithKeyStore(keystore: Uint8Array, pwd: string): Promise<Array\<[X509TrustAnchor](#x509trustanchor11)>> 9806 9807Creates a [TrustAnchor](#x509trustanchor11) object array from a .p12 keystore file. This API uses a promise to return the result. 9808 9809**Atomic service API**: This API can be used in atomic services since API version 12. 9810 9811**System capability**: SystemCapability.Security.Cert 9812 9813**Parameters** 9814 9815| Name | Type | Mandatory | Description | 9816| -------- | -------------------- | ---- | -------------------------- | 9817| keystore | Uint8Array | Yes | .p12 file in DER format. | 9818| pwd | string | Yes | Password of the .p12 file. | 9819 9820**Return value** 9821 9822| Type | Description | 9823| --------------------------------- | -------------------- | 9824| Array\<[X509TrustAnchor](#x509trustanchor11)> | **X509TrustAnchor** object array created. | 9825 9826**Error codes** 9827 9828For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9829 9830| ID | Error Message | 9831| -------- | ------------------------------------------------- | 9832| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9833| 19020001 | memory error. | 9834| 19020002 | runtime error. | 9835| 19030001 | crypto operation error. | 9836| 19030002 | the certificate signature verification failed. | 9837| 19030003 | the certificate has not taken effect. | 9838| 19030004 | the certificate has expired. | 9839| 19030005 | failed to obtain the certificate issuer. | 9840| 19030006 | the key cannot be used for signing a certificate. | 9841| 19030007 | the key cannot be used for digital signature. | 9842 9843**Example** 9844 9845```ts 9846import { cert } from '@kit.DeviceCertificateKit'; 9847import { BusinessError } from '@kit.BasicServicesKit'; 9848 9849try { 9850 cert.createTrustAnchorsWithKeyStore( 9851 new Uint8Array([0x30, 0x82, 0x07, 0x5C, 0x02, 0x01, 0x03, 0x30, 0x82, 0x07, 0x12, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x07, 0x03, 0x04, 0x82, 0x06, 0xFF, 0x30, 0x82, 0x06, 0xFB, 0x30, 0x82, 0x05, 0xB2, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06, 0xA0, 0x82, 0x05, 0xA3, 0x30, 0x82, 0x05, 0x9F, 0x02, 0x01, 0x00, 0x30, 0x82, 0x05, 0x98, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, 0x30, 0x1C, 0x04, 0x08, 0xA9, 0x1C, 0x1B, 0x19, 0x36, 0xDE, 0xD4, 0x20, 0x02, 0x02, 0x08, 0x00, 0x30, 0x0C, 0x06, 0x08, 0x2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8, 0x51, 0x9F, 0xA4, 0x3E, 0x7B, 0xA4, 0x18, 0x6D, 0x99, 0xF0, 0x6E, 0xC3, 0x97, 0xAE, 0xF4, 0xB7, 0x66, 0x37, 0xFA, 0x65, 0xFC, 0x5E, 0xE2, 0x57, 0xFA, 0x8B, 0x4C, 0x86, 0x10, 0xB4, 0x5C, 0xA4, 0xD2, 0x60, 0x83, 0x69, 0x1E, 0xFF, 0x36, 0x9B, 0xF9, 0x84, 0xFB, 0xB8, 0x83, 0x64, 0xF1, 0x41, 0xA5, 0x25, 0x56, 0x21, 0xBA, 0x13, 0x98, 0x0C, 0x3B, 0x04, 0xAA, 0x6C, 0x9A, 0xD4, 0xE3, 0x13, 0x15, 0x54, 0x05, 0x4C, 0x5C, 0xE1, 0x7A, 0x31, 0x5E, 0x90, 0xCF, 0x48, 0x4E, 0x83, 0xD7, 0x7F, 0xED, 0x93, 0x22, 0xAB, 0x67, 0xE7, 0x76, 0x32, 0x64, 0xBA, 0x5A, 0x21, 0x3E, 0x30, 0x82, 0x01, 0x41, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x01, 0x32, 0x04, 0x82, 0x01, 0x2E, 0x30, 0x82, 0x01, 0x2A, 0x30, 0x82, 0x01, 0x26, 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x0A, 0x01, 0x02, 0xA0, 0x81, 0xEF, 0x30, 0x81, 0xEC, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0D, 0x30, 0x4A, 0x30, 0x29, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x05, 0x0C, 0x30, 0x1C, 0x04, 0x08, 0xED, 0x3E, 0xED, 0x07, 0x5C, 0x1F, 0x71, 0xAD, 0x02, 0x02, 0x08, 0x00, 0x30,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 0x1C, 0x5E, 0x74, 0x9D, 0x7B, 0x31, 0x25, 0x30, 0x23, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x15, 0x31, 0x16, 0x04, 0x14, 0x5F, 0x8E, 0xAB, 0x9C, 0x5F, 0xE2, 0x3B, 0xB1, 0x5C, 0x1A, 0x36, 0x1D, 0x7D, 0xCB, 0x90, 0x45, 0x20, 0x3C, 0x3B, 0xAC, 0x30, 0x41, 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20, 0x93, 0x25, 0xC4, 0x3E, 0x2A, 0x6D, 0x4C, 0x30, 0x87, 0x0F, 0xE3, 0x5A, 0x95, 0xB0, 0xF2, 0x6C, 0xBA, 0x07, 0x89, 0x7D, 0xFB, 0xCF, 0xCF, 0x1D, 0x54, 0xA3, 0x36, 0x24, 0x7B, 0x30, 0x97, 0xB5, 0x04, 0x08, 0xE7, 0x96, 0x59, 0xCC, 0x42, 0x9F, 0xEF, 0xFC, 0x02, 0x02, 0x08, 0x00]), 9852 '123456').then((data) => { 9853 console.log('createTrustAnchorsWithKeyStore sucess, number of the result is: ' + JSON.stringify(data.length)); 9854 }).catch((err : BusinessError) => { 9855 console.error('createTrustAnchorsWithKeyStore failed:' + JSON.stringify(err)); 9856 }) 9857} catch (error) { 9858 console.error('createTrustAnchorsWithKeyStore failed:' + JSON.stringify(error)); 9859} 9860``` 9861 9862## X509CertChain<sup>11+</sup> 9863 9864Provides APIs for managing the X.509 certificate chain. 9865 9866### getCertList<sup>11+</sup> 9867 9868getCertList(): Array\<X509Cert> 9869 9870Obtains the X.509 certificate list. 9871 9872**Atomic service API**: This API can be used in atomic services since API version 12. 9873 9874**System capability**: SystemCapability.Security.Cert 9875 9876**Return value** 9877 9878| Type | Description | 9879| -------------- | ----------- | 9880| Array\<[X509Cert](#x509cert)> | X.509 certificate list obtained. | 9881 9882**Error codes** 9883 9884For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 9885 9886| ID | Error Message | 9887| -------- | ----------------------- | 9888| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 9889| 19020001 | memory error. | 9890| 19030001 | crypto operation error. | 9891 9892**Example** 9893 9894```ts 9895import { cert } from '@kit.DeviceCertificateKit'; 9896import { BusinessError } from '@kit.BasicServicesKit'; 9897 9898// Convert the string into a Uint8Array. 9899function stringToUint8Array(str: string): Uint8Array { 9900 let arr: Array<number> = []; 9901 for (let i = 0, j = str.length; i < j; i++) { 9902 arr.push(str.charCodeAt(i)); 9903 } 9904 return new Uint8Array(arr); 9905} 9906 9907let certChainData = "-----BEGIN CERTIFICATE-----\n" + 9908 "MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n" + 9909 "BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n" + 9910 "ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n" + 9911 "MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n" + 9912 "Z3N1MRAwDgYDVQQHEwdOYW5qaW5nMQwwCgYDVQQKEwN0czMxDDAKBgNVBAsTA3Rz\n" + 9913 "MzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" + 9914 "CgKCAQEAtt+2QxUevbolYLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLR\n" + 9915 "p26LFV/F8ebwPyo8YEBKSwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmc\n" + 9916 "rVvLBNMeVnxY86xHpo0MTNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0j\n" + 9917 "zT9GjeUP6JLdLFUZJKUPSTK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/U\n" + 9918 "T+p5ThAMH593zszlz330nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI3\n" + 9919 "8MFQFJKvRHfgTAvVsvAvpBUM2DuBKwIDAQABo4GsMIGpMAkGA1UdEwQCMAAwHQYD\n" + 9920 "VR0OBBYEFDfsHTMZwoA6eaDFlBUyDpka+sYtMAsGA1UdDwQEAwID+DAnBgNVHSUE\n" + 9921 "IDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEy\n" + 9922 "Ny4wLjAuMTARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBj\n" + 9923 "ZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEAp5vTvXrt8ZpgRJVtzv9ss0lJ\n" + 9924 "izp1fJf+ft5cDXrs7TSD5oHrSW2vk/ZieIMhexU4LFwhs4OE7jK6pgI48Dseqxx7\n" + 9925 "B/KktxhVMJUmVXd9Ayjp6f+BtZlIk0cArPuoXToXjsV8caTGBXHRdzxpAk/w9syc\n" + 9926 "GYrbH9TrdNMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n" + 9927 "DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n" + 9928 "iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n" + 9929 "-----END CERTIFICATE-----\n" + 9930 "-----BEGIN CERTIFICATE-----\n" + 9931 "MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 9932 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 9933 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n" + 9934 "OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 9935 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n" + 9936 "AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n" + 9937 "YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n" + 9938 "SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n" + 9939 "TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n" + 9940 "STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n" + 9941 "nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n" + 9942 "pBUM2DuBKwIDAQABo28wbTAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBQ37B0zGcKA\n" + 9943 "OnmgxZQVMg6ZGvrGLTALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEBBAQDAgAHMB4G\n" + 9944 "CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n" + 9945 "b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n" + 9946 "uKPWR9dKBA==\n" + 9947 "-----END CERTIFICATE-----\n" + 9948 "-----BEGIN CERTIFICATE-----\n" + 9949 "MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 9950 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 9951 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n" + 9952 "MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 9953 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n" + 9954 "AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n" + 9955 "klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n" + 9956 "St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n" + 9957 "AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n" + 9958 "KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n" + 9959 "xjoE\n" + 9960 "-----END CERTIFICATE-----\n"; 9961 9962// Certificate chain binary data, which varies with the service. 9963let encodingBlob: cert.EncodingBlob = { 9964 data: stringToUint8Array(certChainData), 9965 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 9966 encodingFormat: cert.EncodingFormat.FORMAT_PEM 9967}; 9968 9969cert.createX509CertChain(encodingBlob, (err, certChain) => { 9970 if (err) { 9971 console.error('createX509CertChain failed, errCode: ' + err.code + ', errMsg: ' + err.message); 9972 } else { 9973 console.log('createX509CertChain success'); 9974 try { 9975 let certList = certChain.getCertList(); 9976 } catch (err) { 9977 let e: BusinessError = err as BusinessError; 9978 console.error('X509CertChain getCertList failed, errCode: ' + e.code + ', errMsg: ' + e.message); 9979 } 9980 } 9981}); 9982``` 9983 9984### validate<sup>11+</sup> 9985 9986validate(param: CertChainValidationParameters): Promise\<CertChainValidationResult> 9987 9988Validates a certificate chain. This API uses a promise to return the result. 9989 9990**Atomic service API**: This API can be used in atomic services since API version 12. 9991 9992**System capability**: SystemCapability.Security.Cert 9993 9994**Parameters** 9995 9996| Name | Type | Mandatory | Description | 9997| --------- | ------------------------------- | ---- | ----------------- | 9998| param | [CertChainValidationParameters](#certchainvalidationparameters11) | Yes | Parameters for validating the X.509 certificate chain. | 9999 10000**Return value** 10001 10002| Type | Description | 10003| ------------------------------------------------------------ | --------------------------------- | 10004| Promise\<[CertChainValidationResult](#certchainvalidationresult11)> | Promise used to return the result. | 10005 10006**Error codes** 10007 10008For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10009 10010| ID | Error Message | 10011| -------- | ----------------------- | 10012| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 10013| 19020001 | memory error. | 10014| 19020002 | runtime error. | 10015| 19030001 | crypto operation error. | 10016| 19030002 | the certificate signature verification failed. | 10017| 19030003 | the certificate has not taken effect. | 10018| 19030004 | the certificate has expired. | 10019| 19030005 | failed to obtain the certificate issuer. | 10020| 19030006 | the key cannot be used for signing a certificate. | 10021| 19030007 | the key cannot be used for digital signature. | 10022 10023**Example** 10024 10025```ts 10026import { cert } from '@kit.DeviceCertificateKit'; 10027import { BusinessError } from '@kit.BasicServicesKit'; 10028 10029// Convert the string into a Uint8Array. 10030function stringToUint8Array(str: string): Uint8Array { 10031 let arr: Array<number> = []; 10032 for (let i = 0, j = str.length; i < j; i++) { 10033 arr.push(str.charCodeAt(i)); 10034 } 10035 return new Uint8Array(arr); 10036} 10037 10038async function createX509CertChain(): Promise<cert.X509CertChain> { 10039 let certChainData = "-----BEGIN CERTIFICATE-----\n" + 10040 "MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n" + 10041 "BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n" + 10042 "ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n" + 10043 "MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n" + 10044 "Z3N1MRAwDgYDVQQHEwdOYW5qaW5nMQwwCgYDVQQKEwN0czMxDDAKBgNVBAsTA3Rz\n" + 10045 "MzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" + 10046 "CgKCAQEAtt+2QxUevbolYLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLR\n" + 10047 "p26LFV/F8ebwPyo8YEBKSwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmc\n" + 10048 "rVvLBNMeVnxY86xHpo0MTNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0j\n" + 10049 "zT9GjeUP6JLdLFUZJKUPSTK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/U\n" + 10050 "T+p5ThAMH593zszlz330nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI3\n" + 10051 "8MFQFJKvRHfgTAvVsvAvpBUM2DuBKwIDAQABo4GsMIGpMAkGA1UdEwQCMAAwHQYD\n" + 10052 "VR0OBBYEFDfsHTMZwoA6eaDFlBUyDpka+sYtMAsGA1UdDwQEAwID+DAnBgNVHSUE\n" + 10053 "IDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEy\n" + 10054 "Ny4wLjAuMTARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBj\n" + 10055 "ZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEAp5vTvXrt8ZpgRJVtzv9ss0lJ\n" + 10056 "izp1fJf+ft5cDXrs7TSD5oHrSW2vk/ZieIMhexU4LFwhs4OE7jK6pgI48Dseqxx7\n" + 10057 "B/KktxhVMJUmVXd9Ayjp6f+BtZlIk0cArPuoXToXjsV8caTGBXHRdzxpAk/w9syc\n" + 10058 "GYrbH9TrdNMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n" + 10059 "DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n" + 10060 "iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n" + 10061 "-----END CERTIFICATE-----\n" + 10062 "-----BEGIN CERTIFICATE-----\n" + 10063 "MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 10064 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 10065 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n" + 10066 "OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 10067 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n" + 10068 "AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n" + 10069 "YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n" + 10070 "SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n" + 10071 "TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n" + 10072 "STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n" + 10073 "nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n" + 10074 "pBUM2DuBKwIDAQABo28wbTAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBQ37B0zGcKA\n" + 10075 "OnmgxZQVMg6ZGvrGLTALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEBBAQDAgAHMB4G\n" + 10076 "CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n" + 10077 "b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n" + 10078 "uKPWR9dKBA==\n" + 10079 "-----END CERTIFICATE-----\n" + 10080 "-----BEGIN CERTIFICATE-----\n" + 10081 "MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 10082 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 10083 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n" + 10084 "MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 10085 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n" + 10086 "AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n" + 10087 "klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n" + 10088 "St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n" + 10089 "AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n" + 10090 "KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n" + 10091 "xjoE\n" + 10092 "-----END CERTIFICATE-----\n"; 10093 10094 // Certificate chain binary data, which varies with the service. 10095 let encodingBlob: cert.EncodingBlob = { 10096 data: stringToUint8Array(certChainData), 10097 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 10098 encodingFormat: cert.EncodingFormat.FORMAT_PEM 10099 }; 10100 let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; 10101 try { 10102 x509CertChain = await cert.createX509CertChain(encodingBlob); 10103 } 10104 catch (error) { 10105 let e: BusinessError = error as BusinessError; 10106 console.error('createX509CertChain failed, errCode: ' + e.code + ', errMsg: ' + e.message); 10107 } 10108 return x509CertChain; 10109} 10110 10111async function validate() { 10112 const certChain = await createX509CertChain(); 10113 // Certificate chain validation data, which varies with the service. 10114 const param: cert.CertChainValidationParameters = { 10115 date: '20231212080000Z', 10116 trustAnchors: [{ 10117 CAPubKey: new Uint8Array([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, 0xbb, 0x16,0x9d, 0x8f, 0x5c, 0x30, 0xd0, 0xba, 0x8f, 0x37, 0x6e, 0x33, 0xaf, 0x6f, 0x23, 0x71, 0x23, 0xa5, 0x49, 0x60,0x1e, 0xd1, 0x07, 0x4b, 0xc9, 0x11, 0x7e, 0x66, 0x01, 0xba, 0x92, 0x52]), 10118 CASubject: new Uint8Array([0x30, 0x5a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x45,0x4e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x45, 0x6e, 0x67, 0x6c, 0x61, 0x6e,0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x06, 0x4c, 0x6f, 0x6e, 0x64, 0x6f, 0x6e,0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a,0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04,0x03, 0x13, 0x03, 0x74, 0x73, 0x31]), 10119 }] 10120 } 10121 try { 10122 const validationRes = await certChain.validate(param); 10123 console.log('X509CertChain validate success'); 10124 } 10125 catch (err) { 10126 console.error('X509CertChain validate failed'); 10127 } 10128} 10129 10130validate(); 10131``` 10132 10133### validate<sup>11+</sup> 10134 10135validate(param: CertChainValidationParameters, callback: AsyncCallback\<CertChainValidationResult>): void 10136 10137Validates a certificate chain. This API uses an asynchronous callback to return the result. 10138 10139**Atomic service API**: This API can be used in atomic services since API version 12. 10140 10141**System capability**: SystemCapability.Security.Cert 10142 10143**Parameters** 10144 10145| Name | Type | Mandatory | Description | 10146| --------- | ------------------------------- | ---- | ------------ | 10147| param | [CertChainValidationParameters](#certchainvalidationparameters11) | Yes | Parameters for validating the X.509 certificate chain. | 10148| callback | AsyncCallback\<[CertChainValidationResult](#certchainvalidationresult11)> | Yes | Callback used to return the certificate chain validation result. | 10149 10150**Error codes** 10151 10152For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10153 10154| ID | Error Message | 10155| -------- | ----------------------- | 10156| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 10157| 19020001 | memory error. | 10158| 19020002 | runtime error. | 10159| 19030001 | crypto operation error. | 10160| 19030002 | the certificate signature verification failed. | 10161| 19030003 | the certificate has not taken effect. | 10162| 19030004 | the certificate has expired. | 10163| 19030005 | failed to obtain the certificate issuer. | 10164| 19030006 | the key cannot be used for signing a certificate. | 10165| 19030007 | the key cannot be used for digital signature. | 10166 10167**Example** 10168 10169```ts 10170import { cert } from '@kit.DeviceCertificateKit'; 10171 10172// Convert the string into a Uint8Array. 10173function stringToUint8Array(str: string): Uint8Array { 10174 let arr: Array<number> = []; 10175 for (let i = 0, j = str.length; i < j; i++) { 10176 arr.push(str.charCodeAt(i)); 10177 } 10178 return new Uint8Array(arr); 10179} 10180 10181let certChainData = "-----BEGIN CERTIFICATE-----\n" + 10182 "MIID6jCCAtKgAwIBAgIIIM2q/TmRoLcwDQYJKoZIhvcNAQELBQAwWjELMAkGA1UE\n" + 10183 "BhMCRU4xEDAOBgNVBAgTB0VuZ2xhbmQxDzANBgNVBAcTBkxvbmRvbjEMMAoGA1UE\n" + 10184 "ChMDdHMyMQwwCgYDVQQLEwN0czIxDDAKBgNVBAMTA3RzMjAeFw0yMzEyMDUwNzM5\n" + 10185 "MDBaFw0yNDEwMzEyMzU5MDBaMGExCzAJBgNVBAYTAkNOMRAwDgYDVQQIEwdKaWFu\n" + 10186 "Z3N1MRAwDgYDVQQHEwdOYW5qaW5nMQwwCgYDVQQKEwN0czMxDDAKBgNVBAsTA3Rz\n" + 10187 "MzESMBAGA1UEAxMJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n" + 10188 "CgKCAQEAtt+2QxUevbolYLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLR\n" + 10189 "p26LFV/F8ebwPyo8YEBKSwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmc\n" + 10190 "rVvLBNMeVnxY86xHpo0MTNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0j\n" + 10191 "zT9GjeUP6JLdLFUZJKUPSTK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/U\n" + 10192 "T+p5ThAMH593zszlz330nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI3\n" + 10193 "8MFQFJKvRHfgTAvVsvAvpBUM2DuBKwIDAQABo4GsMIGpMAkGA1UdEwQCMAAwHQYD\n" + 10194 "VR0OBBYEFDfsHTMZwoA6eaDFlBUyDpka+sYtMAsGA1UdDwQEAwID+DAnBgNVHSUE\n" + 10195 "IDAeBggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMEMBQGA1UdEQQNMAuCCTEy\n" + 10196 "Ny4wLjAuMTARBglghkgBhvhCAQEEBAMCBkAwHgYJYIZIAYb4QgENBBEWD3hjYSBj\n" + 10197 "ZXJ0aWZpY2F0ZTANBgkqhkiG9w0BAQsFAAOCAQEAp5vTvXrt8ZpgRJVtzv9ss0lJ\n" + 10198 "izp1fJf+ft5cDXrs7TSD5oHrSW2vk/ZieIMhexU4LFwhs4OE7jK6pgI48Dseqxx7\n" + 10199 "B/KktxhVMJUmVXd9Ayjp6f+BtZlIk0cArPuoXToXjsV8caTGBXHRdzxpAk/w9syc\n" + 10200 "GYrbH9TrdNMuTizOb+k268oKXUageZNxHmd7YvOXkcNgrd29jzwXKDYYiUa1DISz\n" + 10201 "DnYaJOgPt0B/5izhoWNK7GhJDy9KEuLURcTSWFysbbnljwO9INPT9MmlS83PdAgN\n" + 10202 "iS8VXF4pce1W9U5jH7d7k0JDVSXybebe1iPFphsZpYM/NE+jap+mPy1nTCbf9g==\n" + 10203 "-----END CERTIFICATE-----\n" + 10204 "-----BEGIN CERTIFICATE-----\n" + 10205 "MIIC0zCCAoWgAwIBAgIIXpLoPpQVWnkwBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 10206 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 10207 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDczNzAwWhcNMjQw\n" + 10208 "OTAxMjM1OTAwWjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 10209 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czIxDDAKBgNVBAsTA3RzMjEMMAoGA1UE\n" + 10210 "AxMDdHMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtt+2QxUevbol\n" + 10211 "YLp51QGcUpageI4fwGLIqv4fj4aoVnHFOOBqVOVpfCLRp26LFV/F8ebwPyo8YEBK\n" + 10212 "SwXzMD1573rMSbaH9BalscH5lZYAbetXoio6YRvzlcmcrVvLBNMeVnxY86xHpo0M\n" + 10213 "TNyP7W024rZsxWO98xFQVdoiaBC+7+midlisx2Y+7u0jzT9GjeUP6JLdLFUZJKUP\n" + 10214 "STK3jVzw9v1eZQZKYoNfU6vFMd6ndtwW6qEnwpzmmX/UT+p5ThAMH593zszlz330\n" + 10215 "nTSXBjIsGkyvOz9gSB0Z0LAuJj06XUNhGL5xKJYKbdI38MFQFJKvRHfgTAvVsvAv\n" + 10216 "pBUM2DuBKwIDAQABo28wbTAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBQ37B0zGcKA\n" + 10217 "OnmgxZQVMg6ZGvrGLTALBgNVHQ8EBAMCAQYwEQYJYIZIAYb4QgEBBAQDAgAHMB4G\n" + 10218 "CWCGSAGG+EIBDQQRFg94Y2EgY2VydGlmaWNhdGUwBQYDK2VwA0EAuasLBe55YgvF\n" + 10219 "b4wmHeohylc9r8cFGS1LNQ5UcSn3sGqMYf6ehnef16NLuCW6upHCs8Sui4iAMvsP\n" + 10220 "uKPWR9dKBA==\n" + 10221 "-----END CERTIFICATE-----\n" + 10222 "-----BEGIN CERTIFICATE-----\n" + 10223 "MIIB3zCCAZGgAwIBAgIIWQvOEDl+ya4wBQYDK2VwMFoxCzAJBgNVBAYTAkVOMRAw\n" + 10224 "DgYDVQQIEwdFbmdsYW5kMQ8wDQYDVQQHEwZMb25kb24xDDAKBgNVBAoTA3RzMTEM\n" + 10225 "MAoGA1UECxMDdHMxMQwwCgYDVQQDEwN0czEwHhcNMjMxMjA1MDAwMDAwWhcNMjQx\n" + 10226 "MjA0MjM1OTU5WjBaMQswCQYDVQQGEwJFTjEQMA4GA1UECBMHRW5nbGFuZDEPMA0G\n" + 10227 "A1UEBxMGTG9uZG9uMQwwCgYDVQQKEwN0czExDDAKBgNVBAsTA3RzMTEMMAoGA1UE\n" + 10228 "AxMDdHMxMCowBQYDK2VwAyEAuxadj1ww0LqPN24zr28jcSOlSWAe0QdLyRF+ZgG6\n" + 10229 "klKjdTBzMBIGA1UdEwEB/wQIMAYBAf8CARQwHQYDVR0OBBYEFNSgpoQvfxR8A1Y4\n" + 10230 "St8NjOHkRpm4MAsGA1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAAcwHgYJYIZI\n" + 10231 "AYb4QgENBBEWD3hjYSBjZXJ0aWZpY2F0ZTAFBgMrZXADQQAblBgoa72X/K13WOvc\n" + 10232 "KW0fqBgFKvLy85hWD6Ufi61k4ProQiZzMK+0+y9jReKelPx/zRdCCgSbQroAR2mV\n" + 10233 "xjoE\n" + 10234 "-----END CERTIFICATE-----\n"; 10235 10236// Certificate chain binary data, which varies with the service. 10237let encodingBlob: cert.EncodingBlob = { 10238 data: stringToUint8Array(certChainData), 10239 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 10240 encodingFormat: cert.EncodingFormat.FORMAT_PEM 10241}; 10242 10243// Certificate chain validation data, which varies with the service. 10244let param: cert.CertChainValidationParameters = { 10245 date: '20231212080000Z', 10246 trustAnchors: [{ 10247 CAPubKey: new Uint8Array([0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00, 0xbb, 0x16,0x9d, 0x8f, 0x5c, 0x30, 0xd0, 0xba, 0x8f, 0x37, 0x6e, 0x33, 0xaf, 0x6f, 0x23, 0x71, 0x23, 0xa5, 0x49, 0x60,0x1e, 0xd1, 0x07, 0x4b, 0xc9, 0x11, 0x7e, 0x66, 0x01, 0xba, 0x92, 0x52]), 10248 CASubject: new Uint8Array([0x30, 0x5a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x45,0x4e, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x07, 0x45, 0x6e, 0x67, 0x6c, 0x61, 0x6e,0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x13, 0x06, 0x4c, 0x6f, 0x6e, 0x64, 0x6f, 0x6e,0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a,0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x03, 0x74, 0x73, 0x31, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04,0x03, 0x13, 0x03, 0x74, 0x73, 0x31]), 10249 }] 10250}; 10251 10252cert.createX509CertChain(encodingBlob, (err, certChain) => { 10253 if (err) { 10254 console.error('createX509CertChain failed, errCode: ' + err.code + ', errMsg: ' + err.message); 10255 } else { 10256 console.log('createX509CertChain success'); 10257 certChain.validate(param, (error, validationRes) => { 10258 if (error) { 10259 console.error('X509CertChain validate failed, errCode: ' + error.code + ', errMsg: ' + error.message); 10260 } else { 10261 console.log('X509CertChain validate success'); 10262 } 10263 }); 10264 } 10265}); 10266``` 10267 10268### toString<sup>12+</sup> 10269 10270toString(): string 10271 10272Converts the object data into a string. 10273 10274**Atomic service API**: This API can be used in atomic services since API version 12. 10275 10276**System capability**: SystemCapability.Security.Cert 10277 10278**Return value** 10279 10280| Type | Description | 10281| ------- | ---------------------------------------------------- | 10282| string | String obtained.| 10283 10284**Error codes** 10285 10286For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10287 10288| ID | Error Message | 10289| -------- | ----------------------- | 10290| 19020001 | memory error. | 10291| 19020002 | runtime error. | 10292| 19030001 | crypto operation error. | 10293 10294**Example** 10295 10296```ts 10297import { cert } from '@kit.DeviceCertificateKit'; 10298import { BusinessError } from '@kit.BasicServicesKit'; 10299 10300// Convert the string into a Uint8Array. 10301function stringToUint8Array(str: string): Uint8Array { 10302 let arr: Array<number> = []; 10303 for (let i = 0, j = str.length; i < j; i++) { 10304 arr.push(str.charCodeAt(i)); 10305 } 10306 return new Uint8Array(arr); 10307} 10308 10309let certChainData = '-----BEGIN CERTIFICATE-----\n' + 10310 'MIIGVjCCBT6gAwIBAgIQBMO0W3CU9LWVw1bE/jqYojANBgkqhkiG9w0BAQsFADBE\n' + 10311 'MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMR4wHAYDVQQDExVH\n' + 10312 'ZW9UcnVzdCBSU0EgQ04gQ0EgRzIwHhcNMjMwMzIzMDAwMDAwWhcNMjQwNDIyMjM1\n' + 10313 'OTU5WjB1MQswCQYDVQQGEwJDTjERMA8GA1UECBMIemhlamlhbmcxETAPBgNVBAcT\n' + 10314 'CGhhbmd6aG91MSwwKgYDVQQKEyNOZXRFYXNlIChIYW5nemhvdSkgTmV0d29yayBD\n' + 10315 'by4sIEx0ZDESMBAGA1UEAwwJKi4xNjMuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOC\n' + 10316 'AQ8AMIIBCgKCAQEAwELks0Q1Z81u1OpbGdEFE2Snm/WpLfmiC5YFj5nFrinSX+UZ\n' + 10317 'MIk42euBdjYSsWFxbljmWDdUCjstMhG8vRAjz3Nt1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' + 10332 'bHp+RL6F8cvNydajQ0Bqxjvd3AIgefAU/po3jBm+96dFVdbX+AG1uss67DL3VL5I\n' + 10333 'nUmVva8AdgBz2Z6JG0yWeKAgfUed5rLGHNBRXnEZKoxrgBB6wXdytQAAAYcNITZS\n' + 10334 'AAAEAwBHMEUCID/sUP12odF7uTTEyE0PjCpKo3nF7A3ba3b5wJJsZrDrAiEAxrat\n' + 10335 'W2eeZTD458LPSPrMMBb1/o6zibWXqJCQye+bVFwAdwBIsONr2qZHNA/lagL6nTDr\n' + 10336 'HFIBy1bdLIHZu7+rOdiEcwAAAYcNITYeAAAEAwBIMEYCIQCCJ2ktM1F+d1I5mQju\n' + 10337 'Tn7oDYxy3GCGyG3u/yhu8k7EaAIhANSP8cAaMQFV6y8B2tubKY5eSQtgkF3a6NNq\n' + 10338 'QJjtPnoHMA0GCSqGSIb3DQEBCwUAA4IBAQC8dK/G4nvs/SyQe/mnK+rUYIdSFs+4\n' + 10339 'lgzatmq8V/I1tBly+Sv/FPhnn4F3iCrqy9j8y202FP51ev95DGbjlJRTIFPqVAO8\n' + 10340 'ywYrLhvl1SJhV0b/8NF0Pr3dZVnK5Vfn11+LSBUg0cBB2hcVV30nv3IuVhz3d12n\n' + 10341 'P+VseYQgMpQf7ad+ttpZtA7yqHzrUm4fzr03G7q88GztACRSHoYiPbOlz99SeTgW\n' + 10342 '7bzZl1I4taxy2Q3b0ZBGfUt/kPY05tpKzKwDTbbqSErYszCt5X1RfVvf3coxF8Mo\n' + 10343 '9bHbs2wYIzQBdujDQ/hU0u6ItERer3SUItZoxaSIxdrZ9eXFwVvXsT/g\n' + 10344 '-----END CERTIFICATE-----\n' + 10345 '-----BEGIN CERTIFICATE-----\n' + 10346 'MIIFDzCCA/egAwIBAgIQCxNitu5qnT6WiTDxbiB9OTANBgkqhkiG9w0BAQsFADBh\n' + 10347 'MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n' + 10348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YmFsUm9vdENBLmNybDCB3QYDVR0gBIHVMIHSMIHF\n' + 10363 'BglghkgBhv1sAQEwgbcwKAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0\n' + 10364 'LmNvbS9DUFMwgYoGCCsGAQUFBwICMH4MfEFueSB1c2Ugb2YgdGhpcyBDZXJ0aWZp\n' + 10365 'Y2F0ZSBjb25zdGl0dXRlcyBhY2NlcHRhbmNlIG9mIHRoZSBSZWx5aW5nIFBhcnR5\n' + 10366 'IEFncmVlbWVudCBsb2NhdGVkIGF0IGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9y\n' + 10367 'cGEtdWEwCAYGZ4EMAQICMA0GCSqGSIb3DQEBCwUAA4IBAQCzkcXq0TN0oSn4UeXp\n' + 10368 'FBW7U8zrHBIhH9MXHNBp+Yy/yN19133UY05uuHXHaU2Uv0hxefckjPdkaX7ARso+\n' + 10369 'O3Ar6nf7YfBwCqSpqsNckKT7KKtf3Ot95wYFpKDa64jcRUfxzRWnmq12IVzczqHI\n' + 10370 'sIvUZQINw/UHSQcWekdUnMg58bQSHyTjwkj9jcX2RURxaVZkr15wxo/Z3Ydo2PVK\n' + 10371 '3afEr0/vcuFvE7QeGXiI2DJdVt3JefatZ3rj4VTW2aUZwHGUiWWIUudBfQKR0JEp\n' + 10372 'lJ8MFaKDh4/A2VEJnXILu1iwvc1m3jCaPuzZKdoHM/1234bznJI2aAfhfIhoHw90\n' + 10373 'tPO+\n' + 10374 '-----END CERTIFICATE-----\n'; 10375 10376// Certificate chain binary data, which varies with the service. 10377let encodingBlob: cert.EncodingBlob = { 10378 data: stringToUint8Array(certChainData), 10379 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 10380 encodingFormat: cert.EncodingFormat.FORMAT_PEM 10381}; 10382 10383async function certChainToString() { 10384 let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; 10385 try { 10386 x509CertChain = await cert.createX509CertChain(encodingBlob); 10387 console.log('createX509CertChain success'); 10388 console.info('toString success: ' + JSON.stringify(x509CertChain.toString())); 10389 } catch (error) { 10390 let e: BusinessError = error as BusinessError; 10391 console.error('createX509CertChain failed, errCode: ' + e.code + ', errMsg: ' + e.message); 10392 } 10393} 10394``` 10395### hashCode<sup>12+</sup> 10396 10397hashCode(): Uint8Array 10398 10399Obtains the hash value of the data in DER format. 10400 10401**Atomic service API**: This API can be used in atomic services since API version 12. 10402 10403**System capability**: SystemCapability.Security.Cert 10404 10405**Return value** 10406 10407| Type | Description | 10408| ------- | ---------------------------------------------------- | 10409| Uint8Array | Hash value obtained.| 10410 10411**Error codes** 10412 10413For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10414 10415| ID | Error Message | 10416| -------- | ----------------------- | 10417| 19020001 | memory error. | 10418| 19020002 | runtime error. | 10419| 19030001 | crypto operation error. | 10420 10421**Example** 10422 10423```ts 10424import { cert } from '@kit.DeviceCertificateKit'; 10425import { BusinessError } from '@kit.BasicServicesKit'; 10426 10427// Convert the string into a Uint8Array. 10428function stringToUint8Array(str: string): Uint8Array { 10429 let arr: Array<number> = []; 10430 for (let i = 0, j = str.length; i < j; i++) { 10431 arr.push(str.charCodeAt(i)); 10432 } 10433 return new Uint8Array(arr); 10434} 10435 10436let certChainData = '-----BEGIN CERTIFICATE-----\n' + 10437 'MIIGVjCCBT6gAwIBAgIQBMO0W3CU9LWVw1bE/jqYojANBgkqhkiG9w0BAQsFADBE\n' + 10438 'MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMR4wHAYDVQQDExVH\n' + 10439 'ZW9UcnVzdCBSU0EgQ04gQ0EgRzIwHhcNMjMwMzIzMDAwMDAwWhcNMjQwNDIyMjM1\n' + 10440 'OTU5WjB1MQswCQYDVQQGEwJDTjERMA8GA1UECBMIemhlamlhbmcxETAPBgNVBAcT\n' + 10441 'CGhhbmd6aG91MSwwKgYDVQQKEyNOZXRFYXNlIChIYW5nemhvdSkg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vXsT/g\n' + 10471 '-----END CERTIFICATE-----\n' + 10472 '-----BEGIN CERTIFICATE-----\n' + 10473 'MIIFDzCCA/egAwIBAgIQCxNitu5qnT6WiTDxbiB9OTANBgkqhkiG9w0BAQsFADBh\n' + 10474 'MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n' + 10475 'd3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n' + 10476 'QTAeFw0yMDAzMDQxMjA0NDBaFw0zMDAzMDQxMjA0NDBaMEQxCzAJBgNVBAYTAlVT\n' + 10477 'MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxHjAcBgNVBAMTFUdlb1RydXN0IFJTQSBD\n' + 10478 'TiBDQSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANA1OZJJtZUI\n' + 10479 '7zj4qFHT79g+Otks4TEfmUEDhrNKBEEjb/i29GBfnpvFdT36azCg2VODJRSjIzFn\n' + 10480 '4qADcc84EmfKiDEM97HFsQPp9RRkqxH5cB51EU2eBE9Ua95x+wQp/KSdCqITCQ/v\n' + 10481 'yvm3J4Upjl0wlW8wRCPCWcYw3pKClGRkNzVtI1KXnfpn7fG3N84n7wlBb9IGKJFa\n' + 10482 'c/6+hxvZx2qnfLsxdIKR0Q/biGoU6Z8Iy/R/p7GoPO8vamV090+QHEL5AdSzKtEh\n' + 10483 'U9vdvcuWjjLxVnaJLfj/6WoGZj8UWn3zFbEoTVaAfp2xqdzW7yRvi2r148m9ev7l\n' + 10484 'jDqHo8UX69sCAwEAAaOCAd4wggHaMB0GA1UdDgQWBBQkb5E/iYeHDjLCQBjfxUzr\n' + 10485 'T8hJMjAfBgNVHSMEGDAWgBQD3lA1VtFMu2bwo+IbG8OXsj3RVTAOBgNVHQ8BAf8E\n' + 10486 'BAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQI\n' + 10487 'MAYBAf8CAQAwMwYIKwYBBQUHAQEEJzAlMCMGCCsGAQUFBzABhhdodHRwOi8vb2Nz\n' + 10488 'cC5kaWdpY2VydC5jbjBABgNVHR8EOTA3MDWgM6Axhi9odHRwOi8vY3JsLmRpZ2lj\n' + 10489 'ZXJ0LmNuL0RpZ2lDZXJ0R2xvYmFsUm9vdENBLmNybDCB3QYDVR0gBIHVMIHSMIHF\n' + 10490 'BglghkgBhv1sAQEwgbcwKAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0\n' + 10491 'LmNvbS9DUFMwgYoGCCsGAQUFBwICMH4MfEFueSB1c2Ugb2YgdGhpcyBDZXJ0aWZp\n' + 10492 'Y2F0ZSBjb25zdGl0dXRlcyBhY2NlcHRhbmNlIG9mIHRoZSBSZWx5aW5nIFBhcnR5\n' + 10493 'IEFncmVlbWVudCBsb2NhdGVkIGF0IGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9y\n' + 10494 'cGEtdWEwCAYGZ4EMAQICMA0GCSqGSIb3DQEBCwUAA4IBAQCzkcXq0TN0oSn4UeXp\n' + 10495 'FBW7U8zrHBIhH9MXHNBp+Yy/yN19133UY05uuHXHaU2Uv0hxefckjPdkaX7ARso+\n' + 10496 'O3Ar6nf7YfBwCqSpqsNckKT7KKtf3Ot95wYFpKDa64jcRUfxzRWnmq12IVzczqHI\n' + 10497 'sIvUZQINw/UHSQcWekdUnMg58bQSHyTjwkj9jcX2RURxaVZkr15wxo/Z3Ydo2PVK\n' + 10498 '3afEr0/vcuFvE7QeGXiI2DJdVt3JefatZ3rj4VTW2aUZwHGUiWWIUudBfQKR0JEp\n' + 10499 'lJ8MFaKDh4/A2VEJnXILu1iwvc1m3jCaPuzZKdoHM/1234bznJI2aAfhfIhoHw90\n' + 10500 'tPO+\n' + 10501 '-----END CERTIFICATE-----\n'; 10502 10503// Certificate chain binary data, which varies with the service. 10504let encodingBlob: cert.EncodingBlob = { 10505 data: stringToUint8Array(certChainData), 10506 // Set the encoding format, which can be FORMAT_PEM, FORMAT_DER, or FORMAT_PKCS7. 10507 encodingFormat: cert.EncodingFormat.FORMAT_PEM 10508}; 10509 10510async function certChainHashCode() { 10511 let x509CertChain: cert.X509CertChain = {} as cert.X509CertChain; 10512 try { 10513 x509CertChain = await cert.createX509CertChain(encodingBlob); 10514 console.log('createX509CertChain success'); 10515 console.info('hashCode success: ' + JSON.stringify(x509CertChain.hashCode())); 10516 } catch (error) { 10517 let e: BusinessError = error as BusinessError; 10518 console.error('createX509CertChain failed, errCode: ' + e.code + ', errMsg: ' + e.message); 10519 } 10520} 10521``` 10522## cert.createX500DistinguishedName<sup>12+</sup> 10523 10524createX500DistinguishedName(nameStr: string): Promise\<X500DistinguishedName> 10525 10526Creates an **X500DistinguishedName** object in the form of a string. This API uses a promise to return the result. 10527 10528**Atomic service API**: This API can be used in atomic services since API version 12. 10529 10530**System capability**: SystemCapability.Security.Cert 10531 10532**Parameters** 10533 10534| Name | Type | Mandatory | Description | 10535| -------- | ----------------------------- | ---- | -------------------- | 10536| nameStr | string | Yes |DN of the string type defined by X.509.| 10537 10538**Return value** 10539 10540| Type | Description | 10541| ------------------------------- | ---------------- | 10542| Promise\<[X500DistinguishedName](#x500distinguishedname12)> | Promise used to return the **X500DistinguishedName** object created.| 10543 10544**Error codes** 10545 10546For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10547 10548| ID | Error Message | 10549| -------- | ------------- | 10550| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 10551| 19020001 | memory error. | 10552| 19020002 | runtime error. | 10553| 19030001 | crypto operation error. | 10554| 19030002 | the certificate signature verification failed. | 10555| 19030003 | the certificate has not taken effect. | 10556| 19030004 | the certificate has expired. | 10557| 19030005 | failed to obtain the certificate issuer. | 10558| 19030006 | the key cannot be used for signing a certificate. | 10559| 19030007 | the key cannot be used for digital signature. | 10560 10561**Example** 10562 10563```ts 10564import { cert } from '@kit.DeviceCertificateKit'; 10565import { BusinessError } from '@kit.BasicServicesKit'; 10566 10567// Convert the string into a Uint8Array. 10568function stringToUint8Array(str: string): Uint8Array { 10569 let arr: Array<number> = []; 10570 for (let i = 0, j = str.length; i < j; i++) { 10571 arr.push(str.charCodeAt(i)); 10572 } 10573 return new Uint8Array(arr); 10574} 10575 10576let nameStr = '/CN=John Doe/OU=IT Department/O=ACME Inc./L=San Francisco/ST=California/C=US/CN=ALN C/CN=XTS'; 10577async function createX500DistinguishedName() { 10578 try { 10579 cert.createX500DistinguishedName(nameStr) 10580 .then((data) => { 10581 console.log('createX500DistinguishedName success'); 10582 }) 10583 .catch((err: BusinessError) => { 10584 console.error('createX500DistinguishedName catch, errCode: ' + err.code + ', errMsg: ' + err.message); 10585 }) 10586 } catch (error) { 10587 let e: BusinessError = error as BusinessError; 10588 console.error('createX500DistinguishedName catch, errCode: ' + e.code + ', errMsg: ' + e.message); 10589 } 10590} 10591``` 10592 10593## cert.createX500DistinguishedName<sup>12+</sup> 10594 10595createX500DistinguishedName(nameDer: Uint8Array): Promise\<X500DistinguishedName> 10596 10597Creates an **X500DistinguishedName** object in DER format. This API uses a promise to return the result. 10598 10599**Atomic service API**: This API can be used in atomic services since API version 12. 10600 10601**System capability**: SystemCapability.Security.Cert 10602 10603**Parameters** 10604 10605| Name | Type | Mandatory | Description | 10606| -------- | ----------------------------- | ---- | -------------------- | 10607| nameDer | Uint8Array | Yes |Name of the Uint8Array type in DER format defined by X.509.| 10608 10609**Return value** 10610 10611| Type | Description | 10612| ------------------------------- | ---------------- | 10613| Promise\<[X500DistinguishedName](#x500distinguishedname12)> | Promise used to return the **X500DistinguishedName** object created.| 10614 10615**Error codes** 10616 10617For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10618 10619| ID | Error Message | 10620| -------- | ------------- | 10621| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 10622| 19020001 | memory error. | 10623| 19020002 | runtime error. | 10624| 19030001 | crypto operation error. | 10625| 19030002 | the certificate signature verification failed. | 10626| 19030003 | the certificate has not taken effect. | 10627| 19030004 | the certificate has expired. | 10628| 19030005 | failed to obtain the certificate issuer. | 10629| 19030006 | the key cannot be used for signing a certificate. | 10630| 19030007 | the key cannot be used for digital signature. | 10631 10632**Example** 10633 10634```ts 10635import { cert } from '@kit.DeviceCertificateKit'; 10636import { BusinessError } from '@kit.BasicServicesKit'; 10637 10638let nameDer = new Uint8Array([48,41,49,11,48,9,6,3,85,4,3,12,2,67,65,49,13,48,11,6,3,85,4,10,12,4,116,101,115,116,49,11,48,9,6,3,85,4,6,19,2,67,78]); 10639async function createX500DistinguishedName() { 10640 try { 10641 cert.createX500DistinguishedName(nameDer) 10642 .then((data) => { 10643 console.log('createX500DistinguishedName success'); 10644 }) 10645 .catch((err: BusinessError) => { 10646 console.error('createX500DistinguishedName catch, errCode: ' + err.code + ', errMsg: ' + err.message); 10647 }) 10648 } catch (error) { 10649 let e: BusinessError = error as BusinessError; 10650 console.error('createX500DistinguishedName catch, errCode: ' + e.code + ', errMsg: ' + e.message); 10651 } 10652} 10653``` 10654## X500DistinguishedName<sup>12+</sup> 10655 10656Provides APIs for managing the **X500DistinguishedName** instance. 10657 10658### getName<sup>12+</sup> 10659 10660getName(): string 10661 10662Obtains the DN in the form of a string. 10663 10664**Atomic service API**: This API can be used in atomic services since API version 12. 10665 10666**System capability**: SystemCapability.Security.Cert 10667 10668**Return value** 10669 10670| Type | Description | 10671| ------- | ------------------------------------------------- | 10672| string | DN in the form of a string obtained.| 10673 10674**Error codes** 10675 10676For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10677 10678| ID | Error Message | 10679| -------- | ------------- | 10680| 19020001 | memory error. | 10681| 19020002 | runtime error. | 10682| 19030001 | crypto operation error. | 10683 10684**Example** 10685 10686```ts 10687import { cert } from '@kit.DeviceCertificateKit'; 10688import { BusinessError } from '@kit.BasicServicesKit'; 10689 10690let nameDer = new Uint8Array([48,41,49,11,48,9,6,3,85,4,3,12,2,67,65,49,13,48,11,6,3,85,4,10,12,4,116,101,115,116,49,11,48,9,6,3,85,4,6,19,2,67,78]); 10691async function getName() { 10692 try { 10693 cert.createX500DistinguishedName(nameDer) 10694 .then((data) => { 10695 console.log('createX500DistinguishedName success'); 10696 console.info('createX500DistinguishedName getName: ' + JSON.stringify(data.getName())) 10697 }) 10698 .catch((err: BusinessError) => { 10699 console.error('createX500DistinguishedName catch, errCode: ' + err.code + ', errMsg: ' + err.message); 10700 }) 10701 } catch (error) { 10702 let e: BusinessError = error as BusinessError; 10703 console.error('createX500DistinguishedName catch, errCode: ' + e.code + ', errMsg: ' + e.message); 10704 } 10705} 10706``` 10707 10708### getName<sup>12+</sup> 10709 10710getName(type: string): Array\<string> 10711 10712Obtains DNs of the specified type. 10713 10714**Atomic service API**: This API can be used in atomic services since API version 12. 10715 10716**System capability**: SystemCapability.Security.Cert 10717 10718**Parameters** 10719 10720| Name | Type | Mandatory | Description | 10721| ------------ | ------ | ---- | -------------- | 10722| type | string | Yes | Type of the DNs to obtain.| 10723 10724**Return value** 10725 10726| Type | Description | 10727| ------- | ------------------------------------------------- | 10728| Array\<string> | DNs obtained.| 10729 10730**Error codes** 10731 10732For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10733 10734| ID | Error Message | 10735| -------- | ------------- | 10736| 401 | invalid parameters. Possible causes: <br>1. Mandatory parameters are left unspecified;<br>2. Incorrect parameter types;<br>3. Parameter verification failed.| 10737| 19020001 | memory error. | 10738| 19020002 | runtime error. | 10739| 19030001 | crypto operation error. | 10740 10741**Example** 10742 10743```ts 10744import { cert } from '@kit.DeviceCertificateKit'; 10745import { BusinessError } from '@kit.BasicServicesKit'; 10746 10747let nameStr = '/CN=Example CA/OU=test cert/O=test/L=XA/ST=SX/C=CN/CN=RSA CA/CN=XTS'; 10748async function getName() { 10749 try { 10750 cert.createX500DistinguishedName(nameStr) 10751 .then((data) => { 10752 console.log('createX500DistinguishedName success'); 10753 console.info('createX500DistinguishedName getName: ' + JSON.stringify(data.getName("CN"))) 10754 }) 10755 .catch((err: BusinessError) => { 10756 console.error('createX500DistinguishedName catch, errCode: ' + err.code + ', errMsg: ' + err.message); 10757 }) 10758 } catch (error) { 10759 let e: BusinessError = error as BusinessError; 10760 console.error('createX500DistinguishedName catch, errCode: ' + e.code + ', errMsg: ' + e.message); 10761 } 10762} 10763``` 10764 10765### getEncoded<sup>12+</sup> 10766 10767getEncoded(): EncodingBlob 10768 10769Obtains the data of the X.509 certificate **extensions** field. 10770 10771**Atomic service API**: This API can be used in atomic services since API version 12. 10772 10773**System capability**: SystemCapability.Security.Cert 10774 10775**Return value** 10776 10777| Type | Description | 10778| ------- | ------------------------------------------------- | 10779| [EncodingBlob](#encodingblob) | X.509 certificate extensions data obtained.| 10780 10781**Error codes** 10782 10783For details about the error codes, see [Certificate Error Codes](errorcode-cert.md). 10784 10785| ID | Error Message | 10786| -------- | ------------- | 10787| 19020001 | memory error. | 10788| 19020002 | runtime error. | 10789| 19030001 | crypto operation error. | 10790 10791**Example** 10792 10793```ts 10794import { cert } from '@kit.DeviceCertificateKit'; 10795import { BusinessError } from '@kit.BasicServicesKit'; 10796 10797let nameStr = '/CN=Example CA/OU=test cert/O=test/L=XA/ST=SX/C=CN/CN=RSA CA/CN=XTS'; 10798async function getEncoded() { 10799 try { 10800 cert.createX500DistinguishedName(nameStr) 10801 .then((data) => { 10802 console.log('createX500DistinguishedName success'); 10803 let encodingBlobData = data.getEncoded(); 10804 }) 10805 .catch((err: BusinessError) => { 10806 console.error('createX500DistinguishedName catch, errCode: ' + err.code + ', errMsg: ' + err.message); 10807 }) 10808 } catch (error) { 10809 let e: BusinessError = error as BusinessError; 10810 console.error('createX500DistinguishedName catch, errCode: ' + e.code + ', errMsg: ' + e.message); 10811 } 10812} 10813``` 10814