From 08a2875478ce44dc48fee99233a8a69474800713 Mon Sep 17 00:00:00 2001 From: feng <1362134550@qq.com> Date: Thu, 27 Mar 2025 21:35:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E6=96=87=E5=8A=A0=E8=A7=A3=E5=AF=86?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/pages/Index.ets | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/AppDataSecurity/entry/src/main/ets/pages/Index.ets b/AppDataSecurity/entry/src/main/ets/pages/Index.ets index fe21525b..3eddabf5 100644 --- a/AppDataSecurity/entry/src/main/ets/pages/Index.ets +++ b/AppDataSecurity/entry/src/main/ets/pages/Index.ets @@ -15,7 +15,7 @@ import { common, contextConstant } from '@kit.AbilityKit'; import { fileIo } from '@kit.CoreFileKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; -import { buffer } from '@kit.ArkTS'; +import { buffer, util } from '@kit.ArkTS'; import { huks } from '@kit.UniversalKeystoreKit'; @Entry @@ -110,20 +110,14 @@ function readFile(filePath: string): object { return [readLen, buf.toString()] } -function StringToUint8Array(str: String) { - let arr: number[] = new Array(); - for (let i = 0, j = str.length; i < j; ++i) { - arr.push(str.charCodeAt(i)); - } - return new Uint8Array(arr); +function StringToUint8Array(str: string) { + let textEncoder = util.TextEncoder.create('utf-8'); + return textEncoder.encodeInto(str); } function Uint8ArrayToString(fileData: Uint8Array) { - let dataString = ''; - for (let i = 0; i < fileData.length; i++) { - dataString += String.fromCharCode(fileData[i]); - } - return dataString; + let textDecoder = util.TextDecoder.create('utf-8'); + return textDecoder.decodeToString(fileData); } function GetAesGenerateProperties() { -- Gitee