• 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
16import { cryptoFramework } from '@kit.CryptoArchitectureKit';
17
18function testGenCipherTextBySpec() {
19  let spec: cryptoFramework.SM2CipherTextSpec = {
20    xCoordinate: BigInt('20625015362595980457695435345498579729138244358573902431560627260141789922999'),
21    yCoordinate: BigInt('48563164792857017065725892921053777369510340820930241057309844352421738767712'),
22    cipherTextData: new Uint8Array([100, 227, 78, 195, 249, 179, 43, 70, 242, 69, 169, 10, 65, 123]),
23    hashData: new Uint8Array([87, 167, 167, 247, 88, 146, 203, 234, 83, 126, 117, 129, 52, 142, 82, 54, 152, 226, 201,
24      111, 143, 115, 169, 125, 128, 42, 157, 31, 114, 198, 109, 244]),
25  }
26  // 此处的data可直接使用cryptoFramework进行SM2解密
27  let data = cryptoFramework.SM2CryptoUtil.genCipherTextBySpec(spec, 'C1C3C2');
28  console.info('genCipherTextBySpec success');
29}
30
31@Entry
32@Component
33struct Index {
34  @State message: string = 'Create ASN.1';
35
36  build() {
37    Column({ space: 5 }) {
38      Text(this.message).fontSize(20).fontWeight(FontWeight.Bold)
39      Button($r('app.string.call_create_asn1'))
40        .width('70%')
41        .onClick(() => {
42          try {
43            testGenCipherTextBySpec();
44            this.message = 'Create ASN.1 Success';
45          } catch {
46            this.message = 'Create ASN.1 Fail';
47          }
48        })
49    }
50    .height('100%')
51    .width('100%')
52  }
53}