diff --git a/LiteWearable/build-profile.json5 b/LiteWearable/build-profile.json5
new file mode 100644
index 0000000000000000000000000000000000000000..9952ea80b6c8fe477b3f226597fbf48a22525fad
--- /dev/null
+++ b/LiteWearable/build-profile.json5
@@ -0,0 +1,41 @@
+{
+ "app": {
+ "signingConfigs": [],
+ "products": [
+ {
+ "name": "default",
+ "signingConfig": "default",
+ "compatibleSdkVersion": "4.0.0(10)",
+ "runtimeOS": "HarmonyOS",
+ "buildOption": {
+ "strictMode": {
+ "caseSensitiveCheck": true,
+ "useNormalizedOHMUrl": false
+ }
+ }
+ }
+ ],
+ "buildModeSet": [
+ {
+ "name": "debug",
+ },
+ {
+ "name": "release"
+ }
+ ]
+ },
+ "modules": [
+ {
+ "name": "entry",
+ "srcPath": "./entry",
+ "targets": [
+ {
+ "name": "default",
+ "applyToProducts": [
+ "default"
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/build-profile.json5 b/LiteWearable/entry/build-profile.json5
new file mode 100644
index 0000000000000000000000000000000000000000..da8e97d0230f6ea16e63eb9d60c2d9d597bb191f
--- /dev/null
+++ b/LiteWearable/entry/build-profile.json5
@@ -0,0 +1,10 @@
+{
+ "apiType": "faMode",
+ "buildOption": {
+ },
+ "targets": [
+ {
+ "name": "default"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/hvigorfile.ts b/LiteWearable/entry/hvigorfile.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f5d6dbc4a300ccd28ff794472d6862d15f666427
--- /dev/null
+++ b/LiteWearable/entry/hvigorfile.ts
@@ -0,0 +1,6 @@
+import { legacyHapTasks } from '@ohos/hvigor-ohos-plugin';
+
+export default {
+ system: legacyHapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
+ plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
+}
diff --git a/LiteWearable/entry/oh-package.json5 b/LiteWearable/entry/oh-package.json5
new file mode 100644
index 0000000000000000000000000000000000000000..248c3b7541a589682a250f86a6d3ecf7414d2d6a
--- /dev/null
+++ b/LiteWearable/entry/oh-package.json5
@@ -0,0 +1,10 @@
+{
+ "name": "entry",
+ "version": "1.0.0",
+ "description": "Please describe the basic information.",
+ "main": "",
+ "author": "",
+ "license": "",
+ "dependencies": {}
+}
+
diff --git a/LiteWearable/entry/src/main/config.json b/LiteWearable/entry/src/main/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..c0b16ac154a22808f3ac5b585fd233571c21d073
--- /dev/null
+++ b/LiteWearable/entry/src/main/config.json
@@ -0,0 +1,78 @@
+// [Start 1]
+// [Start 2]
+{
+ // [StartExclude 2]
+ "app": {
+ "bundleName": "com.example.litewearable",
+ "vendor": "example",
+ "version": {
+ "code": 1000000,
+ "name": "1.0.0"
+ }
+ },
+ "deviceConfig": {},
+ // [EndExclude 2]
+ "module": {
+ "deviceType": [
+ "liteWearable"
+ ],
+ "distro": {
+ "deliveryWithInstall": true,
+ "moduleName": "entry",
+ "moduleType": "entry"
+ },
+ // [StartExclude 1]
+ "distroFilter": {
+ "screenShape": {
+ "policy": "include",
+ "value": [
+ "rect"
+ ]
+ },
+ "screenWindow": {
+ "policy": "include",
+ "value": [
+ "408*480"
+ ]
+ }
+ },
+ // [EndExclude 1]
+ // [StartExclude 2]
+ "abilities": [
+ {
+ "name": ".MainAbility",
+ "srcLanguage": "js",
+ "srcPath": "MainAbility",
+ "icon": "$media:icon",
+ "description": "$string:MainAbility_desc",
+ "label": "$string:MainAbility_label",
+ "type": "page"
+ }
+ ],
+ "js": [
+ {
+ "pages": [
+ "pages/index/index",
+ // [StartExclude 1]
+ "initpage/initpage",
+ "style1/style1",
+ "style2/style2",
+ "style3/style3",
+ "style4/style4",
+ "event/event",
+ "details/details",
+ "detail/detail",
+ "exit/exit",
+ "security/security",
+ "cryptoFramework/cryptoFramework",
+ "screenLock/screenLock"
+ // [EndExclude 1]
+ ],
+ "name": ".MainAbility"
+ }
+ ]
+ // [EndExclude 2]
+ }
+}
+// [End 1]
+// [End 2]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/app.js b/LiteWearable/entry/src/main/js/MainAbility/app.js
new file mode 100644
index 0000000000000000000000000000000000000000..326063fc7456533c3fc09658140972d70bc5cba7
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/app.js
@@ -0,0 +1,8 @@
+export default {
+ onCreate() {
+ console.info('Application onCreate');
+ },
+ onDestroy() {
+ console.info('Application onDestroy');
+ }
+};
diff --git a/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.css b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.hml b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.hml
new file mode 100644
index 0000000000000000000000000000000000000000..13ae33e07e3a90032d5fb5589183072449422c77
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.hml
@@ -0,0 +1,5 @@
+
+
+ {{ title }}
+
+
diff --git a/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js
new file mode 100644
index 0000000000000000000000000000000000000000..168cbfcffde083ade81f70de9e937a6cf12fc7fe
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js
@@ -0,0 +1,92 @@
+// [Start 1]
+import cryptoFramework from '@ohos.security.cryptoFramework';
+// [StartExclude 1]
+export default {
+ data: {
+ title: ""
+ },
+ onInit() {
+ this.title = "Hello World";
+ }
+};
+// [EndExclude 1]
+function stringToUint8Array(str) {
+ let arr = [];
+ for (let i = 0, j = str.length; i < j; ++i) {
+ arr.push(str.charCodeAt(i));
+ }
+ let tmpUint8Array = new Uint8Array(arr);
+ return tmpUint8Array;
+}
+
+function doMd() {
+ let mdAlgName = 'SHA256'; // 摘要算法名
+ let message = 'mdTestMessage'; // 待摘要的数据
+ let handle;
+ let mdResult;
+ let mdLen;
+ //指定摘要算法SHA256,生成摘要操作实例
+ try {
+ handle = cryptoFramework.createMd(mdAlgName);
+ } catch (error) {
+ console.error(`createMd error, code: ${error.code}, msg: ${error.message}`);
+ }
+ try {
+ // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制
+ handle?.updateSync({ data: stringToUint8Array(message) });
+ } catch (error) {
+ console.error(`updateSync error, code:+${error.code}, msg: ${error.message}`);
+ }
+ // 获取摘要计算结果。
+ try {
+ mdResult = handle?.digest();
+ } catch (error) {
+ console.error(`digest error, code: ${error.code}, msg: ${error.message}`);
+ }
+ console.info('Md result:' + mdResult?.data);
+ // 获取摘要计算长度,单位为字节
+ try {
+ mdLen = handle?.getMdLength();
+ } catch (error) {
+ console.error(`getMdLength error, code: ${error.code}, msg: ${error.message}`);
+ }
+ console.info(`md len: ${mdLen}`);
+}
+// [End 1]
+// [Start 2]
+function doRand() {
+ let rand;
+ let ret = true;
+ let randData
+ // 生成随机数操作实例
+ try {
+ rand = cryptoFramework.createRandom();
+ } catch (error) {
+ ret = false;
+ console.error(`createRandom error, code:+${error.code}, msg: ${error.message}`);
+ }
+ let len = 24; // Generate a 24-byte random number.
+ // (可选)调用Random.setSeed,为随机数生成池设置种子
+ let seed = new Uint8Array([1, 2, 3]);
+ try {
+ rand?.setSeed({ data: seed });
+ } catch (error) {
+ ret = false;
+ console.error(`setSeed error, code:+${error.code}, msg: ${error.message}`);
+ }
+
+ try {
+ //生成安全随机数
+ randData = rand?.generateRandomSync(len);
+ } catch (error) {
+ ret = false;
+ console.error(`generateRandomSync error, code:+${error.code}, msg: ${error.message}`);
+ }
+ if (ret) {
+ return randData?.data;
+ } else {
+ console.error(`doRand error`);
+ return 'doRand error';
+ }
+}
+// [End 2]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/detail/detail.css b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml
new file mode 100644
index 0000000000000000000000000000000000000000..720f9253d4b35cd83eaf94df05044f2ddee8b60e
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml
@@ -0,0 +1,9 @@
+
+
+
+ Hello World
+
+
+
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/detail/detail.js b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.js
new file mode 100644
index 0000000000000000000000000000000000000000..b89e21b7e998e39ff7a8fd278e4dfccfee9c930b
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.js
@@ -0,0 +1,12 @@
+// [Start 1]
+// index.js
+import router from '@ohos.router';
+
+export default {
+ clickAction() {
+ router.replaceUrl({
+ uri: 'pages/details/details'
+ });
+ }
+};
+// [End 1]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/details/details.css b/LiteWearable/entry/src/main/js/MainAbility/details/details.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/details/details.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/details/details.hml b/LiteWearable/entry/src/main/js/MainAbility/details/details.hml
new file mode 100644
index 0000000000000000000000000000000000000000..a393b645b934cf4699ad14981ce993d9b61650d3
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/details/details.hml
@@ -0,0 +1,9 @@
+
+
+
+ Details Page
+
+
+
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/details/details.js b/LiteWearable/entry/src/main/js/MainAbility/details/details.js
new file mode 100644
index 0000000000000000000000000000000000000000..549561a218711b04c5345ac3d810c2d339d65f03
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/details/details.js
@@ -0,0 +1,12 @@
+// [Start 1]
+// details.js
+import router from '@ohos.router';
+
+export default {
+ clickAction() {
+ router.replaceUrl({
+ uri: 'pages/index/index'
+ });
+ }
+};
+// [End 1]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/event/event.css b/LiteWearable/entry/src/main/js/MainAbility/event/event.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/event/event.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/event/event.hml b/LiteWearable/entry/src/main/js/MainAbility/event/event.hml
new file mode 100644
index 0000000000000000000000000000000000000000..40b3051af5f9234672f3b855dba270c789d27383
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/event/event.hml
@@ -0,0 +1,9 @@
+
+
+
+ Hello World
+
+
+
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/event/event.js b/LiteWearable/entry/src/main/js/MainAbility/event/event.js
new file mode 100644
index 0000000000000000000000000000000000000000..4417284f4cecb65e91a07af4d9a95738af6d938b
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/event/event.js
@@ -0,0 +1,13 @@
+// [Start 1]
+// index.js:
+export default {
+ data: {
+ fontSize: '30px',
+ fontColor: '#FF0000',
+ },
+ clickAction() {
+ this.fontSize = '38px';
+ this.fontColor = '#FFFFFF';
+ }
+};
+// [End 1]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/exit/exit.css b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml
new file mode 100644
index 0000000000000000000000000000000000000000..1ab84cfabc622fa6d24d924960fe75021739f6f2
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml
@@ -0,0 +1,9 @@
+
+
+
+ Hello {{ title }}
+
+
+
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/exit/exit.js b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.js
new file mode 100644
index 0000000000000000000000000000000000000000..955eca4135b757015f993ef2b95988f2108176ca
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.js
@@ -0,0 +1,22 @@
+// [Start 1]
+// index.js
+import router from '@ohos.router';
+// 导入app模块
+import app from '@system.app';
+
+export default {
+ data: {
+ title: 'World'
+ },
+ clickAction() {
+ router.replaceUrl({
+ uri: 'pages/details/details'
+ });
+ },
+ touchMove(e) { // swipe处理事件
+ if (e.direction == "right") { // 右滑退出
+ app.terminate();
+ }
+ }
+};
+// [End 1]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/i18n/en-US.json b/LiteWearable/entry/src/main/js/MainAbility/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/i18n/en-US.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "Hello",
+ "world": "World"
+ }
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/i18n/zh-CN.json b/LiteWearable/entry/src/main/js/MainAbility/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/i18n/zh-CN.json
@@ -0,0 +1,6 @@
+{
+ "strings": {
+ "hello": "您好",
+ "world": "世界"
+ }
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.css b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.css
new file mode 100644
index 0000000000000000000000000000000000000000..23be9f2820d7370ecb058793f1e25a01712ec46f
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.css
@@ -0,0 +1,15 @@
+.container {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 466px;
+ height: 466px;
+}
+.title {
+ font-size: 30px;
+ text-align: center;
+ width: 200px;
+ height: 100px;
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.hml b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.hml
new file mode 100644
index 0000000000000000000000000000000000000000..1e1e08a1ad3724ee5f7c44179cc10e01328cfa69
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.hml
@@ -0,0 +1,8 @@
+
+
+
+ Hello {{ title }}
+
+
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.js b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.js
new file mode 100644
index 0000000000000000000000000000000000000000..0dfc89acf2134f6e524998e981a9b5e7a6c7ca3d
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.js
@@ -0,0 +1,7 @@
+// [Start 1]
+export default {
+ data: {
+ title: 'World'
+ }
+}
+// [End 1]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.css b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..a75028a4780f2f5652297afac125500b61e51370
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.css
@@ -0,0 +1,31 @@
+.container {
+ width: 100%;/* 容器宽度设置为 100% */
+ height: 100%;/* 容器高度设置为 100% */
+ justify-content: center;
+ align-items: center;
+ flex-direction: column;
+ background-color: aquamarine;/* 设置背景色为碧绿色 */
+}
+
+.stackContainer {
+ width: 50%;
+ height: 50%;
+ background-color: white;
+}
+
+.button {
+ top: 10%;/* 设置y轴上距离父组件为父组件高度的10%位置 */
+ left: 10%;/* 设置x轴上距离父组件为父组件宽度的10%位置 */
+ width: 50%;
+ height: 30%;
+ font-size: 30px;
+ background-color: black;
+}
+
+.button2 {
+ width: 50%;
+ height: 20%;
+ font-size: 30px;
+ background-color: black;
+ margin-top: 2%;/* 父组件高度的2% */
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.hml b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..8b8fe70b6678c15d3390e9d42efadc0066899f2b
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.hml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.js b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..ab75d2c9902d12abdf9b7a59c0c75a628ef65947
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.js
@@ -0,0 +1,8 @@
+export default {
+ data: {
+ title: ''
+ },
+ onInit() {
+ this.title = this.$t('strings.world');
+ }
+};
diff --git a/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.css b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.hml b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.hml
new file mode 100644
index 0000000000000000000000000000000000000000..13ae33e07e3a90032d5fb5589183072449422c77
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.hml
@@ -0,0 +1,5 @@
+
+
+ {{ title }}
+
+
diff --git a/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js
new file mode 100644
index 0000000000000000000000000000000000000000..d2db0a6782cfa21424ab8ea66c96e51beec58660
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js
@@ -0,0 +1,58 @@
+// [Start 1]
+import screenLock from '@ohos.screenLock';
+
+// [StartExclude 1]
+export default {
+ data: {
+ title: ""
+ },
+ onInit() {
+ this.title = "Hello World";
+ }
+};
+
+// [EndExclude 1]
+
+function unlockScreen() {
+ let result;
+ screenLock.unlockScreen(function (err) {
+ if (err) {
+ result = `Failed to unlock the screen, Code: ${err.code}, ${err.message}`;
+ } else {
+ result = `call unlockScreen sucess`;
+ }
+ });
+
+ return result;
+}
+// [End 1]
+// [Start 2]
+function isScreenLocked() {
+ let isLocked = false;
+ let result;
+ screenLock.isScreenLocked(function (err, data) {
+ if (err) {
+ result = `call isScreenLocked erro ${err.message}`;
+ } else {
+ isLocked = data
+ result = `call isScreenLocked sucess islocked: ${isLocked}`
+ }
+ });
+ return result;
+}
+// [End 2]
+// [Start 3]
+function isSecureMode() {
+ let result;
+ let isSafety = false;
+ screenLock.isSecureMode(function (err, data) {
+ if (err) {
+ result = `call isSecureMode erro ${err.message}`;
+ } else {
+ isSafety = data
+ result = `call isSecureMode sucess isSafety ${isSafety}`;
+ }
+ });
+ return result;
+}
+// [End 3]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/DES.js b/LiteWearable/entry/src/main/js/MainAbility/security/DES.js
new file mode 100644
index 0000000000000000000000000000000000000000..ad55e0b6c7bac2c71d4736b13c1ee0045836031e
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/DES.js
@@ -0,0 +1,306 @@
+// [Start 1]
+import huks from '@ohos.security.huks';
+
+// [Start 2]
+// [Start 3]
+// 别名,用于区分生成的KEY
+const DES_CBC_64_KEY_ALIAS = 'DesCBC64KeyAlias';
+// [StartExclude 1]
+// 三段式句柄,用于连接三段式上下文
+let handle;
+let IV = '12345678';
+// 明文,加密前数据
+let plainText = 'DESAAAdffssghCBC5612345612345L64';
+// 密文,存放加密后数据
+let cipherText = '';
+// [EndExclude 1]
+
+// [StartExclude 2]
+// [StartExclude 3]
+// 配置生成密钥所需的Tag
+function getDesGenProperties() {
+ let properties = new Array();
+ let index = 0;
+ // DES算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_DES
+ };
+ // 密钥长度64
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: huks.HuksKeySize.HUKS_DES_KEY_SIZE_64
+ };
+ // 密钥用途,加密和解密
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
+ };
+
+ return properties;
+}
+
+// 生成密钥
+function generateDESKey() {
+ let huksInfo;
+ let options = { properties: getDesGenProperties() }
+ huks.generateKeyItem(DES_CBC_64_KEY_ALIAS, options, function (err, data) {
+ if (err) {
+ huksInfo = "generateKeyDES return code:" + err.code + " : " + err.message;
+ } else {
+ huksInfo = "The key has been generated:" + JSON.stringify(data);
+ }
+ });
+ return huksInfo;
+}
+// [EndExclude 2]
+// [End 1]
+function getDesCBCEncryptProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_DES
+ };
+
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: huks.HuksKeySize.HUKS_DES_KEY_SIZE_64
+ };
+
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
+ };
+
+ // 填充方式
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PADDING,
+ value: huks.HuksKeyPadding.HUKS_PADDING_NONE
+ };
+
+ // 分组方式
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
+ value: huks.HuksCipherMode.HUKS_MODE_CBC
+ };
+
+ // 分组加密偏移向量,更安全
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_IV,
+ value: stringToUint8Array(IV)
+ };
+
+ return properties;
+}
+
+function encryptDES() {
+ let huksInfo;
+ let ret = true;
+ let initOptions = {
+ properties: getDesCBCEncryptProperties(),
+ inData: new Uint8Array()
+ }
+
+ let updateOptions = {
+ properties: getDesCBCEncryptProperties(),
+ inData: stringToUint8Array(plainText.substring(0, 16))
+ }
+
+ let finishOptions = {
+ properties: getDesCBCEncryptProperties(),
+ inData: stringToUint8Array(plainText.substring(16, 32))
+ }
+
+ huks.initSession(DES_CBC_64_KEY_ALIAS, initOptions, function (initErr, initData) {
+ if (initErr) {
+ huksInfo = "encryptDES initSession return code:" + initErr.code + " : " + initErr.message;
+ ret = false;
+ huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "encryptDES init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ handle = initData.handle;
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ if (updateErr) {
+ huksInfo = "encryptDES updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ ret = false;
+ huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "encryptDES update abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // 密文接收
+ cipherText = uint8ArrayToString(updateData.outData);
+ huksInfo = cipherText
+ }
+ });
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ if (finishErr) {
+ ret = false;
+ huksInfo = "encryptDES finishSession return code:" + finishErr.code + " : " + finishErr.message;
+ huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "encryptDES finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // 密文接收
+ cipherText = cipherText + uint8ArrayToString(finishData.outData);
+ huksInfo = cipherText
+ }
+ });
+
+ return huksInfo;
+}
+// [EndExclude 3]
+function stringToUint8Array(str) {
+ let arr = [];
+ for (let i = 0, j = str.length; i < j; ++i) {
+ arr.push(str.charCodeAt(i));
+ }
+
+ return new Uint8Array(arr);
+}
+
+function uint8ArrayToString(fileData) {
+ let dataString = '';
+ for (let i = 0; i < fileData.length; i++) {
+ dataString += String.fromCharCode(fileData[i]);
+ }
+
+ return dataString;
+}
+// [End 2]
+
+function GetDesCBCDecryptProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_DES
+ };
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: huks.HuksKeySize.HUKS_DES_KEY_SIZE_64
+ };
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
+ };
+ // 填充方式
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PADDING,
+ value: huks.HuksKeyPadding.HUKS_PADDING_NONE
+ };
+ // 分组方式
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
+ value: huks.HuksCipherMode.HUKS_MODE_CBC
+ };
+ // 分组加密偏移向量,更安全
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_IV,
+ value: stringToUint8Array(IV)
+ };
+ return properties;
+}
+
+function decryptDES() {
+ let huksInfo;
+ let ret = true;
+ let outPlainText;
+ let initOptions = {
+ properties: GetDesCBCDecryptProperties(),
+ inData: new Uint8Array()
+ }
+ let updateOptions = {
+ properties: GetDesCBCDecryptProperties(),
+ inData: stringToUint8Array(cipherText.substring(0, 16))
+ }
+
+ let finishOptions = {
+ properties: GetDesCBCDecryptProperties(),
+ inData: stringToUint8Array(cipherText.substring(16, 32))
+ }
+
+ huks.initSession(DES_CBC_64_KEY_ALIAS, initOptions, function (initErr, initData) {
+ if (initErr) {
+ ret = false;
+ huksInfo = "decryptDES initSession return code:" + initErr.code + " : " + initErr.message;
+ huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "decryptDES initSession abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ handle = initData.handle;
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ if (updateErr) {
+ ret = false;
+ huksInfo = "decryptDES updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "decryptDES update abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // 明文接收
+ outPlainText = uint8ArrayToString(updateData.outData);
+ huksInfo = outPlainText;
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ if (finishErr) {
+ ret = false;
+ huksInfo = "decryptDES finishSession return code:" + finishErr.code + " : " + finishErr.message;
+ huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "decryptDES abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // 明文接收
+ outPlainText = outPlainText + uint8ArrayToString(finishData.outData);
+ huksInfo = outPlainText;
+ }
+ });
+
+ return huksInfo;
+}
+
+// [End 3]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/DesCBC64.js b/LiteWearable/entry/src/main/js/MainAbility/security/DesCBC64.js
new file mode 100644
index 0000000000000000000000000000000000000000..7e86aca71fa2773d8473f30aaea77063f9d2dd09
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/DesCBC64.js
@@ -0,0 +1,39 @@
+// [Start 1]
+// [Start 2]
+import huks from '@ohos.security.huks';
+
+const KEY_ALIAS = 'DesCBC64KeyAlias';
+// [StartExclude 2]
+function isKeyItemExist() {
+ let huksInfo;
+ let emptyOptions = {
+ properties: []
+ };
+
+ huks.isKeyItemExist(KEY_ALIAS, emptyOptions, function (err, data) {
+ if (data) {
+ huksInfo = "The key:" + KEY_ALIAS + " exists";
+ } else {
+ huksInfo = "The key doesn't exist errcode:" + err.code + " : " + err.message;
+ }
+ });
+
+ return huksInfo;
+}
+// [End 1]
+// [EndExclude 2]
+function deleteKeyProcess() {
+ let huksInfo;
+ let emptyOptions = {
+ properties: []
+ };
+ huks.deleteKeyItem(KEY_ALIAS, emptyOptions, function (err, data) {
+ if (err) {
+ huksInfo = "deleteKeyItem error return code:" + err.code + " : " + err.message;
+ } else {
+ huksInfo = "The key has been deleted";
+ }
+ })
+ return huksInfo;
+}
+// [End 2]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/HMAC.js b/LiteWearable/entry/src/main/js/MainAbility/security/HMAC.js
new file mode 100644
index 0000000000000000000000000000000000000000..e10810251c785c477a378e974da9a848e7edcbda
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/HMAC.js
@@ -0,0 +1,166 @@
+// [Start 1]
+// [Start 2]
+import huks from '@ohos.security.huks';
+
+// HMACKeyAlias 别名,用于区分生成的KEY
+const HMAC_KEY_ALIAS = 'HMACKeyAlias';
+// [StartExclude 1]
+// 明文,加密前数据
+let plainText = "HMACSAdffssghABC5612345612345192";
+// 密文,存放加密后数据
+let cipherText = '';
+// 操作句柄
+let handle;
+// [EndExclude 1]
+// [StartExclude 2]
+function getHMACGenProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_AES
+ };
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256
+ };
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_MAC
+ };
+ return properties;
+}
+
+function generateHMACKey() {
+ let huksInfo;
+ let options = {
+ properties: getHMACGenProperties()
+ }
+ huks.generateKeyItem(HMAC_KEY_ALIAS, options, function (err, data) {
+ if (err) {
+ huksInfo = "generateKeyHMAC return code:" + err.code + " : " + err.message;
+ } else {
+ huksInfo = "The key has been generated" + JSON.stringify(data);
+ }
+ });
+ return huksInfo;
+}
+// [End 1]
+// [EndExclude 2]
+function uint8ArrayToString(fileData) {
+ let dataString = '';
+ for (let i = 0; i < fileData.length; i++) {
+ dataString += String.fromCharCode(fileData[i]);
+ }
+ return dataString;
+}
+
+function stringToUnit8Array(str) {
+ let arr = [];
+ for (let i = 0, j = str.length; i < j; ++i) {
+ arr.push(str.charCodeAt(i));
+ }
+ return new Uint8Array(arr);
+}
+
+function getHMACProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_HMAC
+ };
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_256
+ };
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_MAC
+ };
+ // 摘要算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_DIGEST,
+ value: huks.HuksKeyPurpose.HUKS_DIGEST_SHA256
+ };
+ return properties;
+}
+
+function HMACProcess() {
+ let huksInfo;
+ let ret = true;
+ let initOptions = {
+ properties: getHMACProperties(),
+ inData: new Uint8Array()
+ }
+ let updateOptions = {
+ properties: getHMACProperties(),
+ inData: stringToUnit8Array(plainText.substring(0, 16))
+ }
+ let finishOptions = {
+ properties: getHMACProperties(),
+ inData: stringToUnit8Array(plainText.substring(16, 32))
+ }
+
+ huks.initSession(HMAC_KEY_ALIAS, initOptions, function (initErr, initData) {
+ if (initErr) {
+ huksInfo = "HMAC initSession return code:" + initErr.code + " : " + initErr.message;
+ ret = false;
+ huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "HMAC init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ handle = initData.handle;
+ }
+ });
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ if (updateErr) {
+ huksInfo = "HMAC updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ ret = false;
+ huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "HMAC update abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ if (finishErr) {
+ ret = false;
+ huksInfo = "encrypt HMAC finishSession return code:" + finishErr.code + " : " + finishErr.message;
+ huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "encrypt HMAC finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // HMAC密文接收
+ cipherText = uint8ArrayToString(finishData.outData);
+ }
+ });
+ if (ret == false) {
+ return huksInfo;
+ } else {
+ huksInfo = "success:" + cipherText;
+ }
+ return huksInfo;
+}
+// [End 2]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js b/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js
new file mode 100644
index 0000000000000000000000000000000000000000..a07743e5dcf7a1f9648498fb783c72b53a2904b1
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js
@@ -0,0 +1,92 @@
+// [Start 1]
+// [Start 2]
+import huks from '@ohos.security.huks';
+
+// [StartExclude 2]
+// 密钥材料
+let plainTextKey = new Uint8Array([
+ 0x1d, 0x2c, 0x3a, 0x4b, 0x5e, 0x6f, 0x7d, 0x8a, 0x9c, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf1, 0x23
+]);
+// [EndExclude 2]
+// 确定密钥别名
+const KEY_ALIAS = 'keyAlias';
+
+// [StartExclude 2]
+// 封装密钥属性集和密钥材料
+function getImportKeyProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_AES
+ };
+ // 秘钥长度 (128/192/256)
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: huks.HuksKeySize.HUKS_AES_KEY_SIZE_128
+ };
+ // 秘钥用途,生成秘钥时使用可以限制秘钥的使用权限 (AES一般用于加密、解密)
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
+ };
+ return properties
+}
+
+// 明文导入密钥
+function importKey() {
+ let huksInfo;
+ let ret = true;
+ let options = {
+ properties: getImportKeyProperties(),
+ inData: plainTextKey
+ }
+ huks.importKeyItem(KEY_ALIAS, options, function (initErr, initData) {
+ if (initErr) {
+ ret = false;
+ huksInfo = "import key:" + initErr.code + " : " + initErr.message;
+ huks.abortSession(initData.handle, options, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "import key init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ huksInfo = uint8ArrayToString(initData.outData);
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo + "导入失败";
+ }
+
+ return huksInfo + "导入成功";
+}
+// [End 1]
+// [EndExclude 2]
+function exportKeyProcess() {
+ let huksInfo;
+ let emptyOptions = {
+ properties: []
+ }
+
+ huks.exportKeyItem(KEY_ALIAS, emptyOptions, function (err, data) {
+ if (err) {
+ huksInfo = "exportKeyItem error return code:" + err.code + " : " + err.message;
+ } else {
+ huksInfo = uint8ArrayToString(data.outData);
+ }
+ })
+
+ return huksInfo;
+}
+// [End 2]
+
+function uint8ArrayToString(fileData) {
+ let dataString = '';
+ for (let i = 0; i < fileData.length; i++) {
+ dataString += String.fromCharCode(fileData[i]);
+ }
+
+ return dataString;
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/RSA.js b/LiteWearable/entry/src/main/js/MainAbility/security/RSA.js
new file mode 100644
index 0000000000000000000000000000000000000000..f25c8a7c7c062216dad8b8768c678a2084587bab
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/RSA.js
@@ -0,0 +1,286 @@
+// [Start 1]
+// [Start 3]
+import huks from '@ohos.security.huks';
+
+// [Start 2]
+// 别名,用于区分生成的KEY
+const RSA_KEY_ALIAS = 'RSAKeyAlias';
+// 自定义密钥长度必须在1024 -2048之间,且是8的倍数
+const HUKS_RSA_KEY_SIZE_1024 = 1024;
+// [StartExclude 1]
+// 明文,加密前数据
+let plainText = "RSASSAdffssghCBC5612345612345192";
+// 明文,加密前数据的长度
+let plainTextLen = 32;
+// 密文,存放加密后数据
+let cipherText = '';
+// 操作句柄
+let handle;
+
+// [EndExclude 1]
+// [StartExclude 2]
+// [StartExclude 3]
+function getRSAGenProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_RSA
+ };
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: HUKS_RSA_KEY_SIZE_1024
+ };
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT | huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
+ };
+ return properties;
+}
+
+function generateRSAKey() {
+ let huksInfo;
+ let options = { properties: getRSAGenProperties() };
+ huks.generateKeyItem(HUKS_RSA_KEY_SIZE_1024, options, function (err, data) {
+ if (err) {
+ huksInfo = "generateRSAKey return code:" + err.code + " : " + err.message;
+ } else {
+ huksInfo = "The key has been generated:" + JSON.stringify(data);
+ }
+ });
+ return huksInfo;
+}
+
+// [End 1]
+// [EndExclude 2]
+function getRSAEncryptProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_RSA
+ };
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: HUKS_RSA_KEY_SIZE_1024
+ };
+
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_ENCRYPT
+ };
+ // 密钥 PADDING方式
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PADDING,
+ value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5
+ };
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_DIGEST,
+ value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
+ }
+ return properties;
+}
+
+function encryptProcess() {
+ let ret = true;
+ let huksInfo;
+ let initOptions = {
+ properties: getRSAEncryptProperties(),
+ inData: new Uint8Array()
+ }
+ let updateOptions = {
+ properties: getRSAEncryptProperties(),
+ inData: stringToUint8Array(plainText.substring(0, plainTextLen / 2))
+ }
+ let finishOptions = {
+ properties: getRSAEncryptProperties(),
+ inData: stringToUint8Array(plainText.substring(plainTextLen / 2, plainTextLen))
+ }
+ huks.initSession(RSA_KEY_ALIAS, initOptions, function (initErr, initData) {
+ if (initErr) {
+ huksInfo = "encryptProcess initSession return code:" + initErr.code + " : " + initErr.message;
+ ret = false;
+ huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "encryptProcess init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ handle = initData.handle;
+ }
+ });
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ if (updateErr) {
+ huksInfo = "encryptProcess updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ ret = false;
+ huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "encryptProcess updateSession abortSession return code:" + abortErr.code + " : " +
+ abortErr.message;
+ }
+ });
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo;
+ }
+
+ huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ if (finishErr) {
+ ret = false;
+ huksInfo = "encryptProcess finishSession return code:" + finishErr.code + " : " + finishErr.message;
+ huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "encryptProcess finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // 密文接收
+ cipherText = uint8ArrayToString(finishData.outData);
+ huksInfo = cipherText;
+ }
+ });
+ return huksInfo;
+}
+
+function uint8ArrayToString(fileData) {
+ let dataString = '';
+ for (let i = 0; i < fileData.length; i++) {
+ dataString += String.fromCharCode(fileData[i]);
+ }
+ return dataString;
+}
+
+function stringToUint8Array(str) {
+ let arr = [];
+ for (let i = 0, j = str.length; i < j; ++i) {
+ arr.push(str.charCodeAt(i));
+ }
+ return new Uint8Array(arr);
+}
+
+// [End 2]
+// [EndExclude 3]
+function getRSADecryptProperties() {
+ let properties = new Array();
+ let index = 0;
+ // 算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
+ value: huks.HuksKeyAlg.HUKS_ALG_RSA
+ };
+ // 密钥长度
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_KEY_SIZE,
+ value: HUKS_RSA_KEY_SIZE_1024
+ };
+
+ // 密钥用途
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PURPOSE,
+ value: huks.HuksKeyPurpose.HUKS_KEY_PURPOSE_DECRYPT
+ };
+
+ // 密钥 PADDING方式
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_PADDING,
+ value: huks.HuksKeyPadding.HUKS_PADDING_PKCS1_V1_5
+ };
+
+ // 摘要算法
+ properties[index++] = {
+ tag: huks.HuksTag.HUKS_TAG_DIGEST,
+ value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
+ }
+
+ return properties;
+}
+
+function decryptProcess() {
+ // 加密密文长度
+ let len = HUKS_RSA_KEY_SIZE_1024 / 8;
+ let ret = true;
+ let outPlainText;
+ let huksInfo;
+ let initOptions = {
+ properties: getRSADecryptProperties(),
+ inData: new Uint8Array()
+ }
+ let updateOptions = {
+ properties: getRSADecryptProperties(),
+ inData: stringToUint8Array(cipherText.substring(0, len / 2))
+ }
+ let finishOptions = {
+ properties: getRSADecryptProperties(),
+ inData: stringToUint8Array(cipherText.substring(len / 2, len))
+ }
+ huks.initSession(RSA_KEY_ALIAS, initOptions, function (initErr, initData) {
+ if (initErr) {
+ huksInfo = "decryptProcess initSession return code:" + initErr.code + " : " + initErr.message;
+ ret = false;
+ huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "decryptProcess init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ handle = initData.handle;
+ }
+ });
+ if (ret == false) {
+ return huksInfo;
+ }
+ huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ if (updateErr) {
+ huksInfo = "decryptProcess updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ ret = false;
+ huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo = "decryptProcess updateSession abortSession return code:" + abortErr.code + " : " +
+ abortErr.message;
+ }
+ });
+ }
+ });
+
+ if (ret == false) {
+ return huksInfo;
+ }
+ huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ if (finishErr) {
+ ret = false;
+ huksInfo = "decryptProcess finishSession return code:" + finishErr.code + " : " + finishErr.message;
+ huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ if (abortErr) {
+ huksInfo =
+ "decryptProcess finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ }
+ });
+ } else {
+ // 明文接收
+ outPlainText = uint8ArrayToString(finishData.outData);
+ }
+ });
+ if (ret == false) {
+ return huksInfo;
+ } else {
+ huksInfo = "Success:" + outPlainText;
+ }
+ return huksInfo;
+}
+
+// [End 3]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/security.css b/LiteWearable/entry/src/main/js/MainAbility/security/security.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/security.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/security.hml b/LiteWearable/entry/src/main/js/MainAbility/security/security.hml
new file mode 100644
index 0000000000000000000000000000000000000000..13ae33e07e3a90032d5fb5589183072449422c77
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/security.hml
@@ -0,0 +1,5 @@
+
+
+ {{ title }}
+
+
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/security.js b/LiteWearable/entry/src/main/js/MainAbility/security/security.js
new file mode 100644
index 0000000000000000000000000000000000000000..c683063934277cfa65caf96b78ad7250554ca995
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/security.js
@@ -0,0 +1,8 @@
+export default {
+ data: {
+ title: ""
+ },
+ onInit() {
+ this.title = "Hello World";
+ }
+};
diff --git a/LiteWearable/entry/src/main/js/MainAbility/style1/style1.css b/LiteWearable/entry/src/main/js/MainAbility/style1/style1.css
new file mode 100644
index 0000000000000000000000000000000000000000..269400ee202d398dd727d6ef74800d0ee5961945
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/style1/style1.css
@@ -0,0 +1,18 @@
+.container {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ height: 100%;
+}
+
+.title {
+ font-size: 38px;
+ text-align: center;
+ width: 100%;
+ height: 40%;
+ margin: 10px;
+}
diff --git a/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml b/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml
new file mode 100644
index 0000000000000000000000000000000000000000..7696cdf44addd9ed529acac2a77c0c29efb36ec6
--- /dev/null
+++ b/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml
@@ -0,0 +1,9 @@
+
+
+
+
+ Hello World
+
+
+
+
+
+
+ Hello World
+
+
+
+
+
+
+
+ Hello World
+
+
+
+
+
+ Hello World
+
+
+