diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/.gitignore b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..02057bf087c007e3f3d3529f8e1f21167352b4c6 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.hkdfderivation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..83ed1e5d1f097d97a516fb2cfba1c3c23830d8ce --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "HKDFDerivation" + } + ] +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/media/app_icon.png b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/AppScope/resources/base/media/app_icon.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4b4c881205acc5646a5b0dd5e8c995b00372d87c --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/README.md @@ -0,0 +1,72 @@ +# 使用HKDF进行密钥派生 + +### 介绍 + +本示例主要展示了使用HKDF进行密钥派生通过await、Promis、同步返回场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用HKDF进行密钥派生](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-derivation-using-hkdf.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例HKDFDerivation.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用HKDF进行密钥派生示例代码 + │ │ ├── Await.ets + │ │ ├── Promise.ets + │ │ ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── HKDFDerivation.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo CryptoArchitectureKit/KeyDerivation/HKDFDerivation > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/code-linter.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/.gitignore b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/hvigorfile.ts b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets new file mode 100644 index 0000000000000000000000000000000000000000..ba56487c3490ebc434d1535b57fd269a70ada45e --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Await.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start use_hkdf_for_key_derivation_await] + +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function kdfAwait() { + let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); + let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); + let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); + let spec: cryptoFramework.HKDFSpec = { + algName: 'HKDF', + key: keyData, + salt: saltData, + info: infoData, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); + let secret = await kdf.generateSecret(spec); + console.info('key derivation output is ' + secret.data); +} +// [End use_hkdf_for_key_derivation_await] +@Entry +@Component +struct Index { + @State message: string = 'Await'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_await')) + .width('70%') + .onClick(async () => { + try { + await kdfAwait(); + this.message = 'Await Success'; + } catch { + this.message = 'Await Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Index.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..5849718cf9d1f314284b069e7f1fe3160291da70 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'HKDFDerivation'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.await')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Await') + }) + Button($r('app.string.promise')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Promise') + }) + Button($r('app.string.sync')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Sync') + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets new file mode 100644 index 0000000000000000000000000000000000000000..0dc16a07a5576771af8ed98923bd3d7af49c02b7 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Promise.ets @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2025 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. + */ + +// [Start use_hkdf_for_key_derivation_promise] + +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { buffer } from '@kit.ArkTS'; + +function kdfPromise() { + let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); + let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); + let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); + let spec: cryptoFramework.HKDFSpec = { + algName: 'HKDF', + key: keyData, + salt: saltData, + info: infoData, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); + let kdfPromise = kdf.generateSecret(spec); + kdfPromise.then((secret) => { + console.info('key derivation output is ' + secret.data); + }).catch((error: BusinessError) => { + console.error('key derivation error.'); + }); +} + +// [End use_hkdf_for_key_derivation_promise] +@Entry +@Component +struct Index { + @State message: string = 'Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_promise')) + .width('70%') + .onClick(() => { + try { + kdfPromise(); + this.message = 'Promise Success'; + } catch { + this.message = 'Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets new file mode 100644 index 0000000000000000000000000000000000000000..40001e243729ff0ea0e021a707bda7a5c07faa51 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/ets/pages/Sync.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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. + */ +// [Start use_hkdf_for_key_derivation_sync] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function kdfSync() { + let keyData = new Uint8Array(buffer.from('012345678901234567890123456789', 'utf-8').buffer); + let saltData = new Uint8Array(buffer.from('0123456789', 'utf-8').buffer); + let infoData = new Uint8Array(buffer.from('infostring', 'utf-8').buffer); + let spec: cryptoFramework.HKDFSpec = { + algName: 'HKDF', + key: keyData, + salt: saltData, + info: infoData, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('HKDF|SHA256|EXTRACT_AND_EXPAND'); + let secret = kdf.generateSecretSync(spec); + console.info('[Sync]key derivation output is ' + secret.data); +} + +// [End use_hkdf_for_key_derivation_sync] +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sync')) + .width('70%') + .onClick(() => { + try { + kdfSync(); + this.message = 'Sync Success'; + } catch { + this.message = 'Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/string.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c21cb466ec1ec5fcb661e234a5cde968440ab53e --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "HKDFDerivation" + }, + { + "name": "await", + "value": "Await" + }, + { + "name": "promise", + "value": "Promise" + }, + { + "name": "sync", + "value": "Sync" + }, + { + "name": "call_await", + "value": "Call Await" + }, + { + "name": "call_promise", + "value": "Call Promise" + }, + { + "name": "call_sync", + "value": "Call Sync" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/background.png b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/background.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/foreground.png b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/foreground.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/layered_image.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/startIcon.png b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/main_pages.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..e3dc5624a6c7bcfa5e83033d13b7957b916e6f3d --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/Await", + "pages/Promise", + "pages/Sync" + ] +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/Ability.test.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8506514c41de52d50ad132a86c96a1a02848c765 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/HKDFDerivation.test.ets @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function hKDFDerivationTest() { + describe('hKDFDerivationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用HKDF进行密钥派生,通过await返回结果 + */ + it('testHKDFDerivation001', 0, async () => { + console.info('uitest: testHKDFDerivation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Await')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Await')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Await Success')); + console.info('uitest: testHKDFDerivation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用HKDF进行密钥派生,通过Promise返回结果 + */ + it('testHKDFDerivation002', 0, async () => { + console.info('uitest: testHKDFDerivation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Promise Success')); + console.info('uitest: testHKDFDerivation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用HKDF进行密钥派生,通过同步方式返回结果 + */ + it('testHKDFDerivation003', 0, async () => { + console.info('uitest: testHKDFDerivation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Sync Success')); + console.info('uitest: testHKDFDerivation003 end'); + await driver.pressBack(); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/List.test.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b344e613d7df179e1b46c72f4901ec2f06b36f7b --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; +import hKDFDerivationTest from './HKDFDerivation.test'; + +export default function testsuite() { + abilityTest(); + hKDFDerivationTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/List.test.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/LocalUnit.test.ets b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigorfile.ts b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..b60d8dee467228df4088a460dd51f4cf28d122ce --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/ohosTest.md @@ -0,0 +1,10 @@ +# 使用HKDF进行密钥派生测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用HKDF进行密钥派生,通过await返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用HKDF进行密钥派生,通过Promise返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用HKDF进行密钥派生,通过同步方式返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation1.png b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation1.png new file mode 100644 index 0000000000000000000000000000000000000000..4412595947336b867300e694e9ba64eaf93844a2 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation1.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation2.png b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation2.png new file mode 100644 index 0000000000000000000000000000000000000000..05bb47e58f09581630ba20ebceedd9a8b424bfe8 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/HKDFDerivation/screenshots/HKDFDerivation2.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/.gitignore b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..43ce2547493eec2e4bf24f3a28d9cadf943f0961 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "bundleName": "com.samples.pbkdf2derivation", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1c4fc7b6832f0bcf3ecf82109fe716399c3b9b69 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "PBKDF2Derivation" + } + ] +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/media/app_icon.png b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/AppScope/resources/base/media/app_icon.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d6e499271486f1979d125979af593d3f059bf66e --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/README.md @@ -0,0 +1,72 @@ +# 使用PBKDF2进行密钥派生 + +### 介绍 + +本示例主要展示了使用PBKDF2进行密钥派生(通过await、Promise、同步方式返回结果)的场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用PBKDF2进行密钥派生](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-key-derivation-using-pbkdf2.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例PBKDF2Derivation.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 使用PBKDF2进行密钥派生示例代码 + │ │ ├── Await.ets + │ │ ├── Promise.ets + │ │ ├── Sync.ets + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── PBKDF2Derivation.test.ets // 自动化测试代码 + │ │ └── List.test.ets +``` + +### 相关权限 + +不涉及。 + +### 依赖 + +不涉及。 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:华为手机。 + +2. HarmonyOS系统:HarmonyOS 5.0.2 Release及以上。 + +3. DevEco Studio版本:DevEco Studio 5.0.2 Release及以上。 + +4. HarmonyOS SDK版本:HarmonyOS 5.0.2 Release及以上。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +```` +git init +git config core.sparsecheckout true +echo CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation > .git/info/sparse-checkout +git remote add origin https://gitee.com/harmonyos_samples/guide-snippets.git +git pull origin master +```` \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compatibleSdkVersion": "5.0.2(14)", + "targetSdkVersion": "5.0.2(14)", + "runtimeOS": "HarmonyOS", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/code-linter.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/code-linter.json5 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "files": [ + "**/*.ets" + ], + "ignore": [ + "**/src/ohosTest/**/*", + "**/src/test/**/*", + "**/src/mock/**/*", + "**/node_modules/**/*", + "**/oh_modules/**/*", + "**/build/**/*", + "**/.preview/**/*" + ], + "ruleSet": [ + "plugin:@performance/recommended", + "plugin:@typescript-eslint/recommended" + ], + "rules": { + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/.gitignore b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/hvigorfile.ts b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 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. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(0x0000, 'testTag', 'onBackup ok'); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets new file mode 100644 index 0000000000000000000000000000000000000000..681864bef13ce05508f7cc63745e4f43ebd29bb0 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Await.ets @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 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. + */ +// [Start use_pbkdf2_for_key_derivation_await] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +async function kdfAwait() { + let spec: cryptoFramework.PBKDF2Spec = { + algName: 'PBKDF2', + password: '123456', + salt: new Uint8Array(16), + iterations: 10000, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); + let secret = await kdf.generateSecret(spec); + console.info('key derivation output is ' + secret.data); +} + +// [End use_pbkdf2_for_key_derivation_await] + +@Entry +@Component +struct Index { + @State message: string = 'Await'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_await')) + .width('70%') + .onClick(async () => { + try { + await kdfAwait(); + this.message = 'Await Success'; + } catch { + this.message = 'Await Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Index.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..fffe88bd327a6720bc4faf5bc40b1ca97cb59fac --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 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. + */ + +import { router } from '@kit.ArkUI'; + +@Entry +@Component +struct Index { + @State message: string = 'PBKDF2Derivation'; + + goToSample(url: string): void { + router.pushUrl({ + url: url, + }, router.RouterMode.Single, (err) => { + if (err) { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + return; + } + console.info('pushUrl success'); + }) + } + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.await')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Await') + }) + Button($r('app.string.promise')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Promise') + }) + Button($r('app.string.sync')) + .width('70%') + .onClick(() => { + this.goToSample('pages/Sync') + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets new file mode 100644 index 0000000000000000000000000000000000000000..162be118f92fba20403d7dcb557f6247ad0b7d84 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Promise.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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. + */ +// [Start use_pbkdf2_for_key_derivation_promise] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function kdfPromise() { + let spec: cryptoFramework.PBKDF2Spec = { + algName: 'PBKDF2', + password: '123456', + salt: new Uint8Array(16), + iterations: 10000, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); + let kdfPromise = kdf.generateSecret(spec); + kdfPromise.then((secret) => { + console.info('key derivation output is ' + secret.data); + }).catch((error: BusinessError) => { + console.error('key derivation error.'); + }); +} +// [End use_pbkdf2_for_key_derivation_promise] +@Entry +@Component +struct Index { + @State message: string = 'Promise'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_promise')) + .width('70%') + .onClick(() => { + try { + kdfPromise(); + this.message = 'Promise Success'; + } catch { + this.message = 'Promise Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets new file mode 100644 index 0000000000000000000000000000000000000000..e2db20777acb62e20c53535ba7ef90a734e28a78 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/ets/pages/Sync.ets @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 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. + */ +// [Start use_pbkdf2_for_key_derivation_sync] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; + +function kdfSync() { + let spec: cryptoFramework.PBKDF2Spec = { + algName: 'PBKDF2', + password: '123456', + salt: new Uint8Array(16), + iterations: 10000, + keySize: 32 + }; + let kdf = cryptoFramework.createKdf('PBKDF2|SHA256'); + let secret = kdf.generateSecretSync(spec); + console.info('[Sync]key derivation output is ' + secret.data); +} + +// [End use_pbkdf2_for_key_derivation_sync] +@Entry +@Component +struct Index { + @State message: string = 'Sync'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(20).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sync')) + .width('70%') + .onClick(() => { + try { + kdfSync(); + this.message = 'Sync Success'; + } catch { + this.message = 'Sync Fail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/string.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..459aa31680634b502ff5fbed5ea61cba472e38df --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "PBKDF2Derivation" + }, + { + "name": "await", + "value": "Await" + }, + { + "name": "promise", + "value": "Promise" + }, + { + "name": "sync", + "value": "Sync" + }, + { + "name": "call_await", + "value": "Call Await" + }, + { + "name": "call_promise", + "value": "Call Promise" + }, + { + "name": "call_sync", + "value": "Call Sync" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/background.png b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/background.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/foreground.png b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/foreground.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/layered_image.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/startIcon.png b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/main_pages.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..e3dc5624a6c7bcfa5e83033d13b7957b916e6f3d --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,8 @@ +{ + "src": [ + "pages/Index", + "pages/Await", + "pages/Promise", + "pages/Sync" + ] +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/Ability.test.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/List.test.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..68b13391fb276aaa81ad47a5ee929d5aecf33026 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +import abilityTest from './Ability.test'; +import pBKDF2DerivationTest from './PBKDF2Derivation.test'; + +export default function testsuite() { + abilityTest(); + pBKDF2DerivationTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e62d26ac0d5bb9b3dbfa75a9c4ce07ac07ddf0a8 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/ets/test/PBKDF2Derivation.test.ets @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, it, expect, beforeAll } from '@ohos/hypium'; +// 导入测试依赖kit +import { abilityDelegatorRegistry, Driver, ON } from '@kit.TestKit'; +import { UIAbility, Want } from '@kit.AbilityKit'; + +const delegator: abilityDelegatorRegistry.AbilityDelegator = abilityDelegatorRegistry.getAbilityDelegator(); +const bundleName = abilityDelegatorRegistry.getArguments().bundleName; +let want: Want; + +export default function pBKDF2DerivationTest() { + describe('pBKDF2DerivationTest', () => { + /** + * 打开应用 + */ + beforeAll(async () => { + want = { + bundleName: bundleName, + abilityName: 'EntryAbility' + }; + await delegator.startAbility(want); + const driver = Driver.create(); + await driver.delayMs(1000); + const ability: UIAbility = await delegator.getCurrentTopAbility(); + console.info('get top ability'); + await driver.delayMs(1000); + expect(ability.context.abilityInfo.name).assertEqual('EntryAbility'); + }) + + /** + * 点击按钮,使用PBKDF2进行密钥派生,通过await返回 + */ + it('testPBKDF2Derivation001', 0, async () => { + console.info('uitest: testPBKDF2Derivation001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Await')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Await')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Await Success')); + console.info('uitest: testPBKDF2Derivation001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用PBKDF2进行密钥派生,通过Promise返回 + */ + it('testPBKDF2Derivation002', 0, async () => { + console.info('uitest: testPBKDF2Derivation002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Promise')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Promise')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Promise Success')); + console.info('uitest: testPBKDF2Derivation002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用PBKDF2进行密钥派生,通过同步方式 + */ + it('testPBKDF2Derivation003', 0, async () => { + console.info('uitest: testPBKDF2Derivation003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call Sync')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('Sync Success')); + console.info('uitest: testPBKDF2Derivation003 end'); + await driver.pressBack(); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/List.test.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 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. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/LocalUnit.test.ets b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 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. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigor/hvigor-config.json5 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.1", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigorfile.ts b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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. + */ + +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +{ + "modelVersion": "5.0.1", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.19", + "@ohos/hamock": "1.0.0" + } +} diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..96277ce9f2b207b505ca7af84ff10cd821585b85 --- /dev/null +++ b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/ohosTest.md @@ -0,0 +1,10 @@ +# 使用PBKDF2进行密钥派生测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用PBKDF2进行密钥派生,通过await返回 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用PBKDF2进行密钥派生,通过Promise返回 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用PBKDF2进行密钥派生,通过同步方式 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation1.png b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation1.png new file mode 100644 index 0000000000000000000000000000000000000000..7de0dff7003c66f7404dd63a95eb860748acc9a7 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation1.png differ diff --git a/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation2.png b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation2.png new file mode 100644 index 0000000000000000000000000000000000000000..cd801cae4e6ead97eaccf2bf9897873c3814ab78 Binary files /dev/null and b/CryptoArchitectureKit/KeyDerivation/PBKDF2Derivation/screenshots/PBKDF2Derivation2.png differ