• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15// [Start certificate_management_development_guidance]
16
17import { certificateManager } from '@kit.DeviceCertificateKit';
18import { BusinessError } from '@kit.BasicServicesKit';
19
20async function certificateManagerSample() {
21  /* 安装的凭据数据需要业务赋值,本例数据非凭据数据 */
22  let keystore: Uint8Array = new Uint8Array([
23    0x30,0x82,0x0c,0x26,0x02,0x01,0x03,0x30,0x82,0x0b,0xe0,0x06,0x09,0x2a,0x86,0x48,
24    0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x82,0x0b,0xd1,0x04,0x82,0x0b,0xcd,0x30,0x82,
25    0x0b,0xc9,0x30,0x82,0x05,0x6e,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,
26    0x01,0xa0,0x82,0x05,0x5f,0x04,0x82,0x05,0x5b,0x30,0x82,0x05,0x57,0x30,0x82,0x05,
27    0x53,0x06,0x0b,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x0a,0x01,0x02,0xa0,0x82,
28    0x04,0xfa,0x30,0x82,0x04,0xf6,0x30,0x28,0x06,0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d,
29    0x01,0x0c,0x01,0x03,0x30,0x1a,0x04,0x14,0xb6,0x80,0x7d,0xb9,0xc3,0x44,0x84,0x1f,
30    0x44,0xe6,0x95,0x6a,0x98,0xa1,0xcb,0x97,0xfb,0x2b,0xcc,0x5a,0x02,0x02,0x04,0x00,
31    0x04,0x82,0x04,0xc8,0x78,0xa7,0x16,0x45,0x40,0xf0,0xec,0xac,0x3e,0x34,0x17,0xd7,
32    0x8b,0x5c,0xca,0x85,0x29,0x0b,0x08,0xef,0xa2,0xf0,0x6d,0x55,0xd7,0xde,0x96,0xa5,
33    0x49,0x6d,0x9d,0xa6,0xe6,0x00,0xd7,0x2c,0x65,0xf6,0xc2,0xd1,0xe8,0x70,0xfb,0xb5,
34    0xd9,0xc6,0x7d,0xd4,0x28,0x45,0x17,0x4f,0x4f,0xd9,0x9b,0xab,0xe2,0xdc,0xe7,0x22,
35    0x6c,0x1e,0xbc,0xd6,0xf0,0x38,0x0b,0xd7,0xd9,0xfc,0xa7,0xb4,0x87,0x95,0x96,0xc3,
36    0x93,0xc0,0xb5,0x37,0xf4,0x64,0xfe,0xe5,0x07,0xac,0x41,0x2d,0xf5,0xeb,0xe3,0x8b,
37    0xc2,0x74,0x73,0x13,0x3b,0x5f,0x17,0x54,0x2d,0x31,0x20,0x69,0x1c,0xab,0x66,0xba,
38    0x06,0x43,0x03,0xa3,0x69,0x54,0x72,0x70,0x5f,0x78,0xd2,0xec,0xdd,0x50,0xb8,0x25,
39    0x03,0xd4,0xec,0x2d,0x92,0x96,0x9f,0xcc,0xa6,0x4a,0x50,0x34,0x1c,0xfc,0xe3,0xc2,
40    0x6b,0x65,0xec,0xb3,0x1c,0xc8,0xf2,0xd0,0x79,0xf0,0x28,0x61,0x9a,0xfe,0xea,0x7f,
41    0x16,0x38,0xe1,0xf4,0x7f,0x86,0xfe,0x73,0x67,0xc9,0x60,0x73,0xd8,0xef,0x2c,0x6b,
42    0xde,0x88,0x37,0xc5,0xd7,0x18,0x60,0x74,0x97,0x07,0x85,0x70,0x74,0x30,0x66,0x8f,
43    0x11,0x4a,0xb9,0x18,0xed,0xfc,0xc7,0xdb,0x63,0x58,0x7b,0x57,0x0d,0xfa,0x43,0x81,
44    0xbd,0x34,0xfc,0x17,0xd3,0x2a,0xa9,0x74,0xa0,0x2c,0x1b,0xe2,0xaa,0x3d,0xd2,0x84,
45    0x18,0xaa,0x2a,0x0e,0xa8,0xcc,0x2a,0xc4,0x39,0x60,0x29,0xb5,0x03,0xaf,0xea,0x96,
46    0xcf,0xa5,0x67,0x4c,0xa7,0x59,0x76,0xea,0x8a,0x60,0xd6,0xd8,0xc3,0x9e,0x0e,0xad,
47    0xd6,0xa0,0x5a,0x00,0x7c,0xa6,0xe8,0x62,0xa4,0x0a,0x53,0xcc,0x48,0xf0,0x4d,0x6d,
48    0xda,0xb3,0xa9,0x82,0x37,0x75,0xff,0x20,0xa9,0xe8,0x6e,0xc8,0x4a,0x8a,0x81,0x84,
49    0x7a,0x1d,0x02,0x40,0xd9,0x76,0xee,0x89,0x62,0xd5,0x57,0x19,0xc8,0x9a,0x6a,0x22,
50    0x8d,0x01,0x8f,0xc9,0x14,0x72,0xf9,0x90,0xa3,0x0f,0x5f,0x23,0x32,0xc4,0xd5,0x79,
51    0x53,0x1f,0xbc,0x3a,0xf4,0x19,0x7f,0x93,0xb7,0x8b,0x0b,0xb9,0xeb,0x1f,0xa2,0x5c,
52    0x93,0x0e,0x5f,0x29,0x87,0xea,0x67,0x4d,0x5d,0x2b,0x5e,0x29,0x81,0xbd,0x3d,0xfc,
53    0xdf,0x92,0x50,0x19,0xc2,0x50,0x4d,0x07,0x76,0x08,0xfc,0xbe,0xd1,0x73,0x64,0xb7,
54    0x22,0x6f,0xb7,0x89,0x93,0xc1,0xb1,0x44,0x42,0x27,0xf5,0x61,0x06,0x32,0xd1,0xc0,
55    0xdb,0x92,0x51,0x1b,0xd3,0x5c,0x95,0x85,0x0e,0x66,0xc5,0xe9,0xf5,0x7f,0x44,0x52,
56    0x49,0xfb,0x0a,0x83,0x02,0x6e,0x69,0x6c,0xf1,0x6f,0xe5,0xa1,0xa0,0x5d,0x8a,0xd3,
57    0x4f,0x9d,0x0a,0x08,0x1b,0x32,0x70,0xe3,0xf3,0xf0,0x63,0xda,0x37,0x90,0x96,0x3f,
58    0xac,0xf7,0x3d,0xd5,0xeb,0x08,0xc1,0x51,0x91,0x75,0x2c,0x0f,0xf1,0x5b,0x39,0xce,
59    0x05,0x06,0x65,0x1c,0xe8,0x36,0xb0,0x86,0x6e,0xbe,0xb9,0x25,0xd6,0xdf,0x5c,0x50,
60    0x56,0x99,0x69,0x8e,0x92,0xbe,0xa1,0x03,0x18,0xd6,0x34,0xa6,0x98,0x53,0x3a,0xb7,
61    0x96,0xcb,0xa8,0x1d,0xc9,0x9e,0x92,0x15,0xf4,0x99,0x7e,0x58,0x81,0x99,0x84,0xa0,
62    0x67,0xa5,0x77,0x1e,0xa9,0xac,0xc2,0xcf,0xd8,0x7a,0x68,0xef,0x35,0x9e,0xb6,0xb7,
63    0x78,0x6b,0x43,0x12,0x53,0x93,0x7b,0x50,0x94,0x37,0x48,0x75,0x98,0x27,0x0f,0x73,
64    0x1a,0xb7,0x2f,0x19,0x7e,0x42,0x08,0x02,0x05,0x42,0x71,0xd6,0x26,0x64,0x04,0x25,
65    0x87,0xd9,0x02,0x05,0x1f,0x79,0x6b,0x9b,0x0e,0xfa,0x10,0x7b,0xf3,0x96,0x3f,0x53,
66    0x02,0x9d,0x80,0x13,0xd7,0x30,0x03,0x24,0x96,0x21,0x05,0xdb,0x2d,0xe9,0xc8,0x51,
67    0x30,0x42,0x6d,0xa9,0xe8,0x39,0xb0,0xa9,0x59,0xb9,0x21,0x22,0x98,0x41,0x0e,0x33,
68    0x0d,0x7f,0x7a,0x69,0x45,0x0b,0xf1,0xac,0xfd,0xaa,0xaa,0x45,0x7f,0x78,0x24,0xf8,
69    0x56,0x85,0x3b,0x4b,0x95,0x78,0x40,0xc7,0x2f,0xfc,0xb6,0xb7,0x5f,0xa2,0xf9,0xe9,
70    0x80,0x4c,0x4a,0xbf,0x4f,0xcb,0xb9,0x51,0x7c,0x18,0xb7,0xb7,0x70,0xf1,0x4c,0x96,
71    0xd2,0x4a,0x44,0xb9,0xa6,0x22,0xc9,0x95,0xf5,0x99,0xbd,0x8c,0xf2,0x45,0x88,0xfb,
72    0x2f,0xe0,0x38,0x42,0xc8,0xe5,0x0d,0x55,0x05,0x0f,0xb9,0x91,0x7d,0xaf,0x27,0x91,
73    0xb3,0xc4,0x83,0x46,0x49,0x1a,0xce,0x3a,0xff,0x1b,0x58,0xc9,0xa4,0x22,0x82,0x57,
74    0x7f,0xda,0x5f,0xae,0xea,0xae,0x96,0x91,0xef,0xde,0x4e,0x25,0x66,0xbb,0xe9,0xb3,
75    0xa7,0xbc,0x12,0xc4,0x5f,0xee,0xc6,0x13,0x9c,0xd9,0xbc,0x14,0xef,0x3d,0x7b,0xa4,
76    0x91,0x4a,0x77,0xfd,0x18,0x9c,0xc7,0x38,0xaf,0x24,0x3f,0x6c,0x8f,0x8f,0x6e,0x2c,
77    0x38,0x7c,0xa4,0xba,0xc7,0x70,0x90,0x6d,0x5e,0x51,0x3c,0xe0,0x3d,0xc5,0xa8,0x44,
78    0xb0,0xf4,0x0b,0xba,0xe0,0x0e,0x8b,0x65,0xeb,0x04,0xfd,0x1a,0x8b,0x94,0xbf,0xfe,
79    0xf0,0x64,0xa4,0xfa,0xb4,0xe1,0x11,0xd4,0x95,0x13,0xee,0xce,0xf6,0x14,0xf7,0x1c,
80    0xbc,0xf5,0x64,0x90,0x88,0x69,0xb2,0xfd,0x26,0x26,0x83,0xa7,0x4c,0x3d,0x27,0xae,
81    0x3c,0x68,0xb5,0xcc,0x9f,0x46,0xc2,0x9a,0x95,0x9a,0xa7,0x8b,0x4a,0x14,0xf7,0x80,
82    0x9f,0x04,0xf9,0x39,0x3b,0x55,0x9e,0xb5,0x1c,0x79,0x7d,0x2d,0x9b,0x29,0xb9,0x7c,
83    0x61,0x01,0xf5,0x26,0x1e,0xa0,0xcb,0x18,0xaf,0xc6,0x6d,0x2f,0x42,0xb7,0xa5,0x94,
84    0x91,0xa5,0xc0,0x15,0xd9,0x18,0x4e,0xb6,0xc3,0x77,0x9e,0x59,0x6e,0x61,0x48,0x32,
85    0xcf,0x5e,0x09,0x3a,0x17,0x48,0x59,0x68,0x9a,0x6c,0x7f,0xd3,0x71,0xd8,0x2c,0xce,
86    0x58,0x68,0x33,0x79,0xe6,0xb6,0xf0,0xb5,0xac,0xb0,0xa4,0xc0,0x10,0x0f,0xad,0x02,
87    0x19,0x58,0x53,0x5a,0x9a,0x5d,0x84,0xa6,0x8e,0x3c,0xc8,0xa9,0x22,0xb5,0x2a,0x39,
88    0x3f,0xf8,0x76,0x53,0xea,0x7b,0x23,0x81,0x2b,0xe1,0x1d,0x63,0xb3,0x83,0x76,0xc8,
89    0xd3,0x5e,0xba,0x97,0x79,0x9b,0xfb,0xf3,0x1e,0x10,0xac,0xd8,0x2e,0xa0,0x64,0xba,
90    0x02,0x21,0x18,0x05,0xd1,0x30,0xdd,0x33,0x32,0x98,0x3d,0x0d,0x22,0xb4,0xda,0x8d,
91    0xa0,0x9a,0x3a,0x97,0x0f,0xa5,0xe1,0xf1,0x56,0x17,0xd8,0xbd,0x15,0xd3,0xd6,0xe0,
92    0x20,0x95,0x7b,0x6a,0x63,0x59,0x80,0xee,0xcd,0x60,0xb1,0xb0,0xba,0x8d,0x6a,0x4c,
93    0x3d,0x5c,0xac,0x1a,0x87,0x1d,0x07,0xfe,0x69,0x81,0x8f,0x5d,0xba,0x64,0x3f,0xea,
94    0xdf,0x36,0xb3,0x07,0x6c,0xbc,0x5b,0xe8,0xc0,0x5c,0x9a,0xd1,0x16,0xe3,0x2e,0xa5,
95    0x92,0x5b,0xba,0x89,0x55,0x65,0x5d,0x14,0xd2,0x36,0x9e,0xfd,0x6d,0xcf,0x9d,0x68,
96    0x10,0x7f,0xb6,0xdf,0x6b,0x9a,0x9b,0xd4,0x6b,0x37,0xfd,0x77,0xde,0x39,0x59,0xed,
97    0xe3,0xdb,0x65,0xe8,0xa4,0x15,0x4a,0x6d,0xb4,0xad,0xb8,0x36,0xe1,0x3a,0xf8,0x6a,
98    0xfe,0x6e,0x1f,0x02,0x15,0x09,0x36,0x44,0xb7,0x52,0x5b,0x79,0x3c,0x8e,0xfb,0x20,
99    0x62,0xdb,0x7b,0xb6,0xb1,0x43,0xea,0x29,0xff,0x10,0xef,0x24,0x9c,0x4d,0xc2,0xa8,
100    0x98,0xaa,0x29,0x59,0x85,0x06,0xc3,0xdb,0xcf,0xc2,0x71,0xfa,0xad,0x7b,0xd5,0xf7,
101    0x50,0x53,0xc5,0x75,0x97,0x15,0x42,0x90,0x8f,0xf1,0xed,0x6a,0x98,0x83,0x59,0x15,
102    0x23,0xa7,0xea,0xe9,0xed,0x22,0xec,0x0a,0x41,0x4c,0xc2,0x35,0x54,0xd9,0xec,0x4b,
103    0xb8,0x3f,0xd0,0x68,0xed,0xa7,0x83,0x4e,0x42,0x29,0x5c,0x4d,0xa3,0x79,0x3e,0x59,
104    0x86,0x04,0x62,0x24,0x9d,0x7b,0xb3,0x69,0xe9,0x82,0x57,0xdb,0xbf,0xeb,0x98,0x4f,
105    0x59,0x7e,0x8d,0x8f,0x69,0x56,0xdc,0x3f,0xeb,0x01,0xcf,0x82,0x05,0x1e,0xe7,0x6d,
106    0xff,0xb2,0x67,0xd8,0x34,0x68,0xf7,0xd0,0xee,0x6d,0xc6,0x22,0x4c,0x4d,0x36,0xd1,
107    0xf5,0x5a,0xab,0xbb,0x41,0x43,0x4d,0xef,0x2c,0x62,0x64,0x28,0x31,0x46,0x30,0x1f,
108    0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x14,0x31,0x12,0x1e,0x10,0x00,
109    0x6c,0x00,0x64,0x00,0x71,0x00,0x20,0x00,0x74,0x00,0x65,0x00,0x73,0x00,0x74,0x30,
110    0x23,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x09,0x15,0x31,0x16,0x04,0x14,
111    0x44,0x37,0x75,0x8f,0xcd,0x94,0x90,0x07,0x3e,0x38,0x20,0xb7,0x1b,0x3f,0x0d,0x3d,
112    0x40,0x85,0x32,0x6a,0x30,0x82,0x06,0x53,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
113    0x01,0x07,0x06,0xa0,0x82,0x06,0x44,0x30,0x82,0x06,0x40,0x02,0x01,0x00,0x30,0x82,
114    0x06,0x39,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0x30,0x28,0x06,
115    0x0a,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x0c,0x01,0x06,0x30,0x1a,0x04,0x14,0xc8,
116    0xe2,0x48,0x69,0x85,0x06,0xb3,0x34,0x55,0xf1,0xfe,0x9c,0x95,0x92,0xbd,0x73,0xcd,
117    0x50,0xf4,0x88,0x02,0x02,0x04,0x00,0x80,0x82,0x06,0x00,0xb6,0x66,0x06,0x1a,0x84,
118    0xb1,0xb7,0xf8,0xca,0x74,0xe1,0x7c,0x23,0x94,0x5f,0xb3,0x73,0xda,0x81,0x51,0x0e,
119    0x4d,0x07,0xcd,0x8a,0x68,0xd5,0x15,0x98,0x57,0xc1,0xb9,0x94,0x30,0xc7,0x97,0x40,
120    0x3b,0xa4,0xc0,0xd5,0xfe,0xd3,0x9f,0x92,0xe9,0x6a,0xeb,0x52,0x1c,0xd8,0x89,0x26,
121    0xf4,0x1b,0x49,0xe9,0xef,0x45,0x0b,0x33,0x36,0x73,0x1b,0x91,0x2b,0x75,0xff,0x9b,
122    0x12,0x41,0xc7,0x80,0xb1,0x4a,0x12,0xaf,0x02,0x8d,0x4b,0xea,0xcd,0x0e,0xc6,0x03,
123    0x14,0x4c,0x79,0xef,0xa6,0xc2,0xf6,0x86,0xd3,0x19,0xfd,0xe6,0x85,0xfa,0x3b,0x0d,
124    0x3b,0xb2,0x98,0xd2,0xff,0xa0,0xfe,0x65,0x63,0xc9,0xc2,0xa7,0xf4,0x0d,0x98,0x57,
125    0xab,0xd5,0x7b,0x58,0x87,0x62,0x58,0x74,0x40,0x75,0x06,0x8f,0x4a,0x93,0xff,0x76,
126    0xbb,0xd3,0x19,0x4d,0xf8,0x04,0x89,0xa4,0xc5,0xe3,0xbe,0xde,0x60,0x04,0x7f,0x52,
127    0x58,0x11,0x51,0x6f,0xa9,0xf9,0x06,0x6d,0x03,0x83,0xcd,0xa7,0x01,0xf8,0x2d,0xa0,
128    0xe6,0x45,0x63,0x85,0x46,0x7c,0x9b,0x55,0x86,0xfd,0xe9,0xc3,0xd4,0xeb,0xeb,0x3e,
129    0x2b,0x0e,0x33,0x8a,0x9f,0x40,0xe3,0x9d,0x52,0xe3,0xf8,0x6f,0x1a,0x4d,0x5f,0xaf,
130    0x78,0x12,0x56,0x56,0xab,0x3d,0xbd,0x36,0x8e,0xd9,0xa9,0xc4,0xfc,0xd3,0x21,0x6b,
131    0xa7,0xa0,0xa3,0xc6,0x50,0x41,0x43,0xdb,0xd0,0xf7,0x16,0x08,0x06,0x0d,0xed,0x15,
132    0x90,0xdc,0x31,0xeb,0x0d,0x4b,0x7b,0x1c,0xa6,0x32,0xca,0x52,0xaa,0x3a,0x71,0xc2,
133    0xb7,0xce,0x42,0xd4,0x90,0xbe,0x65,0x0b,0x55,0x54,0x79,0x6b,0xbf,0xbc,0xf7,0x1d,
134    0x5f,0x14,0x4a,0x02,0x4c,0x63,0x16,0x6d,0x85,0xad,0xb3,0x1f,0x11,0x43,0x3f,0xd3,
135    0x4d,0x3b,0xfc,0x96,0x79,0xca,0xa5,0x9e,0xc1,0xdf,0xbc,0x94,0x2d,0x46,0xe2,0xe7,
136    0x1a,0x93,0xfc,0xc5,0x09,0x16,0x8d,0x91,0x41,0xc0,0x59,0x4f,0x9c,0x76,0x94,0x86,
137    0xf2,0x59,0x5d,0xca,0xa9,0x20,0x93,0x10,0xd6,0x45,0x3b,0x30,0x55,0xdf,0x96,0x9f,
138    0x60,0x06,0x7c,0x9a,0xb9,0x24,0x1e,0xe0,0xae,0x65,0xd5,0x4b,0x4a,0xe2,0x55,0xc7,
139    0x09,0xb5,0x51,0x40,0x07,0x7e,0xe1,0xef,0x34,0x63,0x7b,0x3a,0xa9,0x98,0x2f,0x09,
140    0xe1,0xfd,0x7a,0xb3,0x29,0x79,0xfc,0xf5,0xbd,0x3c,0x3c,0x05,0x02,0xd5,0xc5,0x86,
141    0xaf,0x9a,0xd3,0x10,0x7e,0xc3,0x1b,0xf7,0x73,0x64,0xd6,0x27,0x04,0x08,0xee,0x7b,
142    0x49,0x2d,0x21,0x2e,0xd8,0xbc,0x29,0x3a,0x80,0x82,0x2d,0xed,0xf2,0xaf,0x08,0x55,
143    0xce,0x80,0x9c,0xf2,0xeb,0x60,0x38,0x12,0x27,0x31,0xa0,0x2f,0x64,0xbf,0x21,0x8c,
144    0x63,0x88,0x90,0xee,0x9e,0xc0,0x5f,0xb8,0xea,0xa5,0xf3,0x26,0x01,0x65,0xe3,0x97,
145    0xb6,0x17,0x6f,0x6a,0x48,0x77,0xc0,0x26,0x00,0x65,0x19,0xc8,0xe8,0xc6,0x94,0x5d,
146    0x03,0xcb,0xc5,0xa9,0x5d,0xc5,0x4b,0x8f,0xcf,0x33,0xeb,0x2a,0x9a,0x5a,0x75,0xe4,
147    0xec,0x7d,0x59,0xab,0xd1,0x9a,0xb7,0x73,0x54,0x2a,0xe3,0x3d,0x63,0x62,0xcf,0xa0,
148    0x5f,0xb5,0xf4,0x12,0x61,0xa6,0xbb,0xd9,0xf6,0x3f,0xc9,0x0c,0x96,0x9f,0xf8,0xa2,
149    0x38,0x2c,0xb5,0xdf,0x26,0x07,0x0d,0xc5,0x43,0x33,0xe3,0x69,0x31,0x56,0x7a,0x4c,
150    0x3c,0xc7,0x44,0xa4,0x9f,0x62,0xa4,0x5f,0x9b,0xdd,0xe4,0x24,0x28,0x1b,0xe6,0x72,
151    0xc8,0x8d,0xe7,0x40,0x4e,0x81,0xe6,0x8e,0x3c,0xb5,0x53,0xe3,0x0b,0x43,0x69,0xaf,
152    0x7d,0xb8,0xfc,0xf2,0xb5,0x2a,0xad,0x95,0xe1,0xb7,0xbd,0xdf,0x3b,0x16,0xac,0x7b,
153    0x9f,0xad,0x8f,0x66,0x7d,0x72,0x3e,0xf4,0xdb,0xf5,0xdd,0x91,0x09,0x7a,0x2b,0xf8,
154    0x3d,0xa6,0x26,0xec,0x22,0x00,0xcc,0xe6,0xab,0x03,0xe6,0xbe,0x7b,0x70,0x09,0x07,
155    0x72,0xfc,0x32,0xf1,0x46,0xda,0x7e,0x0a,0x97,0xcf,0x42,0xaf,0x2d,0x70,0x56,0x34,
156    0xce,0xc9,0x7b,0xca,0xb6,0xd5,0xc8,0xd4,0xe3,0x96,0x62,0x02,0x54,0x66,0x65,0x88,
157    0xf7,0xe5,0xb6,0x68,0x0d,0x61,0x8d,0x71,0xa4,0x39,0xd0,0xe5,0xf7,0x38,0x27,0x00,
158    0x65,0x53,0xd4,0x1b,0x0a,0x94,0x63,0xa8,0x19,0xc3,0x2a,0x5b,0x2a,0x6a,0xb9,0x19,
159    0xfa,0x04,0x3e,0xc5,0x0a,0xc6,0x5c,0xc0,0x3f,0xbb,0x3f,0x18,0x9b,0x27,0xdc,0xd5,
160    0xf7,0x2b,0x54,0x30,0x68,0x47,0x45,0xae,0x12,0xe4,0xdc,0x71,0xa5,0xbd,0x4b,0x6e,
161    0xd6,0xba,0x6e,0x96,0xa6,0x73,0x77,0xc5,0x2b,0x48,0x6d,0x7e,0xbb,0x44,0x6f,0xd5,
162    0x5d,0x17,0xcb,0xd6,0x96,0xb8,0xd1,0x06,0xe1,0xea,0x2f,0xa6,0x86,0x1b,0x81,0x97,
163    0xbe,0xa0,0xfb,0x9a,0x20,0x6d,0xf5,0x33,0xeb,0x64,0xd3,0x89,0x68,0x8c,0x8b,0xa9,
164    0x4f,0x19,0x51,0xb5,0x8d,0x89,0x74,0x51,0x2c,0x90,0x38,0x0e,0x0d,0x18,0x53,0x87,
165    0x31,0x62,0x3d,0x54,0x1e,0x74,0xc0,0x9a,0xc3,0x37,0xdd,0x36,0x00,0x5c,0xc9,0xb4,
166    0x1d,0x57,0x0b,0xb2,0x43,0x25,0x2b,0xb6,0xee,0x83,0xda,0xfd,0xad,0x41,0x9d,0xf4,
167    0xdf,0x60,0xfe,0xa1,0xd0,0x1c,0x78,0x3e,0x36,0x17,0x38,0x4a,0xb2,0x42,0x15,0xac,
168    0xa6,0x5e,0x88,0xe3,0x11,0x76,0x48,0xc9,0xcd,0x86,0xbb,0x2b,0x7a,0xab,0xa9,0xfe,
169    0x76,0x0f,0xb5,0xb4,0x6e,0x1a,0xfd,0x5f,0xa4,0x20,0x32,0xb2,0xb5,0x4d,0x25,0xa4,
170    0x34,0xd3,0x06,0xf4,0xc6,0x6e,0x83,0xcb,0x5e,0x87,0xe0,0x25,0xee,0x17,0x58,0x2e,
171    0xaa,0x3c,0x54,0xf1,0xb5,0x33,0xcd,0xa7,0x37,0x78,0x10,0x25,0x23,0x90,0x8a,0x80,
172    0x3f,0xbb,0x4b,0xdf,0x89,0xc2,0xee,0x5c,0x78,0x33,0x1a,0x76,0x3e,0xf9,0x46,0x49,
173    0x50,0x0c,0x39,0x38,0x33,0x6b,0xbe,0xae,0xec,0xec,0xf9,0xf5,0x1c,0x40,0xa1,0xa7,
174    0x29,0x0e,0x02,0x7a,0xd7,0xb9,0x0b,0x2e,0x6f,0x9f,0x33,0x97,0x63,0x87,0xe0,0xb7,
175    0xf6,0x9e,0xa0,0x43,0xa6,0xbe,0x04,0x3f,0x3f,0x8a,0xcc,0x8d,0xd3,0xbc,0x15,0x0e,
176    0x9b,0xb7,0x99,0xc1,0x3f,0xfa,0xaf,0x8a,0xc4,0x67,0x0d,0x36,0xda,0xab,0xf5,0xe9,
177    0x77,0xa9,0x84,0x0b,0xf9,0x22,0x49,0x15,0x9d,0x72,0x62,0x73,0x21,0x90,0x14,0x6e,
178    0x4b,0x2d,0x50,0x80,0x02,0x5e,0x79,0x66,0x7d,0x8c,0x5b,0xf8,0x2a,0x0c,0x2e,0x62,
179    0x15,0x85,0x78,0xce,0xa7,0xb6,0x33,0x8f,0xba,0xe4,0xb1,0xa5,0x9e,0xea,0x66,0x9e,
180    0x9c,0x98,0x7d,0x90,0x75,0x6f,0xd4,0xc0,0xd5,0x42,0x5d,0x5e,0xd4,0xab,0xed,0x1e,
181    0xe0,0x77,0x48,0xaf,0x13,0xac,0x89,0x8c,0x2a,0x2a,0x6b,0xb1,0x45,0xca,0xae,0x86,
182    0xfc,0xd8,0x15,0x4e,0xae,0xce,0x00,0x63,0x71,0xa6,0xef,0x43,0xdd,0x1c,0x77,0x21,
183    0x85,0xa8,0xd2,0x46,0x61,0xf0,0xfd,0xcb,0x43,0x31,0x41,0x35,0xda,0x2f,0xa9,0xc8,
184    0xb0,0x5f,0xd6,0xc9,0x7b,0x43,0x97,0x28,0xfa,0x2e,0xe7,0x07,0x8e,0x32,0xd5,0xf5,
185    0x30,0x2f,0x76,0x51,0x4b,0x21,0xcf,0xbd,0xc2,0x3a,0x5e,0x85,0x60,0x2b,0x42,0xc5,
186    0x56,0x70,0xf1,0xfb,0xce,0xd5,0xee,0x4f,0x30,0x33,0x08,0xea,0x3b,0xa7,0x31,0x54,
187    0x67,0xc2,0x07,0x2d,0x7c,0x2f,0x43,0xbe,0x34,0x34,0xd4,0x11,0x5c,0x8f,0x94,0x6a,
188    0x77,0xcb,0x03,0x77,0x48,0x33,0xac,0x77,0x78,0x42,0x6c,0x6f,0x08,0x93,0x23,0x5c,
189    0xb8,0x6e,0xae,0xac,0xd0,0x33,0x85,0x1a,0x55,0xd5,0x85,0xa7,0x00,0xf0,0xf9,0x01,
190    0x58,0xac,0x39,0x10,0x05,0x45,0x3e,0xb0,0xa9,0x86,0x12,0x78,0xe7,0xad,0xb0,0xee,
191    0x4f,0xc7,0x34,0xf4,0x09,0x9c,0x70,0x77,0xa7,0x41,0xb3,0x54,0xc3,0xc4,0xa0,0xf2,
192    0x72,0x50,0x74,0x9c,0xed,0x16,0x45,0x92,0x15,0xa8,0x42,0x86,0x93,0x4e,0x28,0x79,
193    0x1e,0x80,0x7a,0x13,0xae,0x4d,0x37,0x55,0xeb,0xbd,0x83,0x35,0xec,0x20,0xa1,0x83,
194    0x19,0x50,0x30,0x02,0x6c,0x48,0x78,0x3b,0xa9,0x6f,0x18,0x57,0x69,0x3a,0x5b,0xdb,
195    0xd6,0x77,0x7f,0x5c,0x0d,0xe3,0xd1,0xd0,0x27,0x1f,0x3f,0xd2,0xfb,0x6b,0xab,0x36,
196    0x44,0x58,0x6f,0xf4,0xa2,0x45,0x32,0xc9,0x05,0x67,0xd9,0x1a,0x9c,0x9b,0x63,0x31,
197    0x7a,0x54,0xbd,0xa0,0x63,0x7a,0x01,0x73,0xbc,0xcc,0xd2,0xe2,0x44,0x17,0xd2,0xd7,
198    0xb8,0x76,0x7e,0xb7,0x5a,0x04,0xfc,0xb9,0xd9,0xed,0xd2,0x76,0x38,0x21,0x71,0xfc,
199    0x83,0x55,0x89,0x30,0x6e,0xf8,0x0d,0xc0,0xe7,0xb6,0x8e,0x1a,0x44,0xf6,0x8d,0xdb,
200    0x2a,0x01,0xf6,0x55,0x6f,0x43,0xbe,0x66,0x39,0xd7,0xeb,0x7c,0x5a,0xb8,0xb2,0xae,
201    0x9c,0xf0,0x7b,0xb8,0xbd,0x4e,0x3b,0xf0,0x67,0x15,0x47,0xc7,0x62,0x6c,0xe5,0xe9,
202    0x96,0xb8,0x97,0x10,0x3a,0x1d,0xf2,0x22,0xf4,0x10,0x92,0x46,0xb0,0x09,0xda,0x98,
203    0xff,0xef,0xa9,0x1f,0xe8,0x23,0x52,0xfa,0x30,0x9b,0x4b,0xf1,0xe1,0xb6,0x13,0xd4,
204    0xd7,0x2c,0x37,0x1d,0x71,0x91,0x0f,0x0a,0x22,0x9d,0x31,0x2a,0x5e,0x70,0xa1,0xe2,
205    0x7d,0xeb,0x3d,0x06,0xc6,0xfb,0xe7,0x96,0x96,0x43,0xcc,0xdc,0x29,0xa1,0xfa,0xbb,
206    0x45,0x16,0x4c,0xbe,0xa1,0xad,0xce,0x0e,0x8b,0x95,0x50,0xac,0x7e,0x8d,0x68,0x08,
207    0xd4,0xe2,0xa6,0x63,0x70,0xb4,0x1e,0x1a,0x80,0xcb,0x6d,0xa6,0xf5,0xf5,0xcc,0xe8,
208    0xeb,0xc2,0x49,0x08,0x72,0xf3,0xad,0x4a,0xb9,0x0a,0xec,0xf7,0x35,0x97,0x6f,0x72,
209    0x0c,0x48,0xc6,0xa8,0x54,0xc7,0x93,0xd4,0xf7,0x70,0x5a,0xe9,0x16,0x08,0xb5,0xfc,
210    0xf9,0xb2,0xb6,0xe4,0xc2,0xd4,0xfd,0x31,0xe9,0xe6,0x3c,0x3a,0x67,0xcc,0x35,0xf5,
211    0xfd,0x81,0xb6,0x14,0xff,0xb8,0xfb,0x4f,0x0f,0xc2,0x2d,0xd0,0x57,0xdf,0xa4,0x5f,
212    0x1e,0x4d,0x01,0x41,0x4f,0xfe,0x76,0x50,0x66,0x83,0x75,0x90,0x06,0xbf,0x2d,0xf1,
213    0x27,0x46,0x7e,0x32,0xc4,0xc5,0x2f,0xf4,0x26,0x7f,0x46,0x30,0x3d,0x30,0x21,0x30,
214    0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1a,0x05,0x00,0x04,0x14,0x33,0x7b,0x5c,0xd1,
215    0x1b,0xad,0x79,0x93,0x10,0xa3,0x79,0x2e,0xae,0x8b,0x10,0x87,0xba,0x28,0xf7,0xa6,
216    0x04,0x14,0x84,0x78,0x82,0x85,0xc4,0x9e,0xa2,0x14,0x4f,0xad,0x59,0x15,0x3d,0x23,
217    0xe6,0x62,0xbf,0x6d,0x8c,0x06,0x02,0x02,0x04,0x00
218  ]);
219
220  /* 安装凭据对应的密码,业务赋值 */
221  let keystorePwd: string = 'huawei';
222  let appKeyUri: string = '';
223  try {
224    /* 安装私有凭据 */
225    const res: certificateManager.CMResult = await certificateManager.installPrivateCertificate(keystore, keystorePwd, 'testPriCredential');
226    appKeyUri = (res.uri != undefined) ? res.uri : '';
227  } catch (err) {
228    let e: BusinessError = err as BusinessError;
229    console.error(`Failed to install private certificate. Code: ${e.code}, message: ${e.message}`);
230  }
231
232  try {
233    /* srcData为待签名、验签的数据,业务自行赋值 */
234    let srcData: Uint8Array = new Uint8Array([
235      0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01,
236    ]);
237
238    /* 构造签名的属性参数 */
239    const signSpec: certificateManager.CMSignatureSpec = {
240      purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_SIGN,
241      padding: certificateManager.CmKeyPadding.CM_PADDING_PSS,
242      digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256
243    };
244
245    /* 签名 */
246    const signHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, signSpec);
247    await certificateManager.update(signHandle.handle, srcData);
248    const signResult: certificateManager.CMResult = await certificateManager.finish(signHandle.handle);
249
250    /* 构造验签的的属性参数 */
251    const verifySpec: certificateManager.CMSignatureSpec = {
252      purpose: certificateManager.CmKeyPurpose.CM_KEY_PURPOSE_VERIFY,
253      padding: certificateManager.CmKeyPadding.CM_PADDING_PSS,
254      digest: certificateManager.CmKeyDigest.CM_DIGEST_SHA256
255    };
256
257    /* 验签 */
258    const verifyHandle: certificateManager.CMHandle = await certificateManager.init(appKeyUri, verifySpec);
259    await certificateManager.update(verifyHandle.handle, srcData);
260    const verifyResult = await certificateManager.finish(verifyHandle.handle, signResult.outData);
261    console.info('Succeeded in signing and verifying.');
262  } catch (err) {
263    let e: BusinessError = err as BusinessError;
264    console.error(`Failed to sign or verify. Code: ${e.code}, message: ${e.message}`);
265  }
266
267  try {
268    /* 卸载私有凭据 */
269    await certificateManager.uninstallPrivateCertificate(appKeyUri);
270  } catch (err) {
271    let e: BusinessError = err as BusinessError;
272    console.error(`Failed to uninstall private certificate. Code: ${e.code}, message: ${e.message}`);
273  }
274}
275
276// [End certificate_management_development_guidance]
277
278@Entry
279@Component
280struct Index {
281  @State message: string = 'CertManagerGuidelines';
282
283  build() {
284    Column({space: 5}) {
285      Text(this.message)
286        .fontSize(25)
287        .fontWeight(FontWeight.Bold)
288      Button($r('app.string.call_certManagerGuidelines'))
289        .width('70%')
290        .onClick(()=>{
291          certificateManagerSample();
292          this.message = 'CertManagerGuidelines Success';
293        })
294    }
295    .height('100%')
296    .width('100%')
297  }
298}