diff --git a/LiteWearable/entry/src/main/config.json b/LiteWearable/entry/src/main/config.json index c0b16ac154a22808f3ac5b585fd233571c21d073..7a53ffd8cf77cbff1a48fbeff235714c5c0ddb50 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 168cbfcffde083ade81f70de9e937a6cf12fc7fe..a15bc8599dcf52fc8e6fa527d9e1455e2df25335 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 720f9253d4b35cd83eaf94df05044f2ddee8b60e..f3a9eb9f0584f43620bce0bd9beb081227905991 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 b89e21b7e998e39ff7a8fd278e4dfccfee9c930b..4140687765c97c5c3ec48372696007342e5abd9b 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 a393b645b934cf4699ad14981ce993d9b61650d3..43daa6f9bf359f5a6a6f676e74a292cd71aac92d 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 549561a218711b04c5345ac3d810c2d339d65f03..8cce889e7d51d4eca3d54cceaf9e2400454b9e97 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 40b3051af5f9234672f3b855dba270c789d27383..2d1641b081ce0babd84043357ea1411c8216316a 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 4417284f4cecb65e91a07af4d9a95738af6d938b..239d95294b436916fa554fd1955b4bd9f416bf4f 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 1ab84cfabc622fa6d24d924960fe75021739f6f2..9b0a820d11f8cb72f2dfa22b34e69027fc8fab19 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 955eca4135b757015f993ef2b95988f2108176ca..8d9cfc726c9f630933ec07178db4b93965aff8de 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 1e1e08a1ad3724ee5f7c44179cc10e01328cfa69..0acac82f39ee3acca68239dc977f69f0b0215435 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 0dfc89acf2134f6e524998e981a9b5e7a6c7ca3d..e802688afe8d18bd550a7e49201c67b24ee7d048 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 8b8fe70b6678c15d3390e9d42efadc0066899f2b..4999668eeef4bf3b3bed103ae631e59555cbd9c0 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 d2db0a6782cfa21424ab8ea66c96e51beec58660..119a8bb9fa579e0e51e51e284d7ab6450db5fb20 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 ad55e0b6c7bac2c71d4736b13c1ee0045836031e..efa05f9af4c6be0efd0340185ee73b9d40f38da8 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 7e86aca71fa2773d8473f30aaea77063f9d2dd09..39f36e765943a5b5da1e3bb59729ea84bf28b509 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 e10810251c785c477a378e974da9a848e7edcbda..c3048f3cf141a0733ac714f956ba137d2ed27a00 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 a07743e5dcf7a1f9648498fb783c72b53a2904b1..2bf669097719b0037752f788cfc25662954772b7 100644 --- a/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js +++ b/LiteWearable/entry/src/main/js/MainAbility/security/KeyAlias.js @@ -1,17 +1,17 @@ -// [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 ]); -// [EndExclude 2] +// [EndExclude export_key] // 确定密钥别名 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 f25c8a7c7c062216dad8b8768c678a2084587bab..73469f3132bcde33a2a243a376f22607370589ec 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 rsa_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 rsa_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 rsa_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 rsa_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 c683063934277cfa65caf96b78ad7250554ca995..3e03cb5afd81a0c3d45f7d16147c4900e17f4f86 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 7696cdf44addd9ed529acac2a77c0c29efb36ec6..bc53d37ea47559a2b108ca0f9aee9faa8a588a6e 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
-