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 NewKey { 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.encryptData(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.decryptData((result: string) => { 85 Logger.info(TAG, `this result = ${result}`) 86 this.plainTextinfo = `${result}` 87 }) 88 } 89 }) 90 } 91 92 Text(this.plainTextinfo) 93 .id('decryptionInfo') 94 .fontSize(18) 95 .width('85%') 96 .height('25%') 97 .border({ width: 2, color: Color.Black }) 98 .margin(10) 99 } 100 } 101 .width('100%') 102 .height('100%') 103 } 104}