diff --git a/AppDataSecurity/entry/src/main/ets/pages/Index.ets b/AppDataSecurity/entry/src/main/ets/pages/Index.ets index 77abcf988a9f5d14c18ffe1e8a8afae3b860c9c2..2baf55383cc4e367ea0f6de1dd430508bdbce339 100644 --- a/AppDataSecurity/entry/src/main/ets/pages/Index.ets +++ b/AppDataSecurity/entry/src/main/ets/pages/Index.ets @@ -65,7 +65,7 @@ struct Index { } // [Start get_el2_path] - getEl2Path() { + getEl2Path(): void { let context = this.getUIContext().getHostContext() as common.UIAbilityContext; context.area = contextConstant.AreaMode.EL2; let filePath = context.filesDir + '/health_data.txt'; @@ -74,7 +74,7 @@ struct Index { // [End get_el2_path] // [Start get_el1_path] - getEl1Path() { + getEl1Path(): void { let context = this.getUIContext().getHostContext() as common.UIAbilityContext; context.area = contextConstant.AreaMode.EL1; let filePath = context.filesDir + '/health_data.txt'; @@ -83,14 +83,14 @@ struct Index { // [End get_el1_path] } -let aesKeyAlias = 'test_aesKeyAlias'; +let aesKeyAlias: string = 'test_aesKeyAlias'; let handle: number; -let plainText = '123456'; -let IV = '001122334455'; +let plainText: string = '123456'; +let IV: string = '001122334455'; let cipherData: Uint8Array; // [Start write_file] -function writeFile(filePath: string, data: string) { +function writeFile(filePath: string, data: string): void { try { let file = fileIo.openSync(filePath, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); let writeLen = fileIo.writeSync(file.fd, data); @@ -125,18 +125,18 @@ function readFile(filePath: string): string { } // [End write_file] -function StringToUint8Array(str: string) { +function StringToUint8Array(str: string): Uint8Array { let textEncoder = util.TextEncoder.create('utf-8'); return textEncoder.encodeInto(str); } -function Uint8ArrayToString(fileData: Uint8Array) { +function Uint8ArrayToString(fileData: Uint8Array): string { let textDecoder = util.TextDecoder.create('utf-8'); return textDecoder.decodeToString(fileData); } // [Start get_aes_generate_properties] -function GetAesGenerateProperties() { +function GetAesGenerateProperties(): Array { let properties: Array = [{ tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES @@ -153,7 +153,7 @@ function GetAesGenerateProperties() { // [End get_aes_generate_properties] // [Start get_aes_encrypt_properties] -function GetAesEncryptProperties() { +function GetAesEncryptProperties(): Array { let properties: Array = [{ tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES @@ -178,7 +178,7 @@ function GetAesEncryptProperties() { // [End get_aes_encrypt_properties] // [Start get_aes_decrypt_properties] -function GetAesDecryptProperties() { +function GetAesDecryptProperties(): Array { let properties: Array = [{ tag: huks.HuksTag.HUKS_TAG_ALGORITHM, value: huks.HuksKeyAlg.HUKS_ALG_AES @@ -203,7 +203,7 @@ function GetAesDecryptProperties() { // [End get_aes_decrypt_properties] // [Start generate_aes_key] -async function GenerateAesKey() { +async function GenerateAesKey(): Promise { let genProperties = GetAesGenerateProperties(); let options: huks.HuksOptions = { properties: genProperties @@ -219,7 +219,7 @@ async function GenerateAesKey() { // [End generate_aes_key] // [Start encrypt_data] -async function EncryptData() { +async function EncryptData(): Promise { let encryptProperties = GetAesEncryptProperties(); let options: huks.HuksOptions = { properties: encryptProperties, @@ -243,7 +243,7 @@ async function EncryptData() { }) } -async function DecryptData() { +async function DecryptData(): Promise { let decryptOptions = GetAesDecryptProperties() let options: huks.HuksOptions = { properties: decryptOptions, @@ -267,7 +267,7 @@ async function DecryptData() { } // [End encrypt_data] -async function DeleteKey() { +async function DeleteKey(): Promise { let emptyOptions: huks.HuksOptions = { properties: [] };