diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/.gitignore b/CryptoArchitectureKit/SecureRandomNumberGeneration/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/.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/SecureRandomNumberGeneration/AppScope/app.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5501621fff880e82a2661e43e9debc4bdb600aaa --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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.securerandomnumbergeneration", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3487457a46dffed3da9b3c3ab078e5a68353143e --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SecureRandomNumberGeneration" + } + ] +} diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/media/app_icon.png b/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CryptoArchitectureKit/SecureRandomNumberGeneration/AppScope/resources/base/media/app_icon.png differ diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md b/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md new file mode 100644 index 0000000000000000000000000000000000000000..edf08ffc21329f6fa207cd20025d2422e7848fd5 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/README.md @@ -0,0 +1,71 @@ +# 安全随机数生成 + +### 介绍 + +随机数主要用于临时会话密钥生成和非对称加密算法密钥生成等场景。在加解密场景中,安全随机数生成器需要具备随机性,不可预测性,与不可重现性。当前系统生成的随机数满足密码学安全伪随机性要求 + +本示例主要展示了安全随机数生成(await、同步)场景 。该工程中展示的代码详细描述可查如下链接。 + +- [安全随机数生成](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-generate-random-number.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SecureRandomNumberGeneration.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 安全随机数生成示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SecureRandomNumberGeneration.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/SecureRandomNumberGeneration > .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/SecureRandomNumberGeneration/build-profile.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/code-linter.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/.gitignore b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/build-profile.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/hvigorfile.ts b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/oh-package.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/ets/entryability/EntryAbility.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/ets/pages/Index.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7bdacbcc1cbe564d9b4f5604f8589712a9020e35 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,81 @@ +/* + * 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 secure_random_number_generation] + +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function doRandBySync() { + let rand = cryptoFramework.createRandom(); + let len = 24; // Generate a 24-byte random number. + try { + let randData = rand.generateRandomSync(len); + if (randData != null) { + console.info('[Sync]: rand result: ' + randData.data); + } else { + console.error('[Sync]: get rand result fail!'); + } + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`do rand failed, ${e.code}, ${e.message}`); + } +} + +async function doRand() { + let rand = cryptoFramework.createRandom(); + let seed = new Uint8Array([1, 2, 3]); + rand.setSeed({ data: seed }); + let len = 12; + let randOutput = await rand.generateRandom(len); + console.info('rand output:' + randOutput.data); +} + +// [End secure_random_number_generation] + +@Entry +@Component +struct Index { + @State message: string = 'SecureRandomNumberGeneration'; + + build() { + Column({ space: 5 }) { + Text(this.message) + .fontSize(25) + .fontWeight(FontWeight.Bold) + Button($r('app.string.call_async')) + .width('70%') + .onClick(async () => { + try { + await doRand(); + this.message = 'AsyncSuccess'; + } catch { + this.message = 'AsyncFail'; + } + }) + Button($r('app.string.call_sync')) + .width('70%') + .onClick(() => { + try { + doRandBySync(); + this.message = 'SyncSuccess'; + } catch { + this.message = 'SyncFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/module.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/resources/base/element/color.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/resources/base/element/string.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0576b4e5cab3463584220ff1897cd8e5bf86e839 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SecureRandomNumberGeneration" + }, + { + "name": "call_async", + "value": "Call Async" + }, + { + "name": "call_sync", + "value": "Call Sync" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/background.png b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/background.png differ diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/foreground.png b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/foreground.png differ diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/layered_image.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/resources/base/media/startIcon.png b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/backup_config.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/main_pages.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/dark/element/color.json b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/Ability.test.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/List.test.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3640d60cb951037c6e5f6091df8037654e5227e5 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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 secureRandomNumberGenerationTest from './SecureRandomNumberGeneration.test'; + +export default function testsuite() { + abilityTest(); + secureRandomNumberGenerationTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cc40b528c8b63a31c7097cb52cf98e216eeddc80 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/ets/test/SecureRandomNumberGeneration.test.ets @@ -0,0 +1,72 @@ +/* + * 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 secureRandomNumberGenerationTest() { + describe('secureRandomNumberGenerationTest', () => { + /** + * 打开应用 + */ + 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'); + }) + + /** + * 点击按钮,安全随机数生成,使用await返回结果 + */ + it('testSecureRandomNumberGeneration001', 0, async () => { + console.info('uitest: testSecureRandomNumberGeneration001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call Async')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('AsyncSuccess')); + console.info('uitest: testSecureRandomNumberGeneration001 end'); + }) + + /** + * 点击按钮,安全随机数生成,同步返回结果 + */ + it('testSecureRandomNumberGeneration002', 0, async () => { + console.info('uitest: testSecureRandomNumberGeneration002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call Sync')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SyncSuccess')); + console.info('uitest: testSecureRandomNumberGeneration002 end'); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/module.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/test/List.test.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/entry/src/test/LocalUnit.test.ets b/CryptoArchitectureKit/SecureRandomNumberGeneration/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/hvigor/hvigor-config.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/hvigorfile.ts b/CryptoArchitectureKit/SecureRandomNumberGeneration/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/oh-package.json5 b/CryptoArchitectureKit/SecureRandomNumberGeneration/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/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/SecureRandomNumberGeneration/ohosTest.md b/CryptoArchitectureKit/SecureRandomNumberGeneration/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..7437e0328f2411cb658056ee7508646ea3345292 --- /dev/null +++ b/CryptoArchitectureKit/SecureRandomNumberGeneration/ohosTest.md @@ -0,0 +1,9 @@ +# 安全随机数生成测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,安全随机数生成,使用await返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,安全随机数生成,同步返回结果 | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration1.png b/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration1.png new file mode 100644 index 0000000000000000000000000000000000000000..e8761709882f2c0f7aa3dc322cb8ac77b0448e24 Binary files /dev/null and b/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration1.png differ diff --git a/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration2.png b/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration2.png new file mode 100644 index 0000000000000000000000000000000000000000..93ea21ee483746375de2b4cbc43b018526b91d56 Binary files /dev/null and b/CryptoArchitectureKit/SecureRandomNumberGeneration/screenshots/SecureRandomNumberGeneration2.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/.gitignore b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/.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/SignatureVerification/SigningSignatureVerification/AppScope/app.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..56d39e636c9058c5a8f86e67597abe34a8695cce --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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.signingsignatureverification", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7d9ab06441ad9ced1e145a29bc035572fbcd6ef4 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SigningSignatureVerification" + } + ] +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/media/app_icon.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/AppScope/resources/base/media/app_icon.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e847c1dea7940f9df5e0301e1152550d47cba3dd --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/README.md @@ -0,0 +1,91 @@ +# 签名验签(C/C++) + +### 介绍 + +当需要判断接收的数据是否被篡改、数据是否为指定对象发送的数据时,可以使用签名验签操作。接下来将说明系统目前支持的算法及其对应的规格。 + +本示例主要展示了签名验签(C/C++)的多种场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用RSA密钥对(PKCS1模式)验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-ndk.md) +- [使用RSA密钥对(PKCS1模式)签名恢复(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-recover-pkcs1-ndk.md) +- [使用RSA密钥对分段验签(PKCS1模式)(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-by-segment-ndk.md) +- [使用RSA密钥对验签(PSS模式)(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pss-ndk.md) +- [使用ECDSA密钥对验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-ecdsa-sign-sig-verify-ndk.md) +- [使用SM2密钥对验签(C/C++)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-sign-sig-verify-pkcs1-ndk.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SigningSignatureVerification.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── cpp + │ │ ├── types + │ │ | ├── libentry + │ │ | ├── index.d.ts + │ │ | ├── oh-package.json5 + │ │ | ├── project + │ │ | ├── ecdsa_signature_verification.cpp + │ │ | ├── rsa_pkcs1_segment_signature.cpp + │ │ | ├── rsa_pkcs1_signature_restoration.cpp + │ │ | ├── rsa_pkcs1_signature_validator.cpp + │ │ | ├── rsa_pss_verification_tool.cpp + │ │ | ├── signing_signature_verification.h + │ │ | ├── sm2_signature_verification.cpp + │ │ ├── CMakeList.txt + │ │ ├── napi_init.cpp + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 签名验签(C/C++)示例代码 + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SigningSignatureVerification.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/SignatureVerification/SigningSignatureVerification > .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/SignatureVerification/SigningSignatureVerification/build-profile.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/code-linter.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/.gitignore b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ced8b405e37827741e0de3460a34f65be3085668 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/build-profile.json5 @@ -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. + */ + +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": [ + "arm64-v8a", + "x86_64" + ], + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/hvigorfile.ts b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..118bdd4fe7699368a010e04c24f5bfc887cf1298 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/oh-package.json5 @@ -0,0 +1,26 @@ +/* + * 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": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f3347fe669e9f04c7978387ee510f7e9c23733b9 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,16 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(MyApplication) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include + ${NATIVERENDER_ROOT_PATH}/types/project) + +add_library(entry SHARED napi_init.cpp types/project/rsa_pkcs1_segment_signature.cpp types/project/rsa_pkcs1_signature_restoration.cpp types/project/rsa_pkcs1_signature_validator.cpp types/project/rsa_pss_verification_tool.cpp types/project/ecdsa_signature_verification.cpp types/project/sm2_signature_verification.cpp) +target_link_libraries(entry PUBLIC libace_napi.z.so libohcrypto.so libhilog_ndk.z.so) \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b243c28c087a823ef07756a5bd4d971fc8bb61b8 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,88 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include "types/project/signing_signature_verification.h" +#include + +static napi_value TestRsaSignatureSeg(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestRsaSignatureSeg(), &ret); + return ret; +} + +static napi_value TestRsaSignature(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestRsaSignature(), &ret); + return ret; +} + +static napi_value TestRsaSignatureRecover(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_create_int32(env, DoTestRsaSignatureRecover(), &ret); + return ret; +} + +static napi_value TestRsaPssSignatureSeg(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestRsaPssSignatureSeg(), &ret); + return ret; +} + +static napi_value TestEcdsaSignature(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestEcdsaSignature(), &ret); + return ret; +} + +static napi_value TestSm2Signature(napi_env env, napi_callback_info info) +{ + napi_value ret; + napi_get_boolean(env, DoTestSm2Signature(), &ret); + return ret; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + {"signatureSeg", nullptr, TestRsaSignatureSeg, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"signature", nullptr, TestRsaSignature, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"signatureRecover", nullptr, TestRsaSignatureRecover, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"pssSignatureSeg", nullptr, TestRsaPssSignatureSeg, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"ecdsaSignature", nullptr, TestEcdsaSignature, nullptr, nullptr, nullptr, napi_default, nullptr}, + {"sm2Signature", nullptr, TestSm2Signature, nullptr, nullptr, nullptr, napi_default, nullptr}, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); } diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c14cf00cf4dfef8b005f46397d39ef630986d84e --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export const signatureSeg: () => number; + +export const signature: () => number; + +export const signatureRecover: () => number; + +export const pssSignatureSeg: () => number; + +export const ecdsaSignature: () => number; + +export const sm2Signature: () => number; \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6abf3b7c20f22c62aaac6a995a25cae672f73f35 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -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. + */ + +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aff24c6835172752bccf394d23e1ae9bab5c5884 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/ecdsa_signature_verification.cpp @@ -0,0 +1,80 @@ +/* + * 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 verify_signatures_with_ecdsa_keys_c] +#include "signing_signature_verification.h" + +bool DoTestEcdsaSignature() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = {0xe4, 0x2b, 0xcc, 0x08, 0x11, 0x79, 0x16, 0x1b, + 0x35, 0x7f, 0xb3, 0xaf, 0x40, 0x3b, 0x3f, 0x7c}; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = {0x30, 0x39, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, + 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x22, 0x00, 0x03, 0x4d, 0xe4, 0xbb, + 0x11, 0x10, 0x1a, 0xd2, 0x05, 0x74, 0xf1, 0x0b, 0xb4, 0x75, 0x57, 0xf4, 0x3e, 0x55, 0x14, + 0x17, 0x05, 0x4a, 0xb2, 0xfb, 0x8c, 0x84, 0x64, 0x38, 0x02, 0xa0, 0x2a, 0xa6, 0xf0}; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = {0x30, 0x44, 0x02, 0x20, 0x21, 0x89, 0x99, 0xb1, 0x56, 0x4e, 0x3a, 0x2c, 0x16, 0x08, + 0xb5, 0x8a, 0x06, 0x6f, 0x67, 0x47, 0x1b, 0x04, 0x18, 0x7d, 0x53, 0x2d, 0xba, 0x00, + 0x38, 0xd9, 0xe3, 0xe7, 0x8c, 0xcf, 0x76, 0x83, 0x02, 0x20, 0x13, 0x54, 0x84, 0x9d, + 0x73, 0x40, 0xc3, 0x92, 0x66, 0xdc, 0x3e, 0xc9, 0xf1, 0x4c, 0x33, 0x84, 0x2a, 0x76, + 0xaf, 0xc6, 0x61, 0x84, 0x5c, 0xae, 0x4b, 0x0d, 0x3c, 0xb0, 0xc8, 0x04, 0x89, 0x71}; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + // keypair + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"ECC256", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_DER, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"ECC|SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (ret != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} +// [End verify_signatures_with_ecdsa_keys_c] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4b41c78f3fcafe240132b6fd944dec1d87b2f7bd --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_segment_signature.cpp @@ -0,0 +1,123 @@ +/* + * 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 pkcs1_seg_verify_rsa_keypair_sign] +#include "signing_signature_verification.h" + +static constexpr int INT_64 = 64; +bool DoTestRsaSignatureSeg() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x43, 0x31, 0x7d, 0xb5, 0x85, 0x2e, 0xd4, 0xef, 0x08, 0x7a, 0x17, 0x96, 0xbc, 0x7c, 0x8f, 0x80, + 0x8c, 0xa7, 0x63, 0x7f, 0x26, 0x89, 0x8f, 0xf0, 0xfa, 0xa7, 0x51, 0xbd, 0x9c, 0x69, 0x17, 0xf3, + 0xd1, 0xb5, 0xc7, 0x12, 0xbf, 0xcf, 0x91, 0x25, 0x82, 0x23, 0x6b, 0xd6, 0x64, 0x52, 0x77, 0x93, + 0x01, 0x9d, 0x70, 0xa3, 0xf4, 0x92, 0x16, 0xec, 0x3f, 0xa7, 0x3c, 0x83, 0x8d, 0x40, 0x41, 0xfc, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, + 0x6f, 0x47, 0x42, 0x41, 0x4d, 0x78, 0x63, 0x44, 0x4d, 0x6f, 0x61, 0x59, 0x52, 0x58, 0x6f, 0x78, 0x65, 0x69, + 0x33, 0x49, 0x6d, 0x33, 0x33, 0x78, 0x4a, 0x76, 0x61, 0x73, 0x63, 0x43, 0x62, 0x77, 0x31, 0x6f, 0x73, 0x63, + 0x32, 0x56, 0x56, 0x69, 0x47, 0x6a, 0x56, 0x47, 0x47, 0x4a, 0x37, 0x6c, 0x75, 0x4e, 0x41, 0x58, 0x6b, 0x6a, + 0x73, 0x56, 0x46, 0x64, 0x35, 0x0a, 0x58, 0x37, 0x4c, 0x4d, 0x6c, 0x46, 0x34, 0x63, 0x35, 0x5a, 0x75, 0x59, + 0x2f, 0x61, 0x69, 0x57, 0x77, 0x70, 0x54, 0x69, 0x63, 0x62, 0x67, 0x49, 0x33, 0x43, 0x66, 0x50, 0x6f, 0x32, + 0x6a, 0x6c, 0x52, 0x74, 0x67, 0x41, 0x46, 0x6b, 0x44, 0x71, 0x7a, 0x4b, 0x53, 0x46, 0x62, 0x46, 0x47, 0x51, + 0x6b, 0x43, 0x6e, 0x64, 0x63, 0x2b, 0x54, 0x59, 0x6b, 0x5a, 0x42, 0x32, 0x70, 0x45, 0x6f, 0x72, 0x0a, 0x7a, + 0x73, 0x61, 0x56, 0x58, 0x77, 0x5a, 0x47, 0x45, 0x34, 0x41, 0x43, 0x70, 0x59, 0x35, 0x79, 0x65, 0x66, 0x49, + 0x44, 0x6c, 0x45, 0x57, 0x49, 0x51, 0x4f, 0x6a, 0x59, 0x4b, 0x2f, 0x6c, 0x58, 0x71, 0x7a, 0x48, 0x47, 0x69, + 0x4f, 0x69, 0x32, 0x75, 0x4a, 0x45, 0x75, 0x44, 0x43, 0x50, 0x6a, 0x51, 0x64, 0x6a, 0x54, 0x41, 0x67, 0x4d, + 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, + 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x68, 0x2f, 0x3b, 0xe6, 0xa6, 0x5c, 0xb8, 0x60, 0xd4, 0xe1, 0x64, 0xa7, 0xd8, 0x0c, 0x9c, 0x89, + 0x39, 0xb4, 0xf0, 0xb7, 0xad, 0xb5, 0x8a, 0x71, 0x04, 0xf1, 0xa5, 0x63, 0xdd, 0x32, 0x6a, 0x44, + 0xeb, 0xff, 0xb7, 0xe6, 0x85, 0xe5, 0xa5, 0x55, 0x5d, 0x5b, 0x28, 0x53, 0x63, 0xe4, 0xb3, 0xb9, + 0xa8, 0x70, 0xc8, 0x8f, 0xcd, 0x21, 0x8d, 0xe6, 0x1f, 0xe5, 0x78, 0x34, 0xd3, 0x45, 0x0c, 0x9c, + 0x7a, 0x22, 0x1b, 0x63, 0x55, 0xca, 0x14, 0xa5, 0x0c, 0x7a, 0x40, 0x8e, 0xa1, 0x14, 0x78, 0xa1, + 0xf1, 0x36, 0x78, 0xbd, 0xba, 0x37, 0x3b, 0x5b, 0xb0, 0x8e, 0xb3, 0x4a, 0x9b, 0x1b, 0x0c, 0xfa, + 0xfa, 0xc7, 0x9f, 0xb1, 0x35, 0x48, 0x82, 0x73, 0xf8, 0x6b, 0xd4, 0x76, 0x33, 0x5c, 0xed, 0x9c, + 0xd8, 0x4b, 0xc9, 0x92, 0xa0, 0x3f, 0x6e, 0xba, 0x78, 0x2e, 0x80, 0x78, 0x1e, 0x74, 0xa0, 0x47, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + int blockSize = 20; + int cntS = INT_64 / blockSize; + int remS = INT_64 % blockSize; + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + for (int i = 0; i < cntS; i++) { + msgBlob.len = blockSize; + ret = OH_CryptoVerify_Update(verify, (Crypto_DataBlob *)&msgBlob); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + msgBlob.data += blockSize; + } + bool res = false; + if (remS > 0) { + msgBlob.len = remS; + res = OH_CryptoVerify_Final(verify, (Crypto_DataBlob *)&msgBlob, (Crypto_DataBlob *)&signBlob); + if (res != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + } + + msgBlob.data -= INT_64 - remS; + msgBlob.len = INT_64; + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} +// [End pkcs1_seg_verify_rsa_keypair_sign] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34a372a568999678720a5f70e003f7c53f41dbf7 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_restoration.cpp @@ -0,0 +1,100 @@ +/* + * 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 pkcs1_recover_rsa_keypair_sign] +#include "signing_signature_verification.h" + +OH_Crypto_ErrCode DoTestRsaSignatureRecover() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = {0xc4, 0xa5, 0xe5, 0x45, 0xee, 0x71, 0x5e, 0x3b, 0x24, 0x1d, 0x7e, + 0x62, 0xd6, 0x6b, 0xab, 0x98, 0x88, 0x0f, 0xaf, 0x1e, 0x96, 0xa0, + 0x6c, 0xa5, 0x0d, 0x29, 0xfd, 0xcc, 0xef, 0xf6, 0x2b, 0x92}; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, + 0x6f, 0x47, 0x42, 0x41, 0x4b, 0x72, 0x55, 0x74, 0x74, 0x64, 0x76, 0x73, 0x2b, 0x62, 0x6e, 0x4d, 0x2f, 0x6f, + 0x4e, 0x75, 0x39, 0x45, 0x42, 0x78, 0x35, 0x64, 0x49, 0x6d, 0x61, 0x70, 0x52, 0x67, 0x4d, 0x6a, 0x4b, 0x41, + 0x38, 0x51, 0x48, 0x4b, 0x61, 0x75, 0x2f, 0x6c, 0x58, 0x50, 0x50, 0x68, 0x76, 0x38, 0x30, 0x69, 0x59, 0x4c, + 0x46, 0x2b, 0x79, 0x35, 0x35, 0x0a, 0x6d, 0x42, 0x2f, 0x38, 0x2b, 0x4b, 0x68, 0x34, 0x34, 0x43, 0x2b, 0x5a, + 0x76, 0x6f, 0x78, 0x5a, 0x66, 0x38, 0x78, 0x34, 0x6e, 0x78, 0x6f, 0x71, 0x76, 0x4f, 0x6f, 0x73, 0x32, 0x44, + 0x55, 0x69, 0x51, 0x44, 0x4f, 0x4a, 0x35, 0x63, 0x57, 0x68, 0x5a, 0x62, 0x4d, 0x71, 0x4d, 0x42, 0x71, 0x62, + 0x39, 0x30, 0x4e, 0x39, 0x63, 0x2f, 0x44, 0x51, 0x67, 0x39, 0x34, 0x63, 0x52, 0x7a, 0x35, 0x66, 0x0a, 0x68, + 0x55, 0x66, 0x6d, 0x66, 0x6d, 0x54, 0x41, 0x46, 0x6a, 0x5a, 0x53, 0x33, 0x78, 0x6c, 0x78, 0x77, 0x6e, 0x50, + 0x77, 0x66, 0x66, 0x39, 0x71, 0x44, 0x79, 0x4c, 0x63, 0x5a, 0x55, 0x6b, 0x6e, 0x64, 0x43, 0x30, 0x50, 0x77, + 0x72, 0x6c, 0x38, 0x72, 0x70, 0x4b, 0x7a, 0x50, 0x47, 0x63, 0x71, 0x4e, 0x67, 0x33, 0x5a, 0x41, 0x67, 0x4d, + 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, + 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x1f, 0xe3, 0xcf, 0x8d, 0x94, 0xb4, 0xa0, 0x9e, 0xf1, 0x0c, 0x38, 0x59, 0xcb, 0x5b, 0x89, 0xc9, + 0x66, 0x8b, 0xfd, 0x8d, 0x1e, 0x37, 0xfa, 0x5e, 0x1b, 0xb1, 0x51, 0x07, 0xf1, 0xb0, 0x7d, 0x18, + 0x2d, 0x82, 0x2a, 0x04, 0xa4, 0x4e, 0x94, 0x7e, 0x76, 0xb8, 0xa4, 0x78, 0x90, 0x2f, 0x43, 0x1d, + 0x95, 0x80, 0xd7, 0xb3, 0x46, 0x4d, 0x58, 0x4b, 0xcd, 0x1f, 0x1d, 0xb3, 0x1f, 0x6b, 0x15, 0xd8, + 0x33, 0x51, 0x1d, 0x36, 0x12, 0x39, 0x92, 0xb4, 0x4d, 0xe2, 0x89, 0x26, 0x01, 0xe9, 0x1f, 0xc0, + 0x9c, 0x7c, 0xd8, 0xeb, 0x47, 0xff, 0xfb, 0x5d, 0x98, 0x9a, 0x02, 0x6a, 0x16, 0x37, 0xb1, 0xf5, + 0x08, 0x4d, 0xd7, 0xa0, 0xf2, 0x9e, 0xbe, 0x4b, 0x54, 0x77, 0x94, 0x95, 0x4b, 0x97, 0x10, 0x22, + 0x49, 0xa5, 0x2e, 0x05, 0x86, 0xfd, 0x6f, 0x9a, 0x40, 0xe6, 0x43, 0xab, 0xc5, 0xbc, 0xac, 0x21, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return ret; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256|Recover", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + Crypto_DataBlob rawSignData = {.data = nullptr, .len = 0}; + ret = OH_CryptoVerify_Recover(verify, (Crypto_DataBlob *)&signBlob, &rawSignData); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return ret; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return ret; +} +// [End pkcs1_recover_rsa_keypair_sign] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c153dd1e410e3a46b46094970b178074c6888f62 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pkcs1_signature_validator.cpp @@ -0,0 +1,102 @@ +/* + * 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 pkcs1_verify_rsa_keypair_sign] +#include "signing_signature_verification.h" + +bool DoTestRsaSignature() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x43, 0x31, 0x7d, 0xb5, 0x85, 0x2e, 0xd4, 0xef, 0x08, 0x7a, 0x17, 0x96, 0xbc, 0x7c, 0x8f, 0x80, + 0x8c, 0xa7, 0x63, 0x7f, 0x26, 0x89, 0x8f, 0xf0, 0xfa, 0xa7, 0x51, 0xbd, 0x9c, 0x69, 0x17, 0xf3, + 0xd1, 0xb5, 0xc7, 0x12, 0xbf, 0xcf, 0x91, 0x25, 0x82, 0x23, 0x6b, 0xd6, 0x64, 0x52, 0x77, 0x93, + 0x01, 0x9d, 0x70, 0xa3, 0xf4, 0x92, 0x16, 0xec, 0x3f, 0xa7, 0x3c, 0x83, 0x8d, 0x40, 0x41, 0xfc, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x47, 0x4a, 0x41, + 0x6f, 0x47, 0x42, 0x41, 0x4d, 0x78, 0x63, 0x44, 0x4d, 0x6f, 0x61, 0x59, 0x52, 0x58, 0x6f, 0x78, 0x65, 0x69, + 0x33, 0x49, 0x6d, 0x33, 0x33, 0x78, 0x4a, 0x76, 0x61, 0x73, 0x63, 0x43, 0x62, 0x77, 0x31, 0x6f, 0x73, 0x63, + 0x32, 0x56, 0x56, 0x69, 0x47, 0x6a, 0x56, 0x47, 0x47, 0x4a, 0x37, 0x6c, 0x75, 0x4e, 0x41, 0x58, 0x6b, 0x6a, + 0x73, 0x56, 0x46, 0x64, 0x35, 0x0a, 0x58, 0x37, 0x4c, 0x4d, 0x6c, 0x46, 0x34, 0x63, 0x35, 0x5a, 0x75, 0x59, + 0x2f, 0x61, 0x69, 0x57, 0x77, 0x70, 0x54, 0x69, 0x63, 0x62, 0x67, 0x49, 0x33, 0x43, 0x66, 0x50, 0x6f, 0x32, + 0x6a, 0x6c, 0x52, 0x74, 0x67, 0x41, 0x46, 0x6b, 0x44, 0x71, 0x7a, 0x4b, 0x53, 0x46, 0x62, 0x46, 0x47, 0x51, + 0x6b, 0x43, 0x6e, 0x64, 0x63, 0x2b, 0x54, 0x59, 0x6b, 0x5a, 0x42, 0x32, 0x70, 0x45, 0x6f, 0x72, 0x0a, 0x7a, + 0x73, 0x61, 0x56, 0x58, 0x77, 0x5a, 0x47, 0x45, 0x34, 0x41, 0x43, 0x70, 0x59, 0x35, 0x79, 0x65, 0x66, 0x49, + 0x44, 0x6c, 0x45, 0x57, 0x49, 0x51, 0x4f, 0x6a, 0x59, 0x4b, 0x2f, 0x6c, 0x58, 0x71, 0x7a, 0x48, 0x47, 0x69, + 0x4f, 0x69, 0x32, 0x75, 0x4a, 0x45, 0x75, 0x44, 0x43, 0x50, 0x6a, 0x51, 0x64, 0x6a, 0x54, 0x41, 0x67, 0x4d, + 0x42, 0x41, 0x41, 0x45, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, + 0x20, 0x50, 0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x68, 0x2f, 0x3b, 0xe6, 0xa6, 0x5c, 0xb8, 0x60, 0xd4, 0xe1, 0x64, 0xa7, 0xd8, 0x0c, 0x9c, 0x89, + 0x39, 0xb4, 0xf0, 0xb7, 0xad, 0xb5, 0x8a, 0x71, 0x04, 0xf1, 0xa5, 0x63, 0xdd, 0x32, 0x6a, 0x44, + 0xeb, 0xff, 0xb7, 0xe6, 0x85, 0xe5, 0xa5, 0x55, 0x5d, 0x5b, 0x28, 0x53, 0x63, 0xe4, 0xb3, 0xb9, + 0xa8, 0x70, 0xc8, 0x8f, 0xcd, 0x21, 0x8d, 0xe6, 0x1f, 0xe5, 0x78, 0x34, 0xd3, 0x45, 0x0c, 0x9c, + 0x7a, 0x22, 0x1b, 0x63, 0x55, 0xca, 0x14, 0xa5, 0x0c, 0x7a, 0x40, 0x8e, 0xa1, 0x14, 0x78, 0xa1, + 0xf1, 0x36, 0x78, 0xbd, 0xba, 0x37, 0x3b, 0x5b, 0xb0, 0x8e, 0xb3, 0x4a, 0x9b, 0x1b, 0x0c, 0xfa, + 0xfa, 0xc7, 0x9f, 0xb1, 0x35, 0x48, 0x82, 0x73, 0xf8, 0x6b, 0xd4, 0x76, 0x33, 0x5c, 0xed, 0x9c, + 0xd8, 0x4b, 0xc9, 0x92, 0xa0, 0x3f, 0x6e, 0xba, 0x78, 0x2e, 0x80, 0x78, 0x1e, 0x74, 0xa0, 0x47, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA1024|PKCS1|SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (res != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} +// [End pkcs1_verify_rsa_keypair_sign] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp new file mode 100644 index 0000000000000000000000000000000000000000..daca1482f34cfa493fde007251751db5922b557e --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/rsa_pss_verification_tool.cpp @@ -0,0 +1,116 @@ +/* + * 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 pss_verify_rsa_keypair_sign] +#include "signing_signature_verification.h" + +bool DoTestRsaPssSignatureSeg() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x13, 0xa7, 0x73, 0xe8, 0xb8, 0x22, 0x99, 0x72, 0x98, 0x29, 0xae, 0x74, 0xa8, 0x4a, 0xea, 0xa9, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, + 0x4c, 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x43, + 0x67, 0x4b, 0x43, 0x41, 0x51, 0x45, 0x41, 0x76, 0x6a, 0x6c, 0x59, 0x35, 0x53, 0x72, 0x54, 0x57, 0x32, 0x43, + 0x78, 0x74, 0x47, 0x32, 0x54, 0x67, 0x54, 0x54, 0x39, 0x39, 0x78, 0x71, 0x37, 0x62, 0x4e, 0x41, 0x6b, 0x54, + 0x2b, 0x65, 0x6a, 0x75, 0x65, 0x7a, 0x37, 0x39, 0x37, 0x2f, 0x65, 0x63, 0x56, 0x4b, 0x34, 0x78, 0x37, 0x58, + 0x41, 0x4d, 0x6d, 0x73, 0x4a, 0x0a, 0x4a, 0x63, 0x66, 0x49, 0x36, 0x73, 0x54, 0x4d, 0x4e, 0x68, 0x45, 0x6b, + 0x70, 0x79, 0x63, 0x31, 0x4b, 0x32, 0x46, 0x6e, 0x30, 0x74, 0x59, 0x47, 0x2f, 0x6d, 0x4d, 0x37, 0x72, 0x71, + 0x6d, 0x6a, 0x6c, 0x6b, 0x75, 0x72, 0x34, 0x72, 0x74, 0x6a, 0x4a, 0x4a, 0x75, 0x66, 0x34, 0x35, 0x45, 0x42, + 0x30, 0x79, 0x6c, 0x55, 0x65, 0x47, 0x61, 0x39, 0x6d, 0x44, 0x4a, 0x57, 0x76, 0x62, 0x2b, 0x73, 0x0a, 0x41, + 0x4a, 0x78, 0x33, 0x41, 0x44, 0x78, 0x70, 0x50, 0x31, 0x59, 0x36, 0x46, 0x61, 0x71, 0x54, 0x44, 0x6e, 0x64, + 0x47, 0x41, 0x6e, 0x6b, 0x65, 0x4d, 0x53, 0x2f, 0x56, 0x71, 0x53, 0x45, 0x65, 0x75, 0x43, 0x36, 0x4d, 0x42, + 0x38, 0x52, 0x53, 0x65, 0x6f, 0x31, 0x4f, 0x59, 0x4c, 0x53, 0x73, 0x7a, 0x36, 0x43, 0x76, 0x38, 0x34, 0x76, + 0x76, 0x53, 0x69, 0x32, 0x37, 0x32, 0x51, 0x44, 0x6e, 0x0a, 0x6f, 0x4b, 0x4f, 0x4d, 0x34, 0x43, 0x78, 0x6d, + 0x6e, 0x32, 0x31, 0x58, 0x5a, 0x43, 0x5a, 0x2f, 0x59, 0x50, 0x32, 0x35, 0x67, 0x5a, 0x6e, 0x57, 0x4f, 0x61, + 0x42, 0x4c, 0x50, 0x57, 0x79, 0x6f, 0x48, 0x46, 0x65, 0x49, 0x55, 0x42, 0x48, 0x4c, 0x50, 0x69, 0x4a, 0x2b, + 0x72, 0x58, 0x48, 0x4e, 0x65, 0x4f, 0x38, 0x2b, 0x70, 0x6c, 0x37, 0x49, 0x42, 0x74, 0x66, 0x35, 0x67, 0x70, + 0x4a, 0x76, 0x0a, 0x31, 0x6e, 0x78, 0x72, 0x45, 0x4b, 0x73, 0x75, 0x2b, 0x6e, 0x64, 0x48, 0x43, 0x6e, 0x46, + 0x64, 0x6f, 0x38, 0x2f, 0x49, 0x46, 0x46, 0x4a, 0x6a, 0x70, 0x36, 0x73, 0x6f, 0x55, 0x4a, 0x4f, 0x5a, 0x52, + 0x4b, 0x6e, 0x6f, 0x41, 0x4b, 0x34, 0x67, 0x6a, 0x34, 0x48, 0x30, 0x50, 0x76, 0x49, 0x79, 0x4d, 0x67, 0x4b, + 0x61, 0x43, 0x43, 0x41, 0x55, 0x57, 0x70, 0x4a, 0x65, 0x76, 0x35, 0x42, 0x52, 0x0a, 0x42, 0x4f, 0x56, 0x38, + 0x4f, 0x59, 0x34, 0x48, 0x48, 0x6f, 0x42, 0x6b, 0x47, 0x4d, 0x6e, 0x32, 0x71, 0x6a, 0x4d, 0x48, 0x78, 0x49, + 0x6c, 0x71, 0x48, 0x50, 0x67, 0x59, 0x70, 0x41, 0x53, 0x50, 0x51, 0x77, 0x49, 0x44, 0x41, 0x51, 0x41, 0x42, + 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x52, 0x53, 0x41, 0x20, 0x50, 0x55, 0x42, 0x4c, + 0x49, 0x43, 0x20, 0x4b, 0x45, 0x59, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0xac, 0x2b, 0x12, 0x56, 0x1c, 0xe1, 0x60, 0x49, 0xc2, 0xd9, 0x87, 0x89, 0xfb, 0xa3, 0xc5, 0x41, 0x64, 0x7f, + 0x6f, 0x80, 0xc8, 0xdb, 0xb3, 0xdf, 0x25, 0x76, 0x4b, 0x1e, 0x51, 0xaa, 0x0a, 0x6d, 0x83, 0x49, 0xae, 0x00, + 0x7a, 0x99, 0xf4, 0xc8, 0x98, 0x45, 0x71, 0xfc, 0x5e, 0xdb, 0xed, 0x31, 0xad, 0xf2, 0x35, 0x05, 0xe2, 0x3e, + 0xf1, 0xcb, 0x96, 0xb2, 0xb9, 0x59, 0xaf, 0x30, 0x25, 0xb0, 0xda, 0x83, 0x18, 0x2b, 0x11, 0xa4, 0x93, 0x2d, + 0x9e, 0x93, 0x99, 0x62, 0xdd, 0xea, 0x1b, 0xfa, 0x60, 0xb8, 0xea, 0x9c, 0xef, 0x4f, 0x2b, 0x9d, 0xd1, 0x3e, + 0xe1, 0x6b, 0x24, 0x98, 0x9d, 0x32, 0xa3, 0x1e, 0x9d, 0x45, 0xe7, 0x3d, 0x51, 0x7e, 0x3b, 0x0c, 0xee, 0x3f, + 0xca, 0x29, 0xd9, 0x02, 0xe5, 0xb8, 0xf5, 0x89, 0x06, 0xf4, 0xfe, 0x27, 0x44, 0xff, 0x38, 0xed, 0x5a, 0x0e, + 0x89, 0x16, 0x15, 0x26, 0xf0, 0xb2, 0x4c, 0x95, 0xee, 0x0a, 0xd3, 0x61, 0xc7, 0xb2, 0x4b, 0xfd, 0x20, 0xb9, + 0x83, 0x25, 0x43, 0x4d, 0xa0, 0x3d, 0xaa, 0x40, 0x7b, 0xac, 0x01, 0x48, 0x8e, 0x2a, 0x96, 0x11, 0xc0, 0x31, + 0x51, 0x5b, 0xaf, 0xeb, 0x8b, 0xaf, 0xb5, 0x88, 0xcb, 0xe0, 0x97, 0x45, 0x36, 0xe9, 0x6e, 0x6e, 0xe0, 0x55, + 0xea, 0xf4, 0xd2, 0x88, 0xbb, 0xc9, 0x85, 0x94, 0xd5, 0x65, 0xeb, 0xa3, 0x1c, 0xd1, 0xd6, 0xf5, 0x22, 0x29, + 0xf1, 0x16, 0xa5, 0x53, 0x1b, 0xd0, 0x6c, 0xf6, 0x0d, 0xa8, 0xd4, 0xe4, 0xb2, 0x0a, 0x92, 0x64, 0x7a, 0x6d, + 0xf2, 0x76, 0xf3, 0xb0, 0x08, 0x44, 0x31, 0x31, 0x90, 0x48, 0x9e, 0x2e, 0x03, 0xc7, 0xab, 0x5d, 0x7a, 0x07, + 0x1f, 0x1d, 0x10, 0x21, 0x54, 0x60, 0x0d, 0x26, 0xe4, 0x1c, 0xc7, 0x82, 0x03, 0x65, 0x64, 0x70, 0x41, 0x68, + 0x0f, 0xfa, 0x64, 0x3c, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"RSA2048", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_PEM, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"RSA2048|PSS|SHA256|MGF1_SHA256", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (ret != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} +// [End pss_verify_rsa_keypair_sign] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h new file mode 100644 index 0000000000000000000000000000000000000000..2aca2232efb18f0901cb7e392853b128f31bbadc --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/signing_signature_verification.h @@ -0,0 +1,29 @@ +#ifndef MYAPPLICATION_AA_H +#define MYAPPLICATION_AA_H +/* + * 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. + */ + +#include "CryptoArchitectureKit/crypto_common.h" +#include "CryptoArchitectureKit/crypto_signature.h" +#include "CryptoArchitectureKit/crypto_asym_key.h" + +bool DoTestRsaSignature(); +bool DoTestRsaSignatureSeg(); +OH_Crypto_ErrCode DoTestRsaSignatureRecover(); +bool DoTestRsaPssSignatureSeg(); +bool DoTestEcdsaSignature(); +bool DoTestSm2Signature(); + +#endif // MYAPPLICATION_AA_H \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ca9a53c96e5e130144778d468e39547e0fe51f7 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/cpp/types/project/sm2_signature_verification.cpp @@ -0,0 +1,88 @@ +/* + * 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 verify_signatures_with_sm2_key_pair_c] +#include "signing_signature_verification.h" + +bool DoTestSm2Signature() +{ + OH_CryptoAsymKeyGenerator *keyCtx = nullptr; + OH_CryptoKeyPair *keyPair = nullptr; + OH_CryptoVerify *verify = nullptr; + + uint8_t plainText[] = { + 0x96, 0x46, 0x2e, 0xde, 0x3f, 0x47, 0xbf, 0xd6, 0x87, 0x48, 0x36, 0x1d, 0x75, 0x35, 0xbd, 0xbc, + 0x6b, 0x06, 0xe8, 0xb3, 0x68, 0x91, 0x53, 0xce, 0x76, 0x5d, 0x24, 0xda, 0xdc, 0xc4, 0x9f, 0x94, + }; + Crypto_DataBlob msgBlob = {.data = reinterpret_cast(plainText), .len = sizeof(plainText)}; + + uint8_t pubKeyText[] = { + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, + 0x81, 0x1c, 0xcf, 0x55, 0x01, 0x82, 0x2d, 0x03, 0x42, 0x00, 0x04, 0x80, 0x5b, 0x78, 0x04, 0xd7, + 0xcf, 0xc3, 0x99, 0x63, 0xae, 0x88, 0xcd, 0xfc, 0xd6, 0x18, 0xf4, 0x08, 0xe8, 0xe3, 0x68, 0x47, + 0x4f, 0x44, 0x0e, 0xb2, 0xba, 0x3a, 0xb3, 0x10, 0xf1, 0xc9, 0xd0, 0x84, 0xe2, 0xa4, 0x47, 0xbe, + 0x72, 0xae, 0xf8, 0x6a, 0xeb, 0x6e, 0x10, 0xab, 0x52, 0x6b, 0x6a, 0x58, 0xc6, 0xb5, 0x78, 0xaa, + 0x70, 0xe5, 0x58, 0x20, 0x4e, 0x34, 0x42, 0x77, 0x08, 0x27, 0x11, + }; + + Crypto_DataBlob keyBlob = {.data = reinterpret_cast(pubKeyText), .len = sizeof(pubKeyText)}; + + uint8_t signText[] = { + 0x30, 0x45, 0x02, 0x21, 0x00, 0xf4, 0xe7, 0x9d, 0x35, 0x33, 0xa6, 0x86, 0x2e, 0x2a, 0x97, 0x72, 0xc9, 0x46, + 0x79, 0x65, 0xca, 0x4a, 0x71, 0x34, 0xca, 0xf7, 0x58, 0xb3, 0x26, 0xa5, 0xdb, 0xfa, 0x8b, 0xbe, 0xbf, 0x5f, + 0x90, 0x02, 0x20, 0x53, 0xb4, 0x23, 0xb1, 0xe2, 0x8f, 0x2f, 0xe9, 0xc8, 0x22, 0xef, 0xab, 0x9b, 0x13, 0x08, + 0x75, 0x8e, 0xb1, 0x9c, 0x59, 0xe5, 0xd6, 0x64, 0x35, 0xf5, 0xd1, 0xde, 0xfa, 0xfe, 0x80, 0x37, 0x1a, + }; + + Crypto_DataBlob signBlob = {.data = reinterpret_cast(signText), .len = sizeof(signText)}; + + // keypair + OH_Crypto_ErrCode ret = CRYPTO_SUCCESS; + ret = OH_CryptoAsymKeyGenerator_Create((const char *)"SM2_256", &keyCtx); + if (ret != CRYPTO_SUCCESS) { + return false; + } + ret = OH_CryptoAsymKeyGenerator_Convert(keyCtx, CRYPTO_DER, &keyBlob, nullptr, &keyPair); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + OH_CryptoPubKey *pubKey = OH_CryptoKeyPair_GetPubKey(keyPair); + // verify + ret = OH_CryptoVerify_Create((const char *)"SM2_256|SM3", &verify); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + ret = OH_CryptoVerify_Init(verify, pubKey); + if (ret != CRYPTO_SUCCESS) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + bool res = OH_CryptoVerify_Final(verify, &msgBlob, &signBlob); + if (ret != true) { + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + return false; + } + + OH_CryptoVerify_Destroy(verify); + OH_CryptoAsymKeyGenerator_Destroy(keyCtx); + OH_CryptoKeyPair_Destroy(keyPair); + return res; +} + +// [End verify_signatures_with_sm2_key_pair_c] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entryability/EntryAbility.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..965554bb3a331e2418180b86da1993baf5e8d536 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..037c49dd582119f1322d373a61ffc3082b92e4aa --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/ets/pages/Index.ets @@ -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. + */ + +import testNapi from 'libentry.so'; + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 5 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_seg')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.signatureSeg(); + this.message = 'SignatureSegSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_signature')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.signature(); + this.message = 'SignatureSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_signature_recover')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.signatureRecover(); + this.message = 'SignatureRecoverSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_psssignature_seg')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.pssSignatureSeg(); + this.message = 'PSSSignatureSegSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_ecdsasignature')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.ecdsaSignature(); + this.message = 'ECDSASignatureSuccess Result:' + ret.toString(); + }) + Button($r('app.string.call_sm2signature')) + .width('70%') + .onClick(() => { + let ret: number = testNapi.sm2Signature(); + this.message = 'SM2SignatureSuccess Result:' + ret.toString(); + }) + } + .height('100%') + .width('100%') + } +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/module.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/color.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/string.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..52aa689cfa16cbd29fd856b0b657775b915035f0 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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": "SigningSignatureVerification" + }, + { + "name": "call_signature_seg", + "value": "Call SignatureSeg" + }, + { + "name": "call_signature", + "value": "Call Signature" + }, + { + "name": "call_signature_recover", + "value": "Call SignatureRecover" + }, + { + "name": "call_psssignature_seg", + "value": "Call PSSSignatureSeg" + }, + { + "name": "call_ecdsasignature", + "value": "Call ECDSASignature" + }, + { + "name": "call_sm2signature", + "value": "Call SM2Signature" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/background.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/background.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/foreground.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/foreground.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/layered_image.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/startIcon.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/backup_config.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/main_pages.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/dark/element/color.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/Ability.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/List.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..00d881f782076d46db517c3c9c373b1bbb289cc0 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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 signingSignatureVerificationTest from './SigningSignatureVerification.test'; + +export default function testsuite() { + abilityTest(); + signingSignatureVerificationTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d3612f119b2796631d0168a6737cf4dde83c410 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/ets/test/SigningSignatureVerification.test.ets @@ -0,0 +1,128 @@ +/* + * 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 signingSignatureVerificationTest() { + describe('signingSignatureVerificationTest', () => { + /** + * 打开应用 + */ + 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'); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)验签(C/C++) + */ + it('testSigningSignatureVerificationTest001', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SignatureSeg')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSegSuccess Result:true')); + console.info('uitest: testSigningSignatureVerificationTest001 end'); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名恢复(C/C++) + */ + it('testSigningSignatureVerificationTest002', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call Signature')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSuccess Result:true')); + console.info('uitest: testSigningSignatureVerificationTest002 end'); + }) + + /** + * 点击按钮,使用RSA密钥对分段验签(PKCS1模式)(C/C++) + */ + it('testSigningSignatureVerificationTest003', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SignatureRecover')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureRecoverSuccess Result:0')); + console.info('uitest: testSigningSignatureVerificationTest003 end'); + }) + + /** + * 点击按钮,使用RSA密钥对验签(PSS模式)(C/C++) + */ + it('testSigningSignatureVerificationTest004', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest004 begin'); + const driver = Driver.create(); + const button = await driver.findComponent(ON.text('Call PSSSignatureSeg')); + await driver.delayMs(1000); + await button.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess Result:false')); + console.info('uitest: testSigningSignatureVerificationTest004 end'); + }) + + /** + * 点击按钮,使用ECDSA密钥对验签(C/C++) + */ + it('testSigningSignatureVerificationTest005', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call ECDSASignature')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECDSASignatureSuccess Result:false')); + console.info('uitest: testSigningSignatureVerificationTest005 end'); + }) + + /** + * 点击按钮,使用SM2密钥对验签(C/C++) + */ + it('testSigningSignatureVerificationTest006', 0, async () => { + console.info('uitest: testSigningSignatureVerificationTest006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('Call SM2Signature')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2SignatureSuccess Result:false')); + console.info('uitest: testSigningSignatureVerificationTest006 end'); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/module.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/test/List.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/entry/src/test/LocalUnit.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/hvigor/hvigor-config.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/hvigorfile.ts b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/oh-package.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/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/SignatureVerification/SigningSignatureVerification/ohosTest.md b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..3484ec8f4819a42287f78c19354fd6a5f175243e --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/ohosTest.md @@ -0,0 +1,13 @@ +# 签名验签(C/C++)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| --------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名恢复(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对分段验签(PKCS1模式)(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对验签(PSS模式)(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDSA密钥对验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM2密钥对验签(C/C++) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification1.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification1.png new file mode 100644 index 0000000000000000000000000000000000000000..803c1b432be51366d65ff3497d0fe16e29a0a2ab Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification1.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification2.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification2.png new file mode 100644 index 0000000000000000000000000000000000000000..54127b135b6f5bf593cceb57205d84f4d42a7ddc Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerification/screenshots/SigningSignatureVerification2.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/.gitignore b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/.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/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/app.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..839e94769a08a2a0352e9e4e1ef9d8c02ba591da --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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.signingsignatureverificationarkts", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..23956993e9766f265e2dc17d8fb70fcf9fdabd45 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SigningSignatureVerificationArkTs" + } + ] +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/media/app_icon.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/AppScope/resources/base/media/app_icon.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md new file mode 100644 index 0000000000000000000000000000000000000000..50411aa3fa2e4627041beb8f451302689031df80 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/README.md @@ -0,0 +1,82 @@ +# 签名验签(ArkTS) + +### 介绍 + +当需要判断接收的数据是否被篡改、数据是否为指定对象发送的数据时,可以使用签名验签操作。接下来将说明系统目前支持的算法及其对应的规格。 + +本示例主要展示了签名验签(ArkTS)的多种场景 。该工程中展示的代码详细描述可查如下链接。 + +- [使用RSA密钥对(PKCS1模式)签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1.md) +- [使用RSA密钥对(PKCS1模式)签名及签名恢复(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-recover-pkcs1.md) +- [使用RSA密钥对分段签名验签(PKCS1模式)(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pkcs1-by-segment.md) +- [使用RSA密钥对签名验签(PSS模式)(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-rsa-sign-sig-verify-pss.md) +- [使用ECDSA密钥对签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-ecdsa-sign-sig-verify.md) +- [使用SM2密钥对签名验签(ArkTS)](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/security/CryptoArchitectureKit/crypto-sm2-sign-sig-verify-pkcs1.md) + +### 效果预览 + +| 首页效果图 | 执行结果图 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| | | + +### 使用说明 + +1. 运行Index主界面。 +2. 页面呈现上述执行结果图效果,点击不同按钮可以跳转到不同功能页面,点击跳转页面中按钮可以执行对应操作,并更新文本内容。 +3. 运行测试用例SigningSignatureVerificationArkTs.test.ets文件对页面代码进行测试可以全部通过。 + +### 工程目录 + +``` +entry/src/ + ├── main + │ ├── ets + │ │ ├── entryability + │ │ ├── entrybackupability + │ │ ├── pages + │ │ ├── Index.ets // 签名验签(ArkTS)示例代码 + │ │ ├── ecdsa_signature_verification + │ │ ├── rsa_pkcs1_segment_signature + │ │ ├── rsa_pkcs1_signature_restoration + │ │ ├── rsa_pkcs1_signature_validator + │ │ ├── rsa_pss_signature_verification + │ │ ├── sm2_signature_verification + │ ├── module.json5 + │ └── resources + ├── ohosTest + │ ├── ets + │ │ └── test + │ │ ├── Ability.test.ets + │ │ ├── SigningSignatureVerificationArkTs.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/SignatureVerification/SigningSignatureVerificationArkTs > .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/SignatureVerification/SigningSignatureVerificationArkTs/build-profile.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fb5a1ab654ae6715a0ab69a31900ad26dcf2487f --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/code-linter.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/code-linter.json5 new file mode 100644 index 0000000000000000000000000000000000000000..28586467ee7a761c737d8654a73aed6fddbc3c71 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/.gitignore b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/build-profile.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/hvigorfile.ts b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/oh-package.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c9cb6c8174858277c9b0d465a51547dcab16d5ff --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entryability/EntryAbility.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..edc2839f203ba057c186e19b0cbbbf80c8faa8b3 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..b1e212947256c5533c7b06285a597c94f840a6e3 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/Index.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..bdf2169035e2de29e179199ecc18035f2b802817 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,102 @@ +/* + * 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 = 'Hello World'; + + 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('SigningSignatureVerificationArkTs').fontSize(27).fontWeight(FontWeight.Bolder) + Button($r('app.string.rsa_pkcs1_signature_validator_asynchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous') + }) + Button($r('app.string.rsa_pkcs1_signature_validator_synchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous') + }) + Button($r('app.string.rsa_pkcs1_signature_restoration_asynchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous') + }) + Button($r('app.string.rsa_pkcs1_signature_restoration_synchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous') + }) + Button($r('app.string.rsa_pkcs1_segment_signature_asynchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous') + }) + Button($r('app.string.rsa_pkcs1_segment_signature_synchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous') + }) + Button($r('app.string.rsa_pss_signature_verification_asynchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous') + }) + Button($r('app.string.rsa_pss_signature_verification_synchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous') + }) + Button($r('app.string.ecdsa_signature_verification_asynchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous') + }) + Button($r('app.string.ecdsa_signature_verification_synchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous') + }) + Button($r('app.string.sm2_signature_verification_asynchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/sm2_signature_verification/sm2_signature_verification_asynchronous') + }) + Button($r('app.string.sm2_signature_verification_synchronous')) + .width('70%') + .onClick(() => { + this.goToSample('pages/sm2_signature_verification/sm2_signature_verification_synchronous') + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..8f55acfd9a031d693f90883eaac0fbdc920823c2 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous.ets @@ -0,0 +1,80 @@ +/* + * 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 signature_verification_with_ecdsa_key_pair_ark_async] + +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'ECC256|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = await signer.sign(input2); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'ECC256|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = await verifier.verify(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function main() { + let keyGenAlg = 'ECC256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +// [End signature_verification_with_ecdsa_key_pair_ark_async] +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecdsasignature_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'ECDSASignatureSuccess'; + } catch { + this.message = 'ECDSASignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..12568ccd9e57e21ca226ca43d5bb9e9a66d62728 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous.ets @@ -0,0 +1,79 @@ +/* + * 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 signature_verification_with_ecdsa_key_pair_ark_sync] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'ECC256|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = signer.signSync(input2); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'ECC256|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = verifier.verifySync(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function main() { + let keyGenAlg = 'ECC256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + + +// [End signature_verification_with_ecdsa_key_pair_ark_sync] +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_ecdsasignature_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'ECDSASignatureSuccess'; + } catch { + this.message = 'ECDSASignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..9fbda9d0a0f72c1c2c78c26c55b07cbb9509c356 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous.ets @@ -0,0 +1,99 @@ +/* + * 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 pkcs1_seg_verify_rsa_keypair_sign_async] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +async function signMessageBySegment(priKey: cryptoFramework.PriKey, plainText: Uint8Array) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + await signer.update(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处sign传入null + let signData = await signer.sign(null); + return signData; +} + +async function verifyMessagBySegment(pubKey: cryptoFramework.PubKey, plainText: Uint8Array, + signMessageBlob: cryptoFramework.DataBlob) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + await verifier.update(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处verify第一个参数传入null + let res = await verifier.verify(null, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function rsaSignatureBySegment() { + let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let messageData = new Uint8Array(buffer.from(message, 'utf-8').buffer); + let signData = await signMessageBySegment(keyPair.priKey, messageData); + let verifyResult = await verifyMessagBySegment(keyPair.pubKey, messageData, signData); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signatureseg_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await rsaSignatureBySegment(); + this.message = 'SignatureSegSuccess'; + } catch { + this.message = 'SignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } +} +// [End pkcs1_seg_verify_rsa_keypair_sign_async] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..ce88faa050cbea052315ad978e9f60bf786e803e --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous.ets @@ -0,0 +1,99 @@ +/* + * 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 pkcs1_seg_verify_rsa_keypair_sign_async] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +function signMessageBySegment(priKey: cryptoFramework.PriKey, plainText: Uint8Array) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + signer.updateSync(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处sign传入null + let signData = signer.signSync(null); + return signData; +} + +function verifyMessagBySegment(pubKey: cryptoFramework.PubKey, plainText: Uint8Array, + signMessageBlob: cryptoFramework.DataBlob) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + let textSplitLen = 64; // 自定义的数据拆分长度,此处取64 + for (let i = 0; i < plainText.length; i += textSplitLen) { + let updateMessage = plainText.subarray(i, i + textSplitLen); + let updateMessageBlob: cryptoFramework.DataBlob = { data: updateMessage }; + // 分段update + verifier.updateSync(updateMessageBlob); + } + // 已通过分段传入所有明文,故此处verify第一个参数传入null + let res = verifier.verifySync(null, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function rsaSignatureBySegment() { + let message = 'This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!' + + 'This is a long plainTest! This is a long plainTest! This is a long plainTest! This is a long plainTest!'; + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let messageData = new Uint8Array(buffer.from(message, 'utf-8').buffer); + let signData = signMessageBySegment(keyPair.priKey, messageData); + let verifyResult = verifyMessagBySegment(keyPair.pubKey, messageData, signData); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signatureseg_synchronous')) + .width('70%') + .onClick(() => { + try { + rsaSignatureBySegment(); + this.message = 'SignatureSegSuccess'; + } catch { + this.message = 'SignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } +} +// [End pkcs1_seg_verify_rsa_keypair_sign_async] \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..a7aa691f192e98dbbd02d3401cc7f3b37a84d425 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous.ets @@ -0,0 +1,75 @@ +/* + * 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 pkcs1_recover_rsa_keypair_sign_async] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|NoHash|OnlySign'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + let signData = await signer.sign(input1); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|NoHash|Recover'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + let rawSignData = await verifier.recover(signMessageBlob); + return rawSignData; +} + +async function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let rawSignData = await verifyMessagePromise(signData, keyPair.pubKey); + if (rawSignData != null) { + console.info('recover result: ' + rawSignData.data); + } else { + console.error('get verify recover result fail!'); + } +} +// [End pkcs1_recover_rsa_keypair_sign_async] + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_recover_asynchronous')) + .width('70%') + .onClick(async () => { + try { + await main(); + this.message = 'SignatureRecoverSuccess'; + } catch { + this.message = 'SignatureRecoverFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..67bf74dc986f082be1d66fc5b2c3cddce4e436d8 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous.ets @@ -0,0 +1,75 @@ +/* + * 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 pkcs1_recover_rsa_keypair_sign_sync] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|NoHash|OnlySign'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + let signData = signer.signSync(input1); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|NoHash|Recover'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + let rawSignData = verifier.recoverSync(signMessageBlob); + return rawSignData; +} + +function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let rawSignData = verifyMessagePromise(signData, keyPair.pubKey); + if (rawSignData != null) { + console.info('recover result: ' + rawSignData.data); + } else { + console.error('get verify recover result fail!'); + } +} +// [End pkcs1_recover_rsa_keypair_sign_sync] + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_recover_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SignatureRecoverSuccess'; + } catch { + this.message = 'SignatureRecoverFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..5dacfc1341d003392fe6c4d4555992f2541213e6 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous.ets @@ -0,0 +1,79 @@ +/* + * 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 pkcs1_verify_rsa_keypair_sign_async] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = await signer.sign(input2); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = await verifier.verify(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} +// [End pkcs1_verify_rsa_keypair_sign_async] + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_verify_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await main(); + this.message = 'SignatureVerifySuccess'; + } catch { + this.message = 'SignatureVerifyFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..6c0a7fd9b888d6797e2bc5307081d005e76d0799 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous.ets @@ -0,0 +1,79 @@ +/* + * 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 pkcs1_verify_rsa_keypair_sign_sync] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'RSA1024|PKCS1|SHA256'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = signer.signSync(input2); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'RSA1024|PKCS1|SHA256'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = verifier.verifySync(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function main() { + let keyGenAlg = 'RSA1024'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} +// [End pkcs1_verify_rsa_keypair_sign_sync] + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_signature_verify_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SignatureVerifySuccess'; + } catch { + this.message = 'SignatureVerifyFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e67a8f9b82f0d0a0587b14cf6f76d2bca3a4b1e --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous.ets @@ -0,0 +1,127 @@ +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 根据密钥参数属性构造RSA非对称密钥对密钥参数 +function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: dIn, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC + }; + return rsaKeyPairSpec; +} + +// 生成RSA2048密钥对参数 +function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc432' + + '8daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34e4' + + 'd933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa7ac' + + '59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589c3e2' + + '53f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + let dIn = + BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb3' + + '06aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283ad8' + + 'bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b275' + + '06c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdde721' + + '26b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); + return genRsaKeyPairSpec(nIn, eIn, dIn); +} + +async function verifyMessagePSS() { + // 完整的明文被拆分为input1和input2 + let plan1 = 'This is Sign test plan1'; + let plan2 = 'This is Sign test plan2'; + let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan1, 'utf-8').buffer) }; + let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan2, 'utf-8').buffer) }; + // 获得RSA密钥对密钥参数对象 + let rsaKeyPairSpec = genRsa2048KeyPairSpec(); + // 构造RSA密钥对生成器 + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + // sign和verfiy均支持RSA密钥带长度/不带长度的写法 + let signer = cryptoFramework.createSign('RSA|PSS|SHA256|MGF1_SHA256'); + let verifyer = cryptoFramework.createVerify('RSA2048|PSS|SHA256|MGF1_SHA256'); + let keyPair = await rsaGeneratorSpec.generateKeyPair(); + await signer.init(keyPair.priKey); + // 在签名初始化后,对PSS参数进行set和get操作 + let setN = 32; + signer.setSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + let saltLen = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + let tf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + let md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + let mgf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + let mgf1Md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + await signer.update(input1); + let signMessageBlob = await signer.sign(input2); + // 在验签初始化前,对PSS参数进行set和get操作 + verifyer.setVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + saltLen = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + tf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + mgf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + mgf1Md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + await verifyer.init(keyPair.pubKey); + await verifyer.update(input1); + let verifyResult = await verifyer.verify(input2, signMessageBlob); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_psssignatureseg_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await verifyMessagePSS(); + this.message = 'PSSSignatureSegSuccess'; + } catch { + this.message = 'PSSSignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..fd4f9257b3fe3f7f2d99ab9638d622f3669df9ae --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous.ets @@ -0,0 +1,127 @@ +/* + * 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 { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 根据密钥参数属性构造RSA非对称密钥对密钥参数 +function genRsaKeyPairSpec(nIn: bigint, eIn: bigint, dIn: bigint) { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: dIn, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC + }; + return rsaKeyPairSpec; +} + +// 生成RSA2048密钥对参数 +function genRsa2048KeyPairSpec(): cryptoFramework.RSAKeyPairSpec { + let nIn = + BigInt('0x9260d0750ae117eee55c3f3deaba74917521a262ee76007cdf8a56755ad73a1598a1408410a01434c3f5bc54a88b57fa19fc43' + + '28daea0750a4c44e88cff3b2382621b80f670464433e4336e6d003e8cd65bff211da144b88291c2259a00a72b711c116ef7686e8fee34' + + 'e4d933c868187bdc26f7be071493c86f7a5941c3510806ad67b0f94d88f5cf5c02a092821d8626e8932b65c5bd8c92049c210932b7afa' + + '7ac59c0e886ae5c1edb00d8ce2c57633db26bd6639bff73cee82be9275c402b4cf2a4388da8cf8c64eefe1c5a0f5ab8057c39fa5c0589' + + 'c3e253f0960332300f94bea44877b588e1edbde97cf2360727a09b775262d7ee552b3319b9266f05a25'); + let eIn = BigInt('0x010001'); + let dIn = + BigInt('0x6a7df2ca63ead4dda191d614b6b385e0d9056a3d6d5cfe07db1daabee022db08212d97613d3328e0267c9dd23d787abde2afcb' + + '306aeb7dfce69246cc73f5c87fdf06030179a2114b767db1f083ff841c025d7dc00cd82435b9a90f695369e94df23d2ce458bc3b3283a' + + 'd8bba2b8fa1ba62e2dce9accff3799aae7c840016f3ba8e0048c0b6cc4339af7161003a5beb864a0164b2c1c9237b64bc87556994351b' + + '27506c33d4bcdfce0f9c491a7d6b0628c7c852be4f0a9c3132b2ed3a2c8881e9aab07e20e17deb074691be677776a78b5c502e05d9bdd' + + 'e72126b3738695e2dd1a0a98a14247c65d8a7ee79432a092cb0721a12df798e44f7cfce0c498147a9b1'); + return genRsaKeyPairSpec(nIn, eIn, dIn); +} + +function verifyMessagePSS() { + // 完整的明文被拆分为input1和input2 + let plan1 = 'This is Sign test plan1'; + let plan2 = 'This is Sign test plan2'; + let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan1, 'utf-8').buffer) }; + let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from(plan2, 'utf-8').buffer) }; + // 获得RSA密钥对密钥参数对象 + let rsaKeyPairSpec = genRsa2048KeyPairSpec(); + // 构造RSA密钥对生成器 + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + // sign和verfiy均支持RSA密钥带长度/不带长度的写法 + let signer = cryptoFramework.createSign('RSA|PSS|SHA256|MGF1_SHA256'); + let verifyer = cryptoFramework.createVerify('RSA2048|PSS|SHA256|MGF1_SHA256'); + let keyPair = rsaGeneratorSpec.generateKeyPairSync(); + signer.initSync(keyPair.priKey); + // 在签名初始化后,对PSS参数进行set和get操作 + let setN = 32; + signer.setSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + let saltLen = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + let tf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + let md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + let mgf = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + let mgf1Md = signer.getSignSpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + console.info('mgf1Md == ' + mgf1Md); + signer.updateSync(input1); + let signMessageBlob = signer.signSync(input2); + // 在验签初始化前,对PSS参数进行set和get操作 + verifyer.setVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM, setN); + saltLen = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_SALT_LEN_NUM); + console.info('SaltLen == ' + saltLen); + tf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_TRAILER_FIELD_NUM); + console.info('trailer field == ' + tf); + md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MD_NAME_STR); + console.info('md == ' + md); + mgf = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF_NAME_STR); + console.info('mgf == ' + mgf); + mgf1Md = verifyer.getVerifySpec(cryptoFramework.SignSpecItem.PSS_MGF1_MD_STR); + verifyer.initSync(keyPair.pubKey); + verifyer.updateSync(input1); + let verifyResult = verifyer.verifySync(input2, signMessageBlob); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_psssignatureseg_synchronous')) + .width('70%') + .onClick(() => { + try { + verifyMessagePSS(); + this.message = 'PSSSignatureSegSuccess'; + } catch { + this.message = 'PSSSignatureSegFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff0539c3104861de95eeefcb33709a4dc9de3290 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_asynchronous.ets @@ -0,0 +1,79 @@ +/* + * 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_the_sm2_key_pair_to_sign_and_verify_async] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +async function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'SM2_256|SM3'; + let signer = cryptoFramework.createSign(signAlg); + await signer.init(priKey); + await signer.update(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = await signer.sign(input2); + return signData; +} + +async function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'SM2_256|SM3'; + let verifier = cryptoFramework.createVerify(verifyAlg); + await verifier.init(pubKey); + await verifier.update(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = await verifier.verify(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +async function main() { + let keyGenAlg = 'SM2_256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = await generator.generateKeyPair(); + let signData = await signMessagePromise(keyPair.priKey); + let verifyResult = await verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + + +// [End use_the_sm2_key_pair_to_sign_and_verify_async] +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_signature_asynchronous')) + .width('70%') + .onClick(async() => { + try { + await main(); + this.message = 'SM2SignatureSuccess'; + } catch { + this.message = 'SM2SignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets new file mode 100644 index 0000000000000000000000000000000000000000..425e384e5c3d61dea5c8048063dd275562d50181 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/ets/pages/sm2_signature_verification/sm2_signature_verification_synchronous.ets @@ -0,0 +1,79 @@ +/* + * 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_the_sm2_key_pair_to_sign_and_verify_sync] +import { cryptoFramework } from '@kit.CryptoArchitectureKit'; +import { buffer } from '@kit.ArkTS'; + +// 完整的明文被拆分为input1和input2 +let input1: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan1', 'utf-8').buffer) }; +let input2: cryptoFramework.DataBlob = { data: new Uint8Array(buffer.from('This is Sign test plan2', 'utf-8').buffer) }; + +function signMessagePromise(priKey: cryptoFramework.PriKey) { + let signAlg = 'SM2_256|SM3'; + let signer = cryptoFramework.createSign(signAlg); + signer.initSync(priKey); + signer.updateSync(input1); // 如果明文较短,可以直接调用sign接口一次性传入 + let signData = signer.signSync(input2); + return signData; +} + +function verifyMessagePromise(signMessageBlob: cryptoFramework.DataBlob, pubKey: cryptoFramework.PubKey) { + let verifyAlg = 'SM2_256|SM3'; + let verifier = cryptoFramework.createVerify(verifyAlg); + verifier.initSync(pubKey); + verifier.updateSync(input1); // 如果明文较短,可以直接调用verify接口一次性传入 + let res = verifier.verifySync(input2, signMessageBlob); + console.info('verify result is ' + res); + return res; +} + +function main() { + let keyGenAlg = 'SM2_256'; + let generator = cryptoFramework.createAsyKeyGenerator(keyGenAlg); + let keyPair = generator.generateKeyPairSync(); + let signData = signMessagePromise(keyPair.priKey); + let verifyResult = verifyMessagePromise(signData, keyPair.pubKey); + if (verifyResult === true) { + console.info('verify success'); + } else { + console.error('verify failed'); + } +} + +// [End use_the_sm2_key_pair_to_sign_and_verify_sync] + +@Entry +@Component +struct Index { + @State message: string = 'Signing Signature Verification'; + + build() { + Column({ space: 12 }) { + Text(this.message).fontSize(25).fontWeight(FontWeight.Bold) + Button($r('app.string.call_sm2_signature_synchronous')) + .width('70%') + .onClick(() => { + try { + main(); + this.message = 'SM2SignatureSuccess'; + } catch { + this.message = 'SM2SignatureFail'; + } + }) + } + .height('100%') + .width('100%') + } +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/module.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4144486d1af4c03b0d767cce1cda86fc0d697f91 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/color.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/string.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..37103725d3d750cc823d30c2189c476df2978ee9 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/element/string.json @@ -0,0 +1,112 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "SigningSignatureVerificationArkTs" + }, + { + "name": "rsa_pkcs1_signature_validator_asynchronous", + "value": "rsa_pkcs1_signature_validator_asynchronous" + }, + { + "name": "rsa_pkcs1_signature_validator_synchronous", + "value": "rsa_pkcs1_signature_validator_synchronous" + }, + { + "name": "rsa_pkcs1_signature_restoration_asynchronous", + "value": "rsa_pkcs1_signature_restoration_asynchronous" + }, + { + "name": "rsa_pkcs1_signature_restoration_synchronous", + "value": "rsa_pkcs1_signature_restoration_synchronous" + }, + { + "name": "rsa_pkcs1_segment_signature_asynchronous", + "value": "rsa_pkcs1_segment_signature_asynchronous" + }, + { + "name": "rsa_pkcs1_segment_signature_synchronous", + "value": "rsa_pkcs1_segment_signature_synchronous" + }, + { + "name": "rsa_pss_signature_verification_asynchronous", + "value": "rsa_pss_signature_verification_asynchronous" + }, + { + "name": "rsa_pss_signature_verification_synchronous", + "value": "rsa_pss_signature_verification_synchronous" + }, + { + "name": "ecdsa_signature_verification_asynchronous", + "value": "ecdsa_signature_verification_asynchronous" + }, + { + "name": "ecdsa_signature_verification_synchronous", + "value": "ecdsa_signature_verification_synchronous" + }, + { + "name": "sm2_signature_verification_asynchronous", + "value": "sm2_signature_verification_asynchronous" + }, + { + "name": "sm2_signature_verification_synchronous", + "value": "sm2_signature_verification_synchronous" + }, + { + "name": "call_ecdsasignature_asynchronous", + "value": "Call ECDSASignature Asynchronous" + }, + { + "name": "call_ecdsasignature_synchronous", + "value": "Call ECDSASignature Synchronous" + }, + { + "name": "call_signatureseg_asynchronous", + "value": "Call SignatureSeg Asynchronous" + }, + { + "name": "call_signatureseg_synchronous", + "value": "Call SignatureSeg Synchronous" + }, + { + "name": "call_signature_recover_asynchronous", + "value": "Call SignatureRecover Asynchronous" + }, + { + "name": "call_signature_recover_synchronous", + "value": "Call SignatureRecover Synchronous" + }, + { + "name": "call_signature_verify_asynchronous", + "value": "Call SignatureVerify Asynchronous" + }, + { + "name": "call_signature_verify_synchronous", + "value": "Call SignatureVerify Synchronous" + }, + { + "name": "call_psssignatureseg_asynchronous", + "value": "Call PSSSignatureSeg Asynchronous" + }, + { + "name": "call_psssignatureseg_synchronous", + "value": "Call PSSSignatureSeg Synchronous" + }, + { + "name": "call_sm2_signature_asynchronous", + "value": "Call SM2Signature Asynchronous" + }, + { + "name": "call_sm2_signature_synchronous", + "value": "Call SM2Signature Synchronous" + } + ] +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/background.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/background.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/foreground.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/foreground.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/layered_image.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/startIcon.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/media/startIcon.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/backup_config.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/main_pages.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..3986e08d086d18949e662be9a2e265dce21ef2bc --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,17 @@ +{ + "src": [ + "pages/Index", + "pages/ecdsa_signature_verification/ecdsa_signature_verification_asynchronous", + "pages/ecdsa_signature_verification/ecdsa_signature_verification_synchronous", + "pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_asynchronous", + "pages/rsa_pkcs1_segment_signature/rsa_pkcs1_segment_signature_synchronous", + "pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_synchronous", + "pages/rsa_pkcs1_signature_restoration/rsa_pkcs1_signature_restoration_asynchronous", + "pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_asynchronous", + "pages/rsa_pkcs1_signature_validator/rsa_pkcs1_signature_validator_synchronous", + "pages/rsa_pss_signature_verification/rsa_pss_signature_verification_asynchronous", + "pages/rsa_pss_signature_verification/rsa_pss_signature_verification_synchronous", + "pages/sm2_signature_verification/sm2_signature_verification_asynchronous", + "pages/sm2_signature_verification/sm2_signature_verification_synchronous" + ] +} diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/dark/element/color.json b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/mock/mock-config.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * 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. + */ + +{ +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/Ability.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0f8ce9a2c012f8fe36114cef65216ef0b6254f41 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/List.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1174ad2d09e8241ad869327fe8a7e02de4ac2d87 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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 signingSignatureVerificationArkTsTest from './SigningSignatureVerificationArkTs.test'; + +export default function testsuite() { + abilityTest(); + signingSignatureVerificationArkTsTest(); +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..13f32fba0ac84f371741e370e6a9a6b029b53d17 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/ets/test/SigningSignatureVerificationArkTs.test.ets @@ -0,0 +1,259 @@ +/* + * 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 signingSignatureVerificationArkTsTest() { + describe('signingSignatureVerificationArkTsTest', () => { + /** + * 打开应用 + */ + 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'); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(异步) + */ + it('signingSignatureVerificationArkTsTest001', 0, async () => { + console.info('uitest: signingSignatureVerificationArkTsTest001 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_validator_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureVerify Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureVerifySuccess')); + console.info('uitest: signingSignatureVerificationArkTsTest001 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(同步) + */ + it('testSigningSignatureVerificationArkTsTest002', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest002 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_validator_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureVerify Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureVerifySuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest002 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(异步) + */ + it('testSigningSignatureVerificationArkTsTest003', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest003 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_restoration_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureRecover Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureRecoverSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest003 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(同步) + */ + it('testSigningSignatureVerificationArkTsTest004', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest004 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_signature_restoration_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureRecover Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureRecoverSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest004 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(异步) + */ + it('testSigningSignatureVerificationArkTsTest005', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest005 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_segment_signature_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureSeg Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest005 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(同步) + */ + it('testSigningSignatureVerificationArkTsTest006', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest006 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pkcs1_segment_signature_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SignatureSeg Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest006 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对签名验签(PSS模式)(异步) + */ + it('testSigningSignatureVerificationArkTsTest007', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest007 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pss_signature_verification_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call PSSSignatureSeg Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest007 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用RSA密钥对签名验签(PSS模式)(同步) + */ + it('testSigningSignatureVerificationArkTsTest008', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest008 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('rsa_pss_signature_verification_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call PSSSignatureSeg Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('PSSSignatureSegSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest008 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECDSA密钥对签名验签(异步) + */ + it('testSigningSignatureVerificationArkTsTest009', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest009 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ecdsa_signature_verification_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECDSASignature Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECDSASignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest009 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用ECDSA密钥对签名验签(同步) + */ + it('testSigningSignatureVerificationArkTsTest010', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest010 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('ecdsa_signature_verification_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call ECDSASignature Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('ECDSASignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest010 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2密钥对签名验签(异步) + */ + it('testSigningSignatureVerificationArkTsTest011', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest011 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm2_signature_verification_asynchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2Signature Asynchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2SignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest011 end'); + await driver.pressBack(); + }) + + /** + * 点击按钮,使用SM2密钥对签名验签(同步) + */ + it('testSigningSignatureVerificationArkTsTest012', 0, async () => { + console.info('uitest: testSigningSignatureVerificationArkTsTest012 begin'); + const driver = Driver.create(); + const button1 = await driver.findComponent(ON.text('sm2_signature_verification_synchronous')); + await driver.delayMs(1000); + await button1.click(); + await driver.delayMs(1000); + const button2 = await driver.findComponent(ON.text('Call SM2Signature Synchronous')); + await button2.click(); + await driver.delayMs(1000); + await driver.assertComponentExist(ON.text('SM2SignatureSuccess')); + console.info('uitest: testSigningSignatureVerificationArkTsTest012 end'); + }) + }) +} \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/module.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c3fd9dda3040d888d9d8b0b62bcb5d3b6fbeb614 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/List.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/LocalUnit.test.ets b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/hvigor/hvigor-config.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d584c19c247db9a7caee4b606bb931aa9279c637 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/hvigorfile.ts b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a5e543f190732c159beb574dfc9fa37bc94e156 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/oh-package.json5 b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e41bae026aab3b50d0abb42fece08ba43b4a772b --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/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/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..6ae3b3fcca5ba900ed20e4fa74ba0c98b5707441 --- /dev/null +++ b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/ohosTest.md @@ -0,0 +1,19 @@ +# 签名验签(ArkTS)测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| -------------------------------------------------------- | ------------ | ---- | -------------- | -------- | -------- | +| 拉起应用 | 设备正常运行 | | 成功拉起应用 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对(PKCS1模式)签名及签名恢复(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对分段签名验签(PKCS1模式)(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对签名验签(PSS模式)(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用RSA密钥对签名验签(PSS模式)(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDSA密钥对签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用ECDSA密钥对签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM2密钥对签名验签(异步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | +| 点击按钮,使用SM2密钥对签名验签(同步) | 成功拉起应用 | | 成功并输出日志 | 是 | Pass | \ No newline at end of file diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs1.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs1.png new file mode 100644 index 0000000000000000000000000000000000000000..4ad0c65328a63dd0113df7085179d6623145dc35 Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs1.png differ diff --git a/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs2.png b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs2.png new file mode 100644 index 0000000000000000000000000000000000000000..2eb2b1970e20eea5fb89c8fb84aba30356a2b82f Binary files /dev/null and b/CryptoArchitectureKit/SignatureVerification/SigningSignatureVerificationArkTs/screenshots/SigningSignatureVerificationArkTs2.png differ