• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 prompt from '@ohos.prompt'
17import Logger from '../model/Logger'
18import { HuksModel } from '../model/HuksModel'
19
20const TAG: string = '[HUKS]'
21
22@Component
23export struct OldKey {
24  @State cipherTextInfo: string = ''
25  @State plainTextInfo: string = ''
26  @State message: string = ''
27  private huksModel: HuksModel = new HuksModel()
28
29  build() {
30    Stack({alignContent:Alignment.Center}) {
31      Column() {
32        Text($r('app.string.input_message')).fontSize(20).margin({ left: 1, top:1 })
33        TextInput()
34          .enableKeyboardOnFocus(false)
35          .margin(4)
36          .width('90%')
37          .id('encryptionInput')
38          .onChange((value: string) => {
39            this.message = value
40          })
41
42        Row() {
43          Button($r('app.string.send_message'))
44            .margin(10)
45            .fontSize(20)
46            .width('45%')
47            .height('6%')
48            .id('encryptionBtn')
49            .onClick(() => {
50              if (this.message === '') {
51                prompt.showToast({
52                  message: 'This message is null.'
53                })
54              } else {
55                this.huksModel.encryptDataUserOldKey(this.message, (result: string) => {
56                  Logger.info(TAG, `this result = ${result}`)
57                  this.cipherTextInfo = `${result}`
58                })
59              }
60            })
61        }
62
63        Text(this.cipherTextInfo)
64          .id('encryptionInfo')
65          .fontSize(18)
66          .width('85%')
67          .height('25%')
68          .border({ width: 2, color: Color.Black })
69          .margin(10)
70
71        Row() {
72          Button($r('app.string.recieve_message'))
73            .margin(10)
74            .fontSize(20)
75            .width('45%')
76            .height('6%')
77            .id('decryptionBtn')
78            .onClick(() => {
79              if (this.message === '') {
80                prompt.showToast({
81                  message: 'This message is null.'
82                })
83              } else {
84                this.huksModel.decryptDataUserOldKey((result: string) => {
85                  Logger.info(TAG, `this result = ${result}`)
86                  this.plainTextInfo = `${result}`
87                })
88              }
89            })
90          Button($r('app.string.import_key'))
91            .margin(10)
92            .fontSize(20)
93            .width('45%')
94            .height('6%')
95            .id('importKeyBtn')
96            .onClick(() => {
97                this.huksModel.importKey()
98            })
99        }
100
101        Text(this.plainTextInfo)
102          .id('decryptionInfo')
103          .fontSize(18)
104          .width('85%')
105          .height('25%')
106          .border({ width: 2, color: Color.Black })
107          .margin(10)
108      }
109    }
110    .width('100%')
111    .height('100%')
112  }
113}