harmony 鸿蒙@ohos.security.certManager (Certificate Management) (System API)
@ohos.security.certManager (Certificate Management) (System API)
The certManager module provides system-level certificate management capabilities to ensure secure use and management of certificates throughout their lifecycle (installation, storage, use, and destruction).
NOTE
- The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
- This topic describes only the system APIs provided by the module. For details about its public APIs, see @ohos.security.certManager (Certificate Management).
Modules to Import
import { certificateManager } from '@kit.DeviceCertificateKit';
CMErrorCode
Enumerates the error codes used in the certificate management APIs.
System capability: System SystemCapability.Security.CertificateManager
Name | Value | Description |
---|---|---|
CM_ERROR_NOT_SYSTEM_APP | 202 | The caller is not a system application. System API: This is a system API. |
certificateManager.getAllAppPrivateCertificates
getAllAppPrivateCertificates(callback: AsyncCallback<CMResult>): void
Obtains all private credentials. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.ACCESS_CERT_MANAGER and ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
System capability: System SystemCapability.Security.CertificateManager
System API: This is a system API.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
callback | AsyncCallback<CMResult> | Yes | Callback used to return the result. If the operation is successful, err is null and data is credentialList in the CMResult object. Otherwise, err is an error object. |
Error codes
For details about the following error codes, see Certificate Management Error Codes.
ID | Error Message |
---|---|
201 | Permission verification failed. The application does not have the permission required to call the API. |
202 | Permission verification failed. A non-system application calls a system API. |
401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
17500001 | Internal error. |
Example
import { certificateManager } from '@kit.DeviceCertificateKit';
try {
certificateManager.getAllAppPrivateCertificates((err, cmResult) => {
if (err != null) {
console.error(`Failed to get all app private certificates. Code: ${err.code}, message: ${err.message}`);
} else {
if (cmResult == undefined) { // If the number of private credentials is 0, return undefined in cmResult.
console.info('the count of the app private certificates is 0');
} else if (cmResult.credentialList == undefined) {
console.info('The result of getting all app private certificates is undefined.');
} else {
let list = cmResult.credentialList;
console.info('Succeeded in getting all app private certificates.');
}
}
});
} catch (error) {
console.error(`Failed to get all app private certificates. Code: ${error.code}, message: ${error.message}`);
}
certificateManager.getAllAppPrivateCertificates
getAllAppPrivateCertificates(): Promise<CMResult>
Obtains all private credentials. This API uses a promise to return the result.
Required permissions: ohos.permission.ACCESS_CERT_MANAGER and ohos.permission.ACCESS_CERT_MANAGER_INTERNAL
System capability: System SystemCapability.Security.CertificateManager
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<CMResult> | Promise used to return all the private credentials obtained, that is, credentialList in the CMResult object. |
Error codes
For details about the following error codes, see Certificate Management Error Codes.
ID | Error Message |
---|---|
201 | Permission verification failed. The application does not have the permission required to call the API. |
202 | Permission verification failed. A non-system application calls a system API. |
17500001 | Internal error. |
Example
import { certificateManager } from '@kit.DeviceCertificateKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
certificateManager.getAllAppPrivateCertificates().then((cmResult) => {
if (cmResult == undefined) { // If the number of private credentials is 0, return undefined in cmResult.
console.info('the count of the app private certificates is 0');
} else if (cmResult.credentialList == undefined) {
console.info('The result of getting all app private certificates is undefined.');
} else {
let list = cmResult.credentialList;
console.info('Succeeded in getting all app private certificates.');
}
}).catch((err: BusinessError) => {
console.error(`Failed to get all app private certificates. Code: ${err.code}, message: ${err.message}`);
})
} catch (error) {
console.error(`Failed to get all app private certificates. Code: ${error.code}, message: ${error.message}`);
}
certificateManager.getAllSystemAppCertificates12+
getAllSystemAppCertificates(): Promise<CMResult>
Obtains all system credentials. This API uses a promise to return the result.
Required permissions: ohos.permission.ACCESS_CERT_MANAGER
System capability: System SystemCapability.Security.CertificateManager
System API: This is a system API.
Return value
Type | Description |
---|---|
Promise<CMResult> | Promise used to return all the system credentials obtained, that is, credentialList in the CMResult object. |
Error codes
For details about the following error codes, see Certificate Management Error Codes.
ID | Error Message |
---|---|
201 | Permission verification failed. The application does not have the permission required to call the API. |
202 | Permission verification failed. A non-system application calls a system API. |
17500001 | Internal error. |
Example
import { certificateManager } from '@kit.DeviceCertificateKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
certificateManager.getAllSystemAppCertificates().then((cmResult) => {
if (cmResult == undefined) { // If the number of system credentials is 0, return undefined in cmResult.
console.info('the count of the system certificates is 0');
} else if (cmResult.credentialList == undefined) {
console.info('The result of getting all system app certificates is undefined.');
} else {
let list = cmResult.credentialList;
console.info('Succeeded in getting all system app certificates.');
}
}).catch((err: BusinessError) => {
console.error(`Failed to get all system app certificates. Code: ${err.code}, message: ${err.message}`);
})
} catch (error) {
console.error(`Failed to get all system app certificates. Code: ${error.code}, message: ${error.message}`);
}
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Device Certificate Kit (Device Certificate Service)
harmony 鸿蒙Certificate Error Codes
harmony 鸿蒙Certificate Management Error Codes
harmony 鸿蒙Certificate Management Dialog Box Error Codes
harmony 鸿蒙@ohos.security.certManager (Certificate Management)
harmony 鸿蒙@ohos.security.certManagerDialog (Certificate Management Dialog Box)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦