From 11a97954c79e320dcde0ed9ba0da8c4f7a7f2225 Mon Sep 17 00:00:00 2001 From: kuangning <2540487435@qq.com> Date: Thu, 15 May 2025 19:08:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?CryptoArchitectureKit=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ets => ObtainCertificateHashValue_One.ets} | 20 ++--------- .../pages/ObtainCertificateHashValue_Two.ets | 34 +++++++++++++++++++ .../resources/base/profile/main_pages.json | 3 +- 3 files changed, 37 insertions(+), 20 deletions(-) rename CryptoArchitectureKit/entry/src/main/ets/pages/{ObtainCertificateHashValue.ets => ObtainCertificateHashValue_One.ets} (70%) create mode 100644 CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_Two.ets diff --git a/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue.ets b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets similarity index 70% rename from CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue.ets rename to CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets index a10df29c..81b36c46 100644 --- a/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue.ets +++ b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets @@ -17,7 +17,7 @@ * FAQ:如何获取应用签名证书的hash值 */ -// DocsCode 1 +// [Start ObtainCertificateHashValue_One] import { bundleManager } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { BusinessError } from '@kit.BasicServicesKit'; @@ -34,20 +34,4 @@ try { let message = (err as BusinessError).message; hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message); } -// DocsCode 1 - -// DocsCode 2 -import { common } from '@kit.AbilityKit'; -import { BusinessError } from '@kit.BasicServicesKit'; -import { hash }from '@kit.CoreFileKit'; - -let context = UIContext.getHostContext()! as common.UIAbilityContext; -let pathDir = context.filesDir; - -let filePath = pathDir + "/test.txt"; -hash.hash(filePath, "sha256").then((str: string) => { - console.info("calculate file hash succeed:" + str); -}).catch((err: BusinessError) => { - console.error("calculate file hash failed with error message: " + err.message + ", error code: " + err.code); -}); -// DocsCode 2 \ No newline at end of file +// [End ObtainCertificateHashValue_One] \ No newline at end of file diff --git a/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_Two.ets b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_Two.ets new file mode 100644 index 00000000..2103f47c --- /dev/null +++ b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_Two.ets @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何获取应用签名证书的hash值 +*/ + +// [Start ObtainCertificateHashValue_Two] +import { common } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { hash }from '@kit.CoreFileKit'; + +let context = AppStorage.get("context") as common.UIAbilityContext; +let pathDir = context.filesDir; + +let filePath = pathDir + "/test.txt"; +hash.hash(filePath, "sha256").then((str: string) => { + console.info("calculate file hash succeed:" + str); +}).catch((err: BusinessError) => { + console.error("calculate file hash failed with error message: " + err.message + ", error code: " + err.code); +}); +// [End ObtainCertificateHashValue_Two] \ No newline at end of file diff --git a/CryptoArchitectureKit/entry/src/main/resources/base/profile/main_pages.json b/CryptoArchitectureKit/entry/src/main/resources/base/profile/main_pages.json index 52582fb0..55c3f007 100644 --- a/CryptoArchitectureKit/entry/src/main/resources/base/profile/main_pages.json +++ b/CryptoArchitectureKit/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,5 @@ { "src": [ - "pages/Index", - "pages/ObtainCertificateHashValue" + "pages/Index" ] } \ No newline at end of file -- Gitee From b876023c7bbb263af13ae8a08d1a33162cdadfb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=93=83?= <2540487435@qq.com> Date: Sat, 17 May 2025 06:26:26 +0000 Subject: [PATCH 2/2] =?UTF-8?q?CryptoArchitectureKit=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 风铃 <2540487435@qq.com> --- .../entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets index 81b36c46..9f3c0a70 100644 --- a/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets +++ b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets @@ -26,7 +26,7 @@ let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO; try { bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); - //data里可以获取到signatureInfo,即应用的签名证书信息 + //In the data, you can obtain the signtureInfo, which is the signature certificate information of the application }).catch((err: BusinessError) => { hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message); }); -- Gitee