diff --git a/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue.ets b/CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets similarity index 67% rename from CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue.ets rename to CryptoArchitectureKit/entry/src/main/ets/pages/ObtainCertificateHashValue_One.ets index a10df29cfe06e5de09dd4b68bc5e2ea360424f90..9f3c0a703242357f3bc981826ec109dd19c13696 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'; @@ -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); }); @@ -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 0000000000000000000000000000000000000000..2103f47c2119ebe0ac947d4e00d12b8e4d4e4c43 --- /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 52582fb0e8493bf4abb8a35ce0d024caef056595..55c3f007f87b7ce5206d325f968cc56f2f79441f 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