From ea96323b4ec04aad2dddf0bdf8d5f528685005a1 Mon Sep 17 00:00:00 2001
From: lon9 <815882449@qq.com>
Date: Wed, 2 Apr 2025 14:37:29 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E8=BD=BB=E9=87=8F=E7=BA=A7=E6=99=BA?=
=?UTF-8?q?=E8=83=BD=E7=A9=BF=E6=88=B4=E5=BC=80=E5=8F=91=E6=8C=87=E5=AF=BC?=
=?UTF-8?q?=E5=90=8C=E6=BA=90=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
LiteWearable/build-profile.json5 | 16 +++-
LiteWearable/entry/src/main/config.json | 16 +---
.../cryptoFramework/cryptoFramework.js | 12 +--
.../src/main/js/MainAbility/detail/detail.hml | 4 +-
.../src/main/js/MainAbility/detail/detail.js | 4 +-
.../main/js/MainAbility/details/details.hml | 4 +-
.../main/js/MainAbility/details/details.js | 4 +-
.../src/main/js/MainAbility/event/event.hml | 4 +-
.../src/main/js/MainAbility/event/event.js | 4 +-
.../src/main/js/MainAbility/exit/exit.hml | 4 +-
.../src/main/js/MainAbility/exit/exit.js | 6 +-
.../main/js/MainAbility/initpage/initpage.hml | 4 +-
.../main/js/MainAbility/initpage/initpage.js | 4 +-
.../main/js/MainAbility/pages/index/index.hml | 4 +-
.../js/MainAbility/screenLock/screenLock.js | 22 ++---
.../src/main/js/MainAbility/security/DES.js | 86 ++++++++---------
.../main/js/MainAbility/security/DesCBC64.js | 24 ++---
.../src/main/js/MainAbility/security/HMAC.js | 56 +++++------
.../main/js/MainAbility/security/KeyAlias.js | 50 +++++-----
.../src/main/js/MainAbility/security/RSA.js | 92 +++++++++----------
.../main/js/MainAbility/security/security.js | 4 +-
.../src/main/js/MainAbility/style1/style1.hml | 4 +-
.../src/main/js/MainAbility/style1/style1.js | 4 +-
.../src/main/js/MainAbility/style2/style2.hml | 4 +-
.../src/main/js/MainAbility/style2/style2.js | 4 +-
.../src/main/js/MainAbility/style3/style3.hml | 4 +-
.../src/main/js/MainAbility/style3/style3.js | 4 +-
.../src/main/js/MainAbility/style4/style4.hml | 4 +-
.../src/main/js/MainAbility/style4/style4.js | 4 +-
29 files changed, 229 insertions(+), 227 deletions(-)
diff --git a/LiteWearable/build-profile.json5 b/LiteWearable/build-profile.json5
index 9952ea80..1e0c4fde 100644
--- a/LiteWearable/build-profile.json5
+++ b/LiteWearable/build-profile.json5
@@ -1,6 +1,20 @@
{
"app": {
- "signingConfigs": [],
+ "signingConfigs": [
+ {
+ "name": "default",
+ "type": "HarmonyOS",
+ "material": {
+ "storePassword": "000000191DBFA24259CBB4CBF4C914AC7AF071A6103A7AD4F492EFEEE35B129792763C6B45819A6692",
+ "certpath": "E:/documents/key/蓝区运动表证书.cer",
+ "keyAlias": "sportwatch",
+ "keyPassword": "00000019C31EB9DA1E001CD1EAF21323D77CEE45DB42688C835E0B875EEFCF71FD2CCF336001E14AD7",
+ "profile": "E:/documents/key/蓝区调试profileDebug.p7b",
+ "signAlg": "SHA256withECDSA",
+ "storeFile": "E:/documents/key/sportwatch.p12"
+ }
+ }
+ ],
"products": [
{
"name": "default",
diff --git a/LiteWearable/entry/src/main/config.json b/LiteWearable/entry/src/main/config.json
index c0b16ac1..7a53ffd8 100644
--- a/LiteWearable/entry/src/main/config.json
+++ b/LiteWearable/entry/src/main/config.json
@@ -1,9 +1,6 @@
-// [Start 1]
-// [Start 2]
{
- // [StartExclude 2]
"app": {
- "bundleName": "com.example.litewearable",
+ "bundleName": "com.example.sportwatchdemo",
"vendor": "example",
"version": {
"code": 1000000,
@@ -11,7 +8,6 @@
}
},
"deviceConfig": {},
- // [EndExclude 2]
"module": {
"deviceType": [
"liteWearable"
@@ -21,7 +17,6 @@
"moduleName": "entry",
"moduleType": "entry"
},
- // [StartExclude 1]
"distroFilter": {
"screenShape": {
"policy": "include",
@@ -36,8 +31,6 @@
]
}
},
- // [EndExclude 1]
- // [StartExclude 2]
"abilities": [
{
"name": ".MainAbility",
@@ -53,7 +46,6 @@
{
"pages": [
"pages/index/index",
- // [StartExclude 1]
"initpage/initpage",
"style1/style1",
"style2/style2",
@@ -66,13 +58,9 @@
"security/security",
"cryptoFramework/cryptoFramework",
"screenLock/screenLock"
- // [EndExclude 1]
],
"name": ".MainAbility"
}
]
- // [EndExclude 2]
}
-}
-// [End 1]
-// [End 2]
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js
index 168cbfcf..a15bc859 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/cryptoFramework/cryptoFramework.js
@@ -1,6 +1,6 @@
-// [Start 1]
+// [Start do_md]
import cryptoFramework from '@ohos.security.cryptoFramework';
-// [StartExclude 1]
+// [StartExclude do_md]
export default {
data: {
title: ""
@@ -9,7 +9,7 @@ export default {
this.title = "Hello World";
}
};
-// [EndExclude 1]
+// [EndExclude do_md]
function stringToUint8Array(str) {
let arr = [];
for (let i = 0, j = str.length; i < j; ++i) {
@@ -52,8 +52,8 @@ function doMd() {
}
console.info(`md len: ${mdLen}`);
}
-// [End 1]
-// [Start 2]
+// [End do_md]
+// [Start do_rand]
function doRand() {
let rand;
let ret = true;
@@ -89,4 +89,4 @@ function doRand() {
return 'doRand error';
}
}
-// [End 2]
\ No newline at end of file
+// [End do_rand]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml
index 720f9253..f3a9eb9f 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.hml
@@ -1,4 +1,4 @@
-
@@ -6,4 +6,4 @@
-
\ No newline at end of file
+
\ 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
index b89e21b7..41406877 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/detail/detail.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/detail/detail.js
@@ -1,4 +1,4 @@
-// [Start 1]
+// [Start detail_js]
// index.js
import router from '@ohos.router';
@@ -9,4 +9,4 @@ export default {
});
}
};
-// [End 1]
\ No newline at end of file
+// [End detail_js]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/details/details.hml b/LiteWearable/entry/src/main/js/MainAbility/details/details.hml
index a393b645..43daa6f9 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/details/details.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/details/details.hml
@@ -1,4 +1,4 @@
-
@@ -6,4 +6,4 @@
-
\ No newline at end of file
+
\ 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
index 549561a2..8cce889e 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/details/details.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/details/details.js
@@ -1,4 +1,4 @@
-// [Start 1]
+// [Start details_js]
// details.js
import router from '@ohos.router';
@@ -9,4 +9,4 @@ export default {
});
}
};
-// [End 1]
\ No newline at end of file
+// [End details_js]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/event/event.hml b/LiteWearable/entry/src/main/js/MainAbility/event/event.hml
index 40b3051a..2d1641b0 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/event/event.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/event/event.hml
@@ -1,4 +1,4 @@
-
@@ -6,4 +6,4 @@
-
\ No newline at end of file
+
\ 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
index 4417284f..239d9529 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/event/event.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/event/event.js
@@ -1,4 +1,4 @@
-// [Start 1]
+// [Start event_js]
// index.js:
export default {
data: {
@@ -10,4 +10,4 @@ export default {
this.fontColor = '#FFFFFF';
}
};
-// [End 1]
\ No newline at end of file
+// [End event_js]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml
index 1ab84cfa..9b0a820d 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.hml
@@ -1,4 +1,4 @@
-
@@ -6,4 +6,4 @@
-
\ No newline at end of file
+
\ 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
index 955eca41..8d9cfc72 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/exit/exit.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/exit/exit.js
@@ -1,4 +1,4 @@
-// [Start 1]
+// [Start exit_js]
// index.js
import router from '@ohos.router';
// 导入app模块
@@ -14,9 +14,9 @@ export default {
});
},
touchMove(e) { // swipe处理事件
- if (e.direction == "right") { // 右滑退出
+ if (e.direction == 'right') { // 右滑退出
app.terminate();
}
}
};
-// [End 1]
\ No newline at end of file
+// [End exit_js]
\ 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
index 1e1e08a1..0acac82f 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.hml
@@ -1,8 +1,8 @@
-
Hello {{ title }}
-
\ No newline at end of file
+
\ 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
index 0dfc89ac..e802688a 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/initpage/initpage.js
@@ -1,7 +1,7 @@
-// [Start 1]
+// [Start init_page_js]
export default {
data: {
title: 'World'
}
}
-// [End 1]
\ No newline at end of file
+// [End init_page_js]
\ 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
index 8b8fe70b..4999668e 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/pages/index/index.hml
@@ -1,4 +1,4 @@
-
@@ -6,4 +6,4 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js
index d2db0a67..119a8bb9 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/screenLock/screenLock.js
@@ -1,7 +1,7 @@
-// [Start 1]
+// [Start unlock_screen]
import screenLock from '@ohos.screenLock';
-// [StartExclude 1]
+// [StartExclude unlock_screen]
export default {
data: {
title: ""
@@ -11,11 +11,11 @@ export default {
}
};
-// [EndExclude 1]
+// [EndExclude unlock_screen]
function unlockScreen() {
let result;
- screenLock.unlockScreen(function (err) {
+ screenLock.unlockScreen((err) => {
if (err) {
result = `Failed to unlock the screen, Code: ${err.code}, ${err.message}`;
} else {
@@ -25,12 +25,12 @@ function unlockScreen() {
return result;
}
-// [End 1]
-// [Start 2]
+// [End unlock_screen]
+// [Start is_screen_locked]
function isScreenLocked() {
let isLocked = false;
let result;
- screenLock.isScreenLocked(function (err, data) {
+ screenLock.isScreenLocked((err, data) => {
if (err) {
result = `call isScreenLocked erro ${err.message}`;
} else {
@@ -40,12 +40,12 @@ function isScreenLocked() {
});
return result;
}
-// [End 2]
-// [Start 3]
+// [End is_screen_locked]
+// [Start is_secure_mode]
function isSecureMode() {
let result;
let isSafety = false;
- screenLock.isSecureMode(function (err, data) {
+ screenLock.isSecureMode((err, data) => {
if (err) {
result = `call isSecureMode erro ${err.message}`;
} else {
@@ -55,4 +55,4 @@ function isSecureMode() {
});
return result;
}
-// [End 3]
\ No newline at end of file
+// [End is_secure_mode]
\ 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
index ad55e0b6..efa05f9a 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/security/DES.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/DES.js
@@ -1,11 +1,11 @@
-// [Start 1]
+// [Start des_generate]
import huks from '@ohos.security.huks';
-// [Start 2]
-// [Start 3]
+// [Start des_encrypt]
+// [Start des_decrypt]
// 别名,用于区分生成的KEY
const DES_CBC_64_KEY_ALIAS = 'DesCBC64KeyAlias';
-// [StartExclude 1]
+// [StartExclude des_generate]
// 三段式句柄,用于连接三段式上下文
let handle;
let IV = '12345678';
@@ -13,10 +13,10 @@ let IV = '12345678';
let plainText = 'DESAAAdffssghCBC5612345612345L64';
// 密文,存放加密后数据
let cipherText = '';
-// [EndExclude 1]
+// [EndExclude des_generate]
-// [StartExclude 2]
-// [StartExclude 3]
+// [StartExclude des_encrypt]
+// [StartExclude des_decrypt]
// 配置生成密钥所需的Tag
function getDesGenProperties() {
let properties = new Array();
@@ -44,17 +44,17 @@ function getDesGenProperties() {
function generateDESKey() {
let huksInfo;
let options = { properties: getDesGenProperties() }
- huks.generateKeyItem(DES_CBC_64_KEY_ALIAS, options, function (err, data) {
+ huks.generateKeyItem(DES_CBC_64_KEY_ALIAS, options, (err, data) => {
if (err) {
- huksInfo = "generateKeyDES return code:" + err.code + " : " + err.message;
+ huksInfo = 'generateKeyDES return code:' + err.code + ' : ' + err.message;
} else {
- huksInfo = "The key has been generated:" + JSON.stringify(data);
+ huksInfo = 'The key has been generated:' + JSON.stringify(data);
}
});
return huksInfo;
}
-// [EndExclude 2]
-// [End 1]
+// [EndExclude des_encrypt]
+// [End des_generate]
function getDesCBCEncryptProperties() {
let properties = new Array();
let index = 0;
@@ -115,13 +115,13 @@ function encryptDES() {
inData: stringToUint8Array(plainText.substring(16, 32))
}
- huks.initSession(DES_CBC_64_KEY_ALIAS, initOptions, function (initErr, initData) {
+ huks.initSession(DES_CBC_64_KEY_ALIAS, initOptions, (initErr, initData) => {
if (initErr) {
- huksInfo = "encryptDES initSession return code:" + initErr.code + " : " + initErr.message;
+ huksInfo = 'encryptDES initSession return code:' + initErr.code + ' : ' + initErr.message;
ret = false;
- huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ huks.abortSession(initData.handle, initOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "encryptDES init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'encryptDES init abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -129,17 +129,17 @@ function encryptDES() {
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ huks.updateSession(handle, updateOptions, (updateErr, updateData) => {
if (updateErr) {
- huksInfo = "encryptDES updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ huksInfo = 'encryptDES updateSession return code:' + updateErr.code + ' : ' + updateErr.message;
ret = false;
- huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ huks.abortSession(handle, updateOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "encryptDES update abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'encryptDES update abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -148,18 +148,18 @@ function encryptDES() {
huksInfo = cipherText
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ huks.finishSession(handle, finishOptions, (finishErr, finishData) => {
if (finishErr) {
ret = false;
- huksInfo = "encryptDES finishSession return code:" + finishErr.code + " : " + finishErr.message;
- huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ huksInfo = 'encryptDES finishSession return code:' + finishErr.code + ' : ' + finishErr.message;
+ huks.abortSession(handle, finishOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "encryptDES finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'encryptDES finish abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -171,7 +171,7 @@ function encryptDES() {
return huksInfo;
}
-// [EndExclude 3]
+// [EndExclude des_decrypt]
function stringToUint8Array(str) {
let arr = [];
for (let i = 0, j = str.length; i < j; ++i) {
@@ -189,7 +189,7 @@ function uint8ArrayToString(fileData) {
return dataString;
}
-// [End 2]
+// [End des_encrypt]
function GetDesCBCDecryptProperties() {
let properties = new Array();
@@ -245,14 +245,14 @@ function decryptDES() {
inData: stringToUint8Array(cipherText.substring(16, 32))
}
- huks.initSession(DES_CBC_64_KEY_ALIAS, initOptions, function (initErr, initData) {
+ huks.initSession(DES_CBC_64_KEY_ALIAS, initOptions, (initErr, initData) => {
if (initErr) {
ret = false;
- huksInfo = "decryptDES initSession return code:" + initErr.code + " : " + initErr.message;
- huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ huksInfo = 'decryptDES initSession return code:' + initErr.code + ' : ' + initErr.message;
+ huks.abortSession(initData.handle, initOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "decryptDES initSession abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'decryptDES initSession abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -260,17 +260,17 @@ function decryptDES() {
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ huks.updateSession(handle, updateOptions, (updateErr, updateData) => {
if (updateErr) {
ret = false;
- huksInfo = "decryptDES updateSession return code:" + updateErr.code + " : " + updateErr.message;
- huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ huksInfo = 'decryptDES updateSession return code:' + updateErr.code + ' : ' + updateErr.message;
+ huks.abortSession(handle, updateOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "decryptDES update abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'decryptDES update abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -280,17 +280,17 @@ function decryptDES() {
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ huks.finishSession(handle, finishOptions, (finishErr, finishData) => {
if (finishErr) {
ret = false;
- huksInfo = "decryptDES finishSession return code:" + finishErr.code + " : " + finishErr.message;
- huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ huksInfo = 'decryptDES finishSession return code:' + finishErr.code + ' : ' + finishErr.message;
+ huks.abortSession(handle, finishOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "decryptDES abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'decryptDES abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -303,4 +303,4 @@ function decryptDES() {
return huksInfo;
}
-// [End 3]
\ No newline at end of file
+// [End des_decrypt]
\ 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
index 7e86aca7..39f36e76 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/security/DesCBC64.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/DesCBC64.js
@@ -1,39 +1,39 @@
-// [Start 1]
-// [Start 2]
+// [Start is_key_item_exist]
+// [Start delete_key_process]
import huks from '@ohos.security.huks';
const KEY_ALIAS = 'DesCBC64KeyAlias';
-// [StartExclude 2]
+// [StartExclude delete_key_process]
function isKeyItemExist() {
let huksInfo;
let emptyOptions = {
properties: []
};
- huks.isKeyItemExist(KEY_ALIAS, emptyOptions, function (err, data) {
+ huks.isKeyItemExist(KEY_ALIAS, emptyOptions, (err, data) => {
if (data) {
- huksInfo = "The key:" + KEY_ALIAS + " exists";
+ huksInfo = 'The key:' + KEY_ALIAS + ' exists';
} else {
- huksInfo = "The key doesn't exist errcode:" + err.code + " : " + err.message;
+ huksInfo = 'The key doesn\'t exist errcode:' + err.code + ' : ' + err.message;
}
});
return huksInfo;
}
-// [End 1]
-// [EndExclude 2]
+// [End is_key_item_exist]
+// [EndExclude delete_key_process]
function deleteKeyProcess() {
let huksInfo;
let emptyOptions = {
properties: []
};
- huks.deleteKeyItem(KEY_ALIAS, emptyOptions, function (err, data) {
+ huks.deleteKeyItem(KEY_ALIAS, emptyOptions, (err, data) => {
if (err) {
- huksInfo = "deleteKeyItem error return code:" + err.code + " : " + err.message;
+ huksInfo = 'deleteKeyItem error return code:' + err.code + ' : ' + err.message;
} else {
- huksInfo = "The key has been deleted";
+ huksInfo = 'The key has been deleted';
}
})
return huksInfo;
}
-// [End 2]
\ No newline at end of file
+// [End delete_key_process]
\ 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
index e1081025..c3048f3c 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/security/HMAC.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/HMAC.js
@@ -1,18 +1,18 @@
-// [Start 1]
-// [Start 2]
+// [Start hmac_generate]
+// [Start hmac_process]
import huks from '@ohos.security.huks';
// HMACKeyAlias 别名,用于区分生成的KEY
const HMAC_KEY_ALIAS = 'HMACKeyAlias';
-// [StartExclude 1]
+// [StartExclude hmac_generate]
// 明文,加密前数据
-let plainText = "HMACSAdffssghABC5612345612345192";
+let plainText = 'HMACSAdffssghABC5612345612345192';
// 密文,存放加密后数据
let cipherText = '';
// 操作句柄
let handle;
-// [EndExclude 1]
-// [StartExclude 2]
+// [EndExclude hmac_generate]
+// [StartExclude hmac_process]
function getHMACGenProperties() {
let properties = new Array();
let index = 0;
@@ -39,17 +39,17 @@ function generateHMACKey() {
let options = {
properties: getHMACGenProperties()
}
- huks.generateKeyItem(HMAC_KEY_ALIAS, options, function (err, data) {
+ huks.generateKeyItem(HMAC_KEY_ALIAS, options, (err, data) => {
if (err) {
- huksInfo = "generateKeyHMAC return code:" + err.code + " : " + err.message;
+ huksInfo = 'generateKeyHMAC return code:' + err.code + ' : ' + err.message;
} else {
- huksInfo = "The key has been generated" + JSON.stringify(data);
+ huksInfo = 'The key has been generated' + JSON.stringify(data);
}
});
return huksInfo;
}
-// [End 1]
-// [EndExclude 2]
+// [End hmac_generate]
+// [EndExclude hmac_process]
function uint8ArrayToString(fileData) {
let dataString = '';
for (let i = 0; i < fileData.length; i++) {
@@ -108,47 +108,47 @@ function HMACProcess() {
inData: stringToUnit8Array(plainText.substring(16, 32))
}
- huks.initSession(HMAC_KEY_ALIAS, initOptions, function (initErr, initData) {
+ huks.initSession(HMAC_KEY_ALIAS, initOptions, (initErr, initData) => {
if (initErr) {
- huksInfo = "HMAC initSession return code:" + initErr.code + " : " + initErr.message;
+ huksInfo = 'HMAC initSession return code:' + initErr.code + ' : ' + initErr.message;
ret = false;
- huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ huks.abortSession(initData.handle, initOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "HMAC init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'HMAC init abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
handle = initData.handle;
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ huks.updateSession(handle, updateOptions, (updateErr, updateData) => {
if (updateErr) {
- huksInfo = "HMAC updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ huksInfo = 'HMAC updateSession return code:' + updateErr.code + ' : ' + updateErr.message;
ret = false;
- huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ huks.abortSession(handle, updateOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "HMAC update abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'HMAC update abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ huks.finishSession(handle, finishOptions, (finishErr, finishData) => {
if (finishErr) {
ret = false;
- huksInfo = "encrypt HMAC finishSession return code:" + finishErr.code + " : " + finishErr.message;
- huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ huksInfo = 'encrypt HMAC finishSession return code:' + finishErr.code + ' : ' + finishErr.message;
+ huks.abortSession(handle, finishOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "encrypt HMAC finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'encrypt HMAC finish abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -156,11 +156,11 @@ function HMACProcess() {
cipherText = uint8ArrayToString(finishData.outData);
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
} else {
- huksInfo = "success:" + cipherText;
+ huksInfo = 'success:' + cipherText;
}
return huksInfo;
}
-// [End 2]
\ No newline at end of file
+// [End hmac_process]
\ 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
index a07743e5..9c4519c1 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js
@@ -1,8 +1,8 @@
-// [Start 1]
-// [Start 2]
+// [Start import_key]
+// [Start export_key]
import huks from '@ohos.security.huks';
-// [StartExclude 2]
+// [StartExclude export_key]
// 密钥材料
let plainTextKey = new Uint8Array([
0x1d, 0x2c, 0x3a, 0x4b, 0x5e, 0x6f, 0x7d, 0x8a, 0x9c, 0xab, 0xbc, 0xcd, 0xde, 0xef, 0xf1, 0x23
@@ -11,7 +11,7 @@ let plainTextKey = new Uint8Array([
// 确定密钥别名
const KEY_ALIAS = 'keyAlias';
-// [StartExclude 2]
+// [StartExclude export_key]
// 封装密钥属性集和密钥材料
function getImportKeyProperties() {
let properties = new Array();
@@ -42,13 +42,13 @@ function importKey() {
properties: getImportKeyProperties(),
inData: plainTextKey
}
- huks.importKeyItem(KEY_ALIAS, options, function (initErr, initData) {
+ huks.importKeyItem(KEY_ALIAS, options, (initErr, initData) => {
if (initErr) {
ret = false;
- huksInfo = "import key:" + initErr.code + " : " + initErr.message;
- huks.abortSession(initData.handle, options, function (abortErr, abortData) {
+ huksInfo = 'import key:' + initErr.code + ' : ' + initErr.message;
+ huks.abortSession(initData.handle, options, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "import key init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ huksInfo = 'import key init abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -56,23 +56,32 @@ function importKey() {
}
});
- if (ret == false) {
- return huksInfo + "导入失败";
+ if (!ret) {
+ return huksInfo + ' import failed';
}
- return huksInfo + "导入成功";
+ return huksInfo + ' import succeed';
}
-// [End 1]
-// [EndExclude 2]
+
+function uint8ArrayToString(fileData) {
+ let dataString = '';
+ for (let i = 0; i < fileData.length; i++) {
+ dataString += String.fromCharCode(fileData[i]);
+ }
+
+ return dataString;
+}
+// [End import_key]
+// [EndExclude export_key]
function exportKeyProcess() {
let huksInfo;
let emptyOptions = {
properties: []
}
- huks.exportKeyItem(KEY_ALIAS, emptyOptions, function (err, data) {
+ huks.exportKeyItem(KEY_ALIAS, emptyOptions, (err, data) => {
if (err) {
- huksInfo = "exportKeyItem error return code:" + err.code + " : " + err.message;
+ huksInfo = 'exportKeyItem error return code:' + err.code + ' : ' + err.message;
} else {
huksInfo = uint8ArrayToString(data.outData);
}
@@ -80,13 +89,4 @@ function exportKeyProcess() {
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
+// [End export_key]
\ 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
index f25c8a7c..10848c2a 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/security/RSA.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/RSA.js
@@ -1,15 +1,15 @@
-// [Start 1]
-// [Start 3]
+// [Start rsa_generate]
+// [Start rsa_decrypt]
import huks from '@ohos.security.huks';
-// [Start 2]
+// [Start res_encrypt]
// 别名,用于区分生成的KEY
const RSA_KEY_ALIAS = 'RSAKeyAlias';
// 自定义密钥长度必须在1024 -2048之间,且是8的倍数
const HUKS_RSA_KEY_SIZE_1024 = 1024;
-// [StartExclude 1]
+// [StartExclude rsa_generate]
// 明文,加密前数据
-let plainText = "RSASSAdffssghCBC5612345612345192";
+let plainText = 'RSASSAdffssghCBC5612345612345192';
// 明文,加密前数据的长度
let plainTextLen = 32;
// 密文,存放加密后数据
@@ -17,9 +17,9 @@ let cipherText = '';
// 操作句柄
let handle;
-// [EndExclude 1]
-// [StartExclude 2]
-// [StartExclude 3]
+// [EndExclude rsa_generate]
+// [StartExclude res_encrypt]
+// [StartExclude rsa_decrypt]
function getRSAGenProperties() {
let properties = new Array();
let index = 0;
@@ -44,18 +44,18 @@ function getRSAGenProperties() {
function generateRSAKey() {
let huksInfo;
let options = { properties: getRSAGenProperties() };
- huks.generateKeyItem(HUKS_RSA_KEY_SIZE_1024, options, function (err, data) {
+ huks.generateKeyItem(HUKS_RSA_KEY_SIZE_1024, options, (err, data) => {
if (err) {
- huksInfo = "generateRSAKey return code:" + err.code + " : " + err.message;
+ huksInfo = 'generateRSAKey return code:' + err.code + ' : ' + err.message;
} else {
- huksInfo = "The key has been generated:" + JSON.stringify(data);
+ huksInfo = 'The key has been generated:' + JSON.stringify(data);
}
});
return huksInfo;
}
-// [End 1]
-// [EndExclude 2]
+// [End rsa_generate]
+// [EndExclude res_encrypt]
function getRSAEncryptProperties() {
let properties = new Array();
let index = 0;
@@ -102,49 +102,49 @@ function encryptProcess() {
properties: getRSAEncryptProperties(),
inData: stringToUint8Array(plainText.substring(plainTextLen / 2, plainTextLen))
}
- huks.initSession(RSA_KEY_ALIAS, initOptions, function (initErr, initData) {
+ huks.initSession(RSA_KEY_ALIAS, initOptions, (initErr, initData) => {
if (initErr) {
- huksInfo = "encryptProcess initSession return code:" + initErr.code + " : " + initErr.message;
+ huksInfo = 'encryptProcess initSession return code:' + initErr.code + ' : ' + initErr.message;
ret = false;
- huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ huks.abortSession(initData.handle, initOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "encryptProcess init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'encryptProcess init abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
handle = initData.handle;
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ huks.updateSession(handle, updateOptions, (updateErr, updateData) => {
if (updateErr) {
- huksInfo = "encryptProcess updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ huksInfo = 'encryptProcess updateSession return code:' + updateErr.code + ' : ' + updateErr.message;
ret = false;
- huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ huks.abortSession(handle, updateOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "encryptProcess updateSession abortSession return code:" + abortErr.code + " : " +
+ huksInfo = 'encryptProcess updateSession abortSession return code:' + abortErr.code + ' : ' +
abortErr.message;
}
});
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ huks.finishSession(handle, finishOptions, (finishErr, finishData) => {
if (finishErr) {
ret = false;
- huksInfo = "encryptProcess finishSession return code:" + finishErr.code + " : " + finishErr.message;
- huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ huksInfo = 'encryptProcess finishSession return code:' + finishErr.code + ' : ' + finishErr.message;
+ huks.abortSession(handle, finishOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "encryptProcess finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'encryptProcess finish abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -172,8 +172,8 @@ function stringToUint8Array(str) {
return new Uint8Array(arr);
}
-// [End 2]
-// [EndExclude 3]
+// [End res_encrypt]
+// [EndExclude rsa_decrypt]
function getRSADecryptProperties() {
let properties = new Array();
let index = 0;
@@ -227,47 +227,47 @@ function decryptProcess() {
properties: getRSADecryptProperties(),
inData: stringToUint8Array(cipherText.substring(len / 2, len))
}
- huks.initSession(RSA_KEY_ALIAS, initOptions, function (initErr, initData) {
+ huks.initSession(RSA_KEY_ALIAS, initOptions, (initErr, initData) => {
if (initErr) {
- huksInfo = "decryptProcess initSession return code:" + initErr.code + " : " + initErr.message;
+ huksInfo = 'decryptProcess initSession return code:' + initErr.code + ' : ' + initErr.message;
ret = false;
- huks.abortSession(initData.handle, initOptions, function (abortErr, abortData) {
+ huks.abortSession(initData.handle, initOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "decryptProcess init abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'decryptProcess init abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
handle = initData.handle;
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.updateSession(handle, updateOptions, function (updateErr, updateData) {
+ huks.updateSession(handle, updateOptions, (updateErr, updateData) => {
if (updateErr) {
- huksInfo = "decryptProcess updateSession return code:" + updateErr.code + " : " + updateErr.message;
+ huksInfo = 'decryptProcess updateSession return code:' + updateErr.code + ' : ' + updateErr.message;
ret = false;
- huks.abortSession(handle, updateOptions, function (abortErr, abortData) {
+ huks.abortSession(handle, updateOptions, (abortErr, abortData) => {
if (abortErr) {
- huksInfo = "decryptProcess updateSession abortSession return code:" + abortErr.code + " : " +
+ huksInfo = 'decryptProcess updateSession abortSession return code:' + abortErr.code + ' : ' +
abortErr.message;
}
});
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
}
- huks.finishSession(handle, finishOptions, function (finishErr, finishData) {
+ huks.finishSession(handle, finishOptions, (finishErr, finishData) => {
if (finishErr) {
ret = false;
- huksInfo = "decryptProcess finishSession return code:" + finishErr.code + " : " + finishErr.message;
- huks.abortSession(handle, finishOptions, function (abortErr, abortData) {
+ huksInfo = 'decryptProcess finishSession return code:' + finishErr.code + ' : ' + finishErr.message;
+ huks.abortSession(handle, finishOptions, (abortErr, abortData) => {
if (abortErr) {
huksInfo =
- "decryptProcess finish abortSession return code:" + abortErr.code + " : " + abortErr.message;
+ 'decryptProcess finish abortSession return code:' + abortErr.code + ' : ' + abortErr.message;
}
});
} else {
@@ -275,12 +275,12 @@ function decryptProcess() {
outPlainText = uint8ArrayToString(finishData.outData);
}
});
- if (ret == false) {
+ if (!ret) {
return huksInfo;
} else {
- huksInfo = "Success:" + outPlainText;
+ huksInfo = 'Success:' + outPlainText;
}
return huksInfo;
}
-// [End 3]
\ No newline at end of file
+// [End rsa_decrypt]
\ No newline at end of file
diff --git a/LiteWearable/entry/src/main/js/MainAbility/security/security.js b/LiteWearable/entry/src/main/js/MainAbility/security/security.js
index c6830639..3e03cb5a 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/security/security.js
+++ b/LiteWearable/entry/src/main/js/MainAbility/security/security.js
@@ -1,8 +1,8 @@
export default {
data: {
- title: ""
+ title: ''
},
onInit() {
- this.title = "Hello World";
+ this.title = 'Hello World';
}
};
diff --git a/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml b/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml
index 7696cdf4..bc53d37e 100644
--- a/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml
+++ b/LiteWearable/entry/src/main/js/MainAbility/style1/style1.hml
@@ -1,4 +1,4 @@
-
@@ -6,4 +6,4 @@
Hello World
-
@@ -6,4 +6,4 @@
Hello World
-
@@ -7,4 +7,4 @@
Hello World
-
Hello World
-