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 16// [Start convert_ecc_uncompressed_pub_keypair] 17import { cryptoFramework } from '@kit.CryptoArchitectureKit'; 18 19async function eccPubUncompressedToCompressed() { 20 let pkData = 21 new Uint8Array([48, 90, 48, 20, 6, 7, 42, 134, 72, 206, 61, 2, 1, 6, 9, 43, 36, 3, 3, 2, 8, 1, 1, 7, 3, 66, 0, 4, 22 143, 39, 57, 249, 145, 50, 63, 222, 35, 70, 178, 121, 202, 154, 21, 146, 129, 75, 76, 63, 8, 195, 157, 111, 40, 23 217, 215, 148, 120, 224, 205, 82, 83, 92, 185, 21, 211, 184, 5, 19, 114, 33, 86, 85, 228, 123, 242, 206, 200, 98, 24 178, 184, 130, 35, 232, 45, 5, 202, 189, 11, 46, 163, 156, 152]); 25 let pubKeyBlob: cryptoFramework.DataBlob = { data: pkData }; 26 let generator = cryptoFramework.createAsyKeyGenerator('ECC_BrainPoolP256r1'); 27 let keyPair = await generator.convertKey(pubKeyBlob, null); 28 let returnBlob = keyPair.pubKey.getEncodedDer('X509|COMPRESSED'); 29 console.info('returnBlob data:' + returnBlob.data); 30} 31// [End convert_ecc_uncompressed_pub_keypair] 32 33@Entry 34@Component 35struct Index { 36 @State message: string = 'SpecifyUncompressedPublicKey'; 37 38 build() { 39 Column({ space: 12 }) { 40 Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) 41 Button($r('app.string.call_specifyUncompressedPublicKey')) 42 .width('70%') 43 .onClick(async () => { 44 try { 45 await eccPubUncompressedToCompressed(); 46 this.message = 'SpecifyUncompressedPublicKey Success'; 47 } catch { 48 this.message = 'SpecifyUncompressedPublicKey Fail'; 49 } 50 }) 51 } 52 .height('100%') 53 .width('100%') 54 } 55}