• 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 MinAccessControl {
24  @State cipherTextinfo: string = ''
25  @State plainTextinfo: string = ''
26  @State inputPassword: string = ''
27  huksModel: HuksModel = new HuksModel()
28
29  build() {
30    Stack({ alignContent: Alignment.Center }) {
31      Column() {
32        GridRow() {
33          GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) {
34            Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
35              List() {
36                ListItem() {
37                  Row() {
38                    Text($r('app.string.input_save_password'))
39                      .fontSize(16)
40                      .textAlign(TextAlign.Start)
41                      .lineHeight(22)
42                  }
43                  .backgroundColor(0xFFFFFF)
44                  .width('100%')
45                  .height('52vp')
46                  .padding({ top: 4, left: 12, right: 12 })
47                }
48
49                ListItem() {
50                  Row() {
51                    TextInput()
52                      .enableKeyboardOnFocus(false)
53                      .margin(4)
54                      .width('90%')
55                      .id('passwordInput')
56                      .fontSize(16)
57                      .textAlign(TextAlign.Start)
58                      .onChange((value: string) => {
59                        this.inputPassword = value
60                      })
61                  }
62                  .backgroundColor(0xFFFFFF)
63                  .width('100%')
64                  .height('48vp')
65                  .padding({ left: 12, right: 12 })
66                }
67              }
68              .width('100%')
69              .height('100%')
70              .borderRadius(16)
71            }
72          }
73        }
74        .height('100vp')
75        .margin({ left: 12, right: 12, bottom: 12 })
76
77        GridRow() {
78          GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) {
79            Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
80              Column() {
81                Row() {
82                  Text($r('app.string.cipher_text'))
83                    .fontSize(16)
84                    .textAlign(TextAlign.Start)
85                    .fontWeight(500)
86                    .lineHeight(22)
87                }
88                .padding({ left: 12, right: 12 })
89                .width('100%')
90                .height('48vp')
91
92                Row() {
93                  Text() {
94                    Span(this.cipherTextinfo)
95                      .fontSize(16)
96                      .fontWeight(400)
97                      .fontColor(0x808080)
98                      .fontColor('#182431')
99                  }.textAlign(TextAlign.Start)
100                  .id('cipherTextinfo')
101                }
102                .padding({ left: 12, right: 12, bottom: 4 })
103                .width('100%')
104                .height('52vp')
105              }
106              .borderRadius(16)
107              .width('100%')
108              .height('100')
109              .backgroundColor(0xFFFFFF)
110            }
111          }
112        }
113        .height('100vp')
114        .margin({ left: 12, right: 12, bottom: 12 })
115
116        GridRow() {
117          GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) {
118            Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
119              Column() {
120                Row() {
121                  Text($r('app.string.plain_text'))
122                    .fontSize(16)
123                    .textAlign(TextAlign.Start)
124                    .fontWeight(500)
125                    .lineHeight(22)
126                }
127                .padding({ left: 12, right: 12 })
128                .width('100%')
129                .height('48vp')
130
131                Row() {
132                  Text() {
133                    Span(this.plainTextinfo)
134                      .fontSize(16)
135                      .fontWeight(400)
136                      .fontColor(0x808080)
137                      .fontColor('#182431')
138                  }.textAlign(TextAlign.Start)
139                  .id('plainTextinfo')
140                }
141                .padding({ left: 12, right: 12, bottom: 4 })
142                .width('100%')
143                .height('52vp')
144              }
145              .borderRadius(16)
146              .width('100%')
147              .height('100')
148              .backgroundColor(0xFFFFFF)
149            }
150          }
151        }
152        .height('100vp')
153        .margin({ left: 12, right: 12, bottom: 12 })
154
155        Column() {
156          GridRow() {
157            GridCol({ span: { xs: 12, sm: 12, md: 12, lg: 12 } }) {
158              Column() {
159                Button() {
160                  Text($r('app.string.save_password')).fontSize(16).fontWeight(500)
161                    .lineHeight(22)
162                    .fontColor('#FFFFFF')
163                }
164                .id('save_password')
165                .borderRadius(20)
166                .type(ButtonType.Capsule)
167                .width('100%')
168                .height('40vp')
169                .margin({ bottom: 16 })
170                .backgroundColor('#007DFF')
171                .onClick(() => {
172                  if (this.inputPassword === '') {
173                    prompt.showToast({
174                      message: 'This message is null.'
175                    })
176                  } else {
177                    this.huksModel.encryptDataUseSm2(this.inputPassword, (result: string) => {
178                      Logger.info(TAG, `this result = ${result}`)
179                      this.cipherTextinfo = `${result}`
180                    })
181                  }
182                });
183
184                Button() {
185                  Text($r('app.string.read_password')).fontSize(16).fontWeight(500)
186                    .lineHeight(22)
187                    .fontColor('#FFFFFF')
188                }
189                .borderRadius(20)
190                .id('read_password')
191                .type(ButtonType.Capsule)
192                .margin({ left: 24, right: 24 })
193                .width('100%')
194                .height('40vp')
195                .backgroundColor('#007DFF')
196                .onClick(() => {
197
198                  if (this.inputPassword === '') {
199                    prompt.showToast({
200                      message: 'This message is null.'
201                    })
202                  } else {
203                    this.huksModel.decryptDataUseSm2((result: string) => {
204                      Logger.info(TAG, `this result = ${result}`)
205                      this.plainTextinfo = `${result}`
206                    })
207                  }
208
209                });
210              }
211            }
212          }.margin({ left: 24, right: 24 })
213        }.width('100%').height('296vp').justifyContent(FlexAlign.End)
214      }
215      .width('100%')
216      .height('100%')
217    }
218  }
219}
220
221