提交 c8b2fc6f 编写于 作者: C CheungVane

将var改为let

Signed-off-by: Nzhangwenzhi <zhangwenzhi3@huawei.com>
上级 7bfb07a6
...@@ -81,8 +81,8 @@ generateKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\ ...@@ -81,8 +81,8 @@ generateKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\
```js ```js
/* 以生成ECC256密钥为例 */ /* 以生成ECC256密钥为例 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_ECC value: huks.HuksKeyAlg.HUKS_ALG_ECC
...@@ -101,7 +101,7 @@ properties[3] = { ...@@ -101,7 +101,7 @@ properties[3] = {
tag: huks.HuksTag.HUKS_TAG_DIGEST, tag: huks.HuksTag.HUKS_TAG_DIGEST,
value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
}; };
var options = { let options = {
properties: properties properties: properties
}; };
try { try {
...@@ -136,8 +136,8 @@ generateKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void> ...@@ -136,8 +136,8 @@ generateKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void>
```js ```js
/* 以生成ECC256密钥为例 */ /* 以生成ECC256密钥为例 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_ECC value: huks.HuksKeyAlg.HUKS_ALG_ECC
...@@ -156,7 +156,7 @@ properties[3] = { ...@@ -156,7 +156,7 @@ properties[3] = {
tag: huks.HuksTag.HUKS_TAG_DIGEST, tag: huks.HuksTag.HUKS_TAG_DIGEST,
value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
}; };
var options = { let options = {
properties: properties properties: properties
}; };
try { try {
...@@ -192,8 +192,8 @@ deleteKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<v ...@@ -192,8 +192,8 @@ deleteKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<v
```js ```js
/* 此处options选择emptyOptions传空 */ /* 此处options选择emptyOptions传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -228,8 +228,8 @@ deleteKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void> ...@@ -228,8 +228,8 @@ deleteKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void>
```js ```js
/* 此处options选择emptyOptions传空 */ /* 此处options选择emptyOptions传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -269,10 +269,10 @@ getSdkVersion(options: HuksOptions) : string ...@@ -269,10 +269,10 @@ getSdkVersion(options: HuksOptions) : string
```js ```js
/* 此处options选择emptyOptions传空 */ /* 此处options选择emptyOptions传空 */
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
var result = huks.getSdkVersion(emptyOptions); let result = huks.getSdkVersion(emptyOptions);
``` ```
## huks.importKeyItem<sup>9+</sup> ## huks.importKeyItem<sup>9+</sup>
...@@ -295,16 +295,16 @@ importKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<v ...@@ -295,16 +295,16 @@ importKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<v
```js ```js
/* 以导入AES256密钥为例 */ /* 以导入AES256密钥为例 */
var plainTextSize32 = makeRandomArr(32); let plainTextSize32 = makeRandomArr(32);
function makeRandomArr(size) { function makeRandomArr(size) {
var arr = new Uint8Array(size); let arr = new Uint8Array(size);
for (var i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
arr[i] = Math.floor(Math.random() * 10); arr[i] = Math.floor(Math.random() * 10);
} }
return arr; return arr;
}; };
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_AES value: huks.HuksKeyAlg.HUKS_ALG_AES
...@@ -326,7 +326,7 @@ properties[4] = { ...@@ -326,7 +326,7 @@ properties[4] = {
tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
value: huks.HuksCipherMode.HUKS_MODE_ECB value: huks.HuksCipherMode.HUKS_MODE_ECB
}; };
var options = { let options = {
properties: properties, properties: properties,
inData: plainTextSize32 inData: plainTextSize32
}; };
...@@ -362,19 +362,19 @@ importKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void> ...@@ -362,19 +362,19 @@ importKeyItem(keyAlias: string, options: HuksOptions) : Promise\<void>
```js ```js
/* 以导入AES128为例 */ /* 以导入AES128为例 */
var plainTextSize32 = makeRandomArr(32); let plainTextSize32 = makeRandomArr(32);
function makeRandomArr(size) { function makeRandomArr(size) {
var arr = new Uint8Array(size); let arr = new Uint8Array(size);
for (var i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
arr[i] = Math.floor(Math.random() * 10); arr[i] = Math.floor(Math.random() * 10);
} }
return arr; return arr;
}; };
/*第一步:生成密钥*/ /*第一步:生成密钥*/
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_AES value: huks.HuksKeyAlg.HUKS_ALG_AES
...@@ -395,7 +395,7 @@ properties[4] = { ...@@ -395,7 +395,7 @@ properties[4] = {
tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
value: huks.HuksCipherMode.HUKS_MODE_ECB value: huks.HuksCipherMode.HUKS_MODE_ECB
}; };
var huksoptions = { let huksoptions = {
properties: properties, properties: properties,
inData: plainTextSize32 inData: plainTextSize32
}; };
...@@ -437,11 +437,11 @@ let versionInfo = stringToUint8Array('version_info'); ...@@ -437,11 +437,11 @@ let versionInfo = stringToUint8Array('version_info');
let keyAliasString = "key attest"; let keyAliasString = "key attest";
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; let arr = [];
for (var i = 0, j = str.length; i < j; ++i) { for (let i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i)); arr.push(str.charCodeAt(i));
} }
var tmpUint8Array = new Uint8Array(arr); let tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array; return tmpUint8Array;
} }
...@@ -564,11 +564,11 @@ let versionInfo = stringToUint8Array('version_info'); ...@@ -564,11 +564,11 @@ let versionInfo = stringToUint8Array('version_info');
let keyAliasString = "key attest"; let keyAliasString = "key attest";
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; let arr = [];
for (var i = 0, j = str.length; i < j; ++i) { for (let i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i)); arr.push(str.charCodeAt(i));
} }
var tmpUint8Array = new Uint8Array(arr); let tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array; return tmpUint8Array;
} }
...@@ -683,9 +683,9 @@ importWrappedKeyItem(keyAlias: string, wrappingKeyAlias: string, options: HuksOp ...@@ -683,9 +683,9 @@ importWrappedKeyItem(keyAlias: string, wrappingKeyAlias: string, options: HuksOp
```js ```js
import huks from '@ohos.security.huks'; import huks from '@ohos.security.huks';
var exportWrappingKey; let exportWrappingKey;
var alias1 = "importAlias"; let alias1 = "importAlias";
var alias2 = "wrappingKeyAlias"; let alias2 = "wrappingKeyAlias";
async function TestGenFunc(alias, options) { async function TestGenFunc(alias, options) {
try { try {
...@@ -800,13 +800,13 @@ async function TestImportWrappedKeyFunc( ...@@ -800,13 +800,13 @@ async function TestImportWrappedKeyFunc(
* nonce1的长度(4字节) + nonce1的数据 + tag1的长度(4字节) + tag1的数据 + * nonce1的长度(4字节) + nonce1的数据 + tag1的长度(4字节) + tag1的数据 +
* keyA长度占用的内存长度(4字节) + keyA的长度 + keyA_enc的长度(4字节) + keyA_enc的数据 * keyA长度占用的内存长度(4字节) + keyA的长度 + keyA_enc的长度(4字节) + keyA_enc的数据
*/ */
var inputKey = new Uint8Array([0x02, 0x00, 0x00, 0x00]); let inputKey = new Uint8Array([0x02, 0x00, 0x00, 0x00]);
importOptions.inData = inputKey; importOptions.inData = inputKey;
await TestImportWrappedFunc(alias, wrappingAlias, importOptions); await TestImportWrappedFunc(alias, wrappingAlias, importOptions);
} }
function makeGenerateOptions() { function makeGenerateOptions() {
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_ECC value: huks.HuksKeyAlg.HUKS_ALG_ECC
...@@ -827,14 +827,14 @@ function makeGenerateOptions() { ...@@ -827,14 +827,14 @@ function makeGenerateOptions() {
tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE, tag: huks.HuksTag.HUKS_TAG_IMPORT_KEY_TYPE,
value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR, value: huks.HuksImportKeyType.HUKS_KEY_TYPE_KEY_PAIR,
}; };
var options = { let options = {
properties: properties properties: properties
}; };
return options; return options;
}; };
function makeImportOptions() { function makeImportOptions() {
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_AES value: huks.HuksKeyAlg.HUKS_ALG_AES
...@@ -859,15 +859,15 @@ function makeImportOptions() { ...@@ -859,15 +859,15 @@ function makeImportOptions() {
tag: huks.HuksTag.HUKS_TAG_UNWRAP_ALGORITHM_SUITE, tag: huks.HuksTag.HUKS_TAG_UNWRAP_ALGORITHM_SUITE,
value: huks.HuksUnwrapSuite.HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING value: huks.HuksUnwrapSuite.HUKS_UNWRAP_SUITE_ECDH_AES_256_GCM_NOPADDING
}; };
var options = { let options = {
properties: properties properties: properties
}; };
return options; return options;
}; };
function huksImportWrappedKey() { function huksImportWrappedKey() {
var genOptions = makeGenerateOptions(); let genOptions = makeGenerateOptions();
var importOptions = makeImportOptions(); let importOptions = makeImportOptions();
TestImportWrappedKeyFunc( TestImportWrappedKeyFunc(
alias1, alias1,
alias2, alias2,
...@@ -932,8 +932,8 @@ exportKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<H ...@@ -932,8 +932,8 @@ exportKeyItem(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<H
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -974,8 +974,8 @@ exportKeyItem(keyAlias: string, options: HuksOptions) : Promise\<HuksReturnResul ...@@ -974,8 +974,8 @@ exportKeyItem(keyAlias: string, options: HuksOptions) : Promise\<HuksReturnResul
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -1011,8 +1011,8 @@ getKeyItemProperties(keyAlias: string, options: HuksOptions, callback: AsyncCall ...@@ -1011,8 +1011,8 @@ getKeyItemProperties(keyAlias: string, options: HuksOptions, callback: AsyncCall
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -1053,8 +1053,8 @@ getKeyItemProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksRetu ...@@ -1053,8 +1053,8 @@ getKeyItemProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksRetu
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -1090,8 +1090,8 @@ isKeyItemExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\< ...@@ -1090,8 +1090,8 @@ isKeyItemExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -1132,8 +1132,8 @@ isKeyItemExist(keyAlias: string, options: HuksOptions) : Promise\<boolean> ...@@ -1132,8 +1132,8 @@ isKeyItemExist(keyAlias: string, options: HuksOptions) : Promise\<boolean>
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
try { try {
...@@ -1328,21 +1328,21 @@ abort操作密钥接口,使用Callback回调异步返回结果 。 ...@@ -1328,21 +1328,21 @@ abort操作密钥接口,使用Callback回调异步返回结果 。
* 以下以RSA1024密钥的callback功能使用为例 * 以下以RSA1024密钥的callback功能使用为例
*/ */
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; let arr = [];
for (var i = 0, j = str.length; i < j; ++i) { for (let i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i)); arr.push(str.charCodeAt(i));
} }
var tmpUint8Array = new Uint8Array(arr); let tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array; return tmpUint8Array;
} }
var keyAlias = "HuksDemoRSA"; let keyAlias = "HuksDemoRSA";
var properties = new Array(); let properties = new Array();
var options = { let options = {
properties: properties, properties: properties,
inData: new Uint8Array(0) inData: new Uint8Array(0)
}; };
var handle; let handle;
async function generateKey() { async function generateKey() {
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
...@@ -1478,21 +1478,21 @@ abort操作密钥接口,使用Promise方式异步返回结果。 ...@@ -1478,21 +1478,21 @@ abort操作密钥接口,使用Promise方式异步返回结果。
* 以下以RSA1024密钥的callback功能使用为例 * 以下以RSA1024密钥的callback功能使用为例
*/ */
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; let arr = [];
for (var i = 0, j = str.length; i < j; ++i) { for (let i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i)); arr.push(str.charCodeAt(i));
} }
var tmpUint8Array = new Uint8Array(arr); let tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array; return tmpUint8Array;
} }
var keyAlias = "HuksDemoRSA"; let keyAlias = "HuksDemoRSA";
var properties = new Array(); let properties = new Array();
var options = { let options = {
properties: properties, properties: properties,
inData: new Uint8Array(0) inData: new Uint8Array(0)
}; };
var handle; let handle;
async function generateKey() { async function generateKey() {
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
...@@ -1999,8 +1999,8 @@ generateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<Huk ...@@ -1999,8 +1999,8 @@ generateKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<Huk
```js ```js
/* 以生成RSA512密钥为例 */ /* 以生成RSA512密钥为例 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_RSA value: huks.HuksKeyAlg.HUKS_ALG_RSA
...@@ -2023,7 +2023,7 @@ properties[4] = { ...@@ -2023,7 +2023,7 @@ properties[4] = {
tag: huks.HuksTag.HUKS_TAG_DIGEST, tag: huks.HuksTag.HUKS_TAG_DIGEST,
value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
}; };
var options = { let options = {
properties: properties properties: properties
}; };
huks.generateKey(keyAlias, options, function (err, data){}); huks.generateKey(keyAlias, options, function (err, data){});
...@@ -2056,8 +2056,8 @@ generateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> ...@@ -2056,8 +2056,8 @@ generateKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
```js ```js
/* 以生成ECC256密钥为例 */ /* 以生成ECC256密钥为例 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_ECC value: huks.HuksKeyAlg.HUKS_ALG_ECC
...@@ -2076,10 +2076,10 @@ properties[3] = { ...@@ -2076,10 +2076,10 @@ properties[3] = {
tag: huks.HuksTag.HUKS_TAG_DIGEST, tag: huks.HuksTag.HUKS_TAG_DIGEST,
value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256 value: huks.HuksKeyDigest.HUKS_DIGEST_SHA256
}; };
var options = { let options = {
properties: properties properties: properties
}; };
var result = huks.generateKey(keyAlias, options); let result = huks.generateKey(keyAlias, options);
``` ```
...@@ -2105,8 +2105,8 @@ deleteKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksR ...@@ -2105,8 +2105,8 @@ deleteKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksR
```js ```js
/* 此处options选择emptyOptions传空 */ /* 此处options选择emptyOptions传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
huks.deleteKey(keyAlias, emptyOptions, function (err, data) {}); huks.deleteKey(keyAlias, emptyOptions, function (err, data) {});
...@@ -2139,11 +2139,11 @@ deleteKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> ...@@ -2139,11 +2139,11 @@ deleteKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
```js ```js
/* 此处options选择emptyOptions传空 */ /* 此处options选择emptyOptions传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
var result = huks.deleteKey(keyAlias, emptyOptions); let result = huks.deleteKey(keyAlias, emptyOptions);
``` ```
...@@ -2169,16 +2169,16 @@ importKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksR ...@@ -2169,16 +2169,16 @@ importKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksR
```js ```js
/* 以导入AES256密钥为例 */ /* 以导入AES256密钥为例 */
var plainTextSize32 = makeRandomArr(32); let plainTextSize32 = makeRandomArr(32);
function makeRandomArr(size) { function makeRandomArr(size) {
var arr = new Uint8Array(size); let arr = new Uint8Array(size);
for (var i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
arr[i] = Math.floor(Math.random() * 10); arr[i] = Math.floor(Math.random() * 10);
} }
return arr; return arr;
}; };
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_AES value: huks.HuksKeyAlg.HUKS_ALG_AES
...@@ -2200,7 +2200,7 @@ properties[4] = { ...@@ -2200,7 +2200,7 @@ properties[4] = {
tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
value: huks.HuksCipherMode.HUKS_MODE_ECB value: huks.HuksCipherMode.HUKS_MODE_ECB
}; };
var options = { let options = {
properties: properties, properties: properties,
inData: plainTextSize32 inData: plainTextSize32
}; };
...@@ -2234,19 +2234,19 @@ importKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> ...@@ -2234,19 +2234,19 @@ importKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
```js ```js
/* 以导入AES128为例 */ /* 以导入AES128为例 */
var plainTextSize32 = makeRandomArr(32); let plainTextSize32 = makeRandomArr(32);
function makeRandomArr(size) { function makeRandomArr(size) {
var arr = new Uint8Array(size); let arr = new Uint8Array(size);
for (var i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
arr[i] = Math.floor(Math.random() * 10); arr[i] = Math.floor(Math.random() * 10);
} }
return arr; return arr;
}; };
/*第一步:生成密钥*/ /*第一步:生成密钥*/
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var properties = new Array(); let properties = new Array();
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
value: huks.HuksKeyAlg.HUKS_ALG_AES value: huks.HuksKeyAlg.HUKS_ALG_AES
...@@ -2267,11 +2267,11 @@ properties[4] = { ...@@ -2267,11 +2267,11 @@ properties[4] = {
tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE, tag: huks.HuksTag.HUKS_TAG_BLOCK_MODE,
value: huks.HuksCipherMode.HUKS_MODE_ECB value: huks.HuksCipherMode.HUKS_MODE_ECB
}; };
var huksoptions = { let huksoptions = {
properties: properties, properties: properties,
inData: plainTextSize32 inData: plainTextSize32
}; };
var result = huks.importKey(keyAlias, huksoptions); let result = huks.importKey(keyAlias, huksoptions);
``` ```
...@@ -2297,8 +2297,8 @@ exportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksR ...@@ -2297,8 +2297,8 @@ exportKey(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<HuksR
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
huks.exportKey(keyAlias, emptyOptions, function (err, data){}); huks.exportKey(keyAlias, emptyOptions, function (err, data){});
...@@ -2331,11 +2331,11 @@ exportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> ...@@ -2331,11 +2331,11 @@ exportKey(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
var result = huks.exportKey(keyAlias, emptyOptions); let result = huks.exportKey(keyAlias, emptyOptions);
``` ```
...@@ -2361,8 +2361,8 @@ getKeyProperties(keyAlias: string, options: HuksOptions, callback: AsyncCallback ...@@ -2361,8 +2361,8 @@ getKeyProperties(keyAlias: string, options: HuksOptions, callback: AsyncCallback
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
huks.getKeyProperties(keyAlias, emptyOptions, function (err, data){}); huks.getKeyProperties(keyAlias, emptyOptions, function (err, data){});
...@@ -2395,11 +2395,11 @@ getKeyProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksResult> ...@@ -2395,11 +2395,11 @@ getKeyProperties(keyAlias: string, options: HuksOptions) : Promise\<HuksResult>
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
var result = huks.getKeyProperties(keyAlias, emptyOptions); let result = huks.getKeyProperties(keyAlias, emptyOptions);
``` ```
...@@ -2425,8 +2425,8 @@ isKeyExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<bool ...@@ -2425,8 +2425,8 @@ isKeyExist(keyAlias: string, options: HuksOptions, callback: AsyncCallback\<bool
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
huks.isKeyExist(keyAlias, emptyOptions, function (err, data){}); huks.isKeyExist(keyAlias, emptyOptions, function (err, data){});
...@@ -2459,11 +2459,11 @@ isKeyExist(keyAlias: string, options: HuksOptions) : Promise\<boolean> ...@@ -2459,11 +2459,11 @@ isKeyExist(keyAlias: string, options: HuksOptions) : Promise\<boolean>
```js ```js
/* 此处options选择emptyOptions来传空 */ /* 此处options选择emptyOptions来传空 */
var keyAlias = 'keyAlias'; let keyAlias = 'keyAlias';
var emptyOptions = { let emptyOptions = {
properties: [] properties: []
}; };
var result = huks.isKeyExist(keyAlias, emptyOptions); let result = huks.isKeyExist(keyAlias, emptyOptions);
``` ```
## huks.init<sup>(deprecated)</sup> ## huks.init<sup>(deprecated)</sup>
...@@ -2640,14 +2640,14 @@ abort操作密钥接口,使用Callback回调异步返回结果。 ...@@ -2640,14 +2640,14 @@ abort操作密钥接口,使用Callback回调异步返回结果。
* *
* 以下以RSA1024密钥的callback操作使用为例 * 以下以RSA1024密钥的callback操作使用为例
*/ */
var keyalias = "HuksDemoRSA"; let keyalias = "HuksDemoRSA";
var properties = new Array(); let properties = new Array();
var options = { let options = {
properties: properties, properties: properties,
inData: new Uint8Array(0) inData: new Uint8Array(0)
}; };
var handle; let handle;
var resultMessage = ""; let resultMessage = "";
async function generateKey() { async function generateKey() {
properties[0] = { properties[0] = {
tag: huks.HuksTag.HUKS_TAG_ALGORITHM, tag: huks.HuksTag.HUKS_TAG_ALGORITHM,
...@@ -2672,11 +2672,11 @@ async function generateKey() { ...@@ -2672,11 +2672,11 @@ async function generateKey() {
huks.generateKey(keyalias, options); huks.generateKey(keyalias, options);
} }
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; let arr = [];
for (var i = 0, j = str.length; i < j; ++i) { for (let i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i)); arr.push(str.charCodeAt(i));
} }
var tmpUint8Array = new Uint8Array(arr); let tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array; return tmpUint8Array;
} }
async function huksInit() { async function huksInit() {
...@@ -2756,20 +2756,20 @@ abort操作密钥接口,使用Promise方式异步返回结果。 ...@@ -2756,20 +2756,20 @@ abort操作密钥接口,使用Promise方式异步返回结果。
* *
* 以下以RSA1024密钥的promise操作使用为例 * 以下以RSA1024密钥的promise操作使用为例
*/ */
var keyalias = "HuksDemoRSA"; let keyalias = "HuksDemoRSA";
var properties = new Array(); let properties = new Array();
var options = { let options = {
properties: properties, properties: properties,
inData: new Uint8Array(0) inData: new Uint8Array(0)
}; };
var handle; let handle;
var resultMessage = ""; let resultMessage = "";
function stringToUint8Array(str) { function stringToUint8Array(str) {
var arr = []; let arr = [];
for (var i = 0, j = str.length; i < j; ++i) { for (let i = 0, j = str.length; i < j; ++i) {
arr.push(str.charCodeAt(i)); arr.push(str.charCodeAt(i));
} }
var tmpUint8Array = new Uint8Array(arr); let tmpUint8Array = new Uint8Array(arr);
return tmpUint8Array; return tmpUint8Array;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册