Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
868f5778
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
868f5778
编写于
7月 14, 2023
作者:
胡
胡啸天
提交者:
Gitee
7月 14, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md.
Signed-off-by:
N
胡啸天
<
huxiaotian2@huawei.com
>
上级
d720ac5d
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
35 addition
and
35 deletion
+35
-35
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
...application-dev/reference/apis/js-apis-cryptoFramework.md
+35
-35
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
浏览文件 @
868f5778
...
...
@@ -494,7 +494,7 @@ clearMem(): void
```
js
let
key
;
// key为使用非对称密钥生成器生成的非对称密钥的私钥对象,此处省略生成过程
key
.
clearMem
();
key
.
clearMem
();
// 非对称密钥私钥clearMem会释放内部密钥结构体,clearMem后不支持getEncoded操作
```
### getAsyKeySpec<sup>10+</sup>
...
...
@@ -915,8 +915,8 @@ convertKey(pubKey: DataBlob, priKey: DataBlob, callback: AsyncCallback\<KeyPair\
```
js
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
pubKeyArray
=
new
Uint8Array
([
48
,
89
,
48
,
19
,
6
,
7
,
42
,
134
,
72
,
206
,
61
,
2
,
1
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
,
3
,
66
,
0
,
4
,
83
,
96
,
142
,
9
,
86
,
214
,
126
,
106
,
247
,
233
,
92
,
125
,
4
,
128
,
138
,
105
,
246
,
162
,
215
,
71
,
81
,
58
,
202
,
121
,
26
,
105
,
211
,
55
,
130
,
45
,
236
,
143
,
55
,
16
,
248
,
75
,
167
,
160
,
167
,
106
,
2
,
152
,
243
,
44
,
68
,
66
,
0
,
167
,
99
,
92
,
235
,
215
,
159
,
239
,
28
,
106
,
124
,
171
,
34
,
145
,
124
,
174
,
57
,
92
]);
let
priKeyArray
=
new
Uint8Array
([
48
,
49
,
2
,
1
,
1
,
4
,
32
,
115
,
56
,
137
,
35
,
207
,
0
,
60
,
191
,
90
,
61
,
136
,
105
,
210
,
16
,
27
,
4
,
171
,
57
,
10
,
61
,
123
,
40
,
189
,
28
,
34
,
207
,
236
,
22
,
45
,
223
,
10
,
189
,
160
,
10
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
]);
let
pubKeyArray
=
new
Uint8Array
([
48
,
89
,
48
,
19
,
6
,
7
,
42
,
134
,
72
,
206
,
61
,
2
,
1
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
,
3
,
66
,
0
,
4
,
83
,
96
,
142
,
9
,
86
,
214
,
126
,
106
,
247
,
233
,
92
,
125
,
4
,
128
,
138
,
105
,
246
,
162
,
215
,
71
,
81
,
58
,
202
,
121
,
26
,
105
,
211
,
55
,
130
,
45
,
236
,
143
,
55
,
16
,
248
,
75
,
167
,
160
,
167
,
106
,
2
,
152
,
243
,
44
,
68
,
66
,
0
,
167
,
99
,
92
,
235
,
215
,
159
,
239
,
28
,
106
,
124
,
171
,
34
,
145
,
124
,
174
,
57
,
92
]);
let
priKeyArray
=
new
Uint8Array
([
48
,
49
,
2
,
1
,
1
,
4
,
32
,
115
,
56
,
137
,
35
,
207
,
0
,
60
,
191
,
90
,
61
,
136
,
105
,
210
,
16
,
27
,
4
,
171
,
57
,
10
,
61
,
123
,
40
,
189
,
28
,
34
,
207
,
236
,
22
,
45
,
223
,
10
,
189
,
160
,
10
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
]);
let
pubKeyBlob
=
{
data
:
pubKeyArray
};
// 公钥的密钥数据
let
priKeyBlob
=
{
data
:
priKeyArray
};
// 私钥的密钥数据
let
asyKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC256
"
);
...
...
@@ -963,8 +963,8 @@ convertKey(pubKey: DataBlob, priKey: DataBlob): Promise\<KeyPair>
```
js
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
pubKeyArray
=
new
Uint8Array
([
48
,
89
,
48
,
19
,
6
,
7
,
42
,
134
,
72
,
206
,
61
,
2
,
1
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
,
3
,
66
,
0
,
4
,
83
,
96
,
142
,
9
,
86
,
214
,
126
,
106
,
247
,
233
,
92
,
125
,
4
,
128
,
138
,
105
,
246
,
162
,
215
,
71
,
81
,
58
,
202
,
121
,
26
,
105
,
211
,
55
,
130
,
45
,
236
,
143
,
55
,
16
,
248
,
75
,
167
,
160
,
167
,
106
,
2
,
152
,
243
,
44
,
68
,
66
,
0
,
167
,
99
,
92
,
235
,
215
,
159
,
239
,
28
,
106
,
124
,
171
,
34
,
145
,
124
,
174
,
57
,
92
]);
let
priKeyArray
=
new
Uint8Array
([
48
,
49
,
2
,
1
,
1
,
4
,
32
,
115
,
56
,
137
,
35
,
207
,
0
,
60
,
191
,
90
,
61
,
136
,
105
,
210
,
16
,
27
,
4
,
171
,
57
,
10
,
61
,
123
,
40
,
189
,
28
,
34
,
207
,
236
,
22
,
45
,
223
,
10
,
189
,
160
,
10
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
]);
let
pubKeyArray
=
new
Uint8Array
([
48
,
89
,
48
,
19
,
6
,
7
,
42
,
134
,
72
,
206
,
61
,
2
,
1
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
,
3
,
66
,
0
,
4
,
83
,
96
,
142
,
9
,
86
,
214
,
126
,
106
,
247
,
233
,
92
,
125
,
4
,
128
,
138
,
105
,
246
,
162
,
215
,
71
,
81
,
58
,
202
,
121
,
26
,
105
,
211
,
55
,
130
,
45
,
236
,
143
,
55
,
16
,
248
,
75
,
167
,
160
,
167
,
106
,
2
,
152
,
243
,
44
,
68
,
66
,
0
,
167
,
99
,
92
,
235
,
215
,
159
,
239
,
28
,
106
,
124
,
171
,
34
,
145
,
124
,
174
,
57
,
92
]);
let
priKeyArray
=
new
Uint8Array
([
48
,
49
,
2
,
1
,
1
,
4
,
32
,
115
,
56
,
137
,
35
,
207
,
0
,
60
,
191
,
90
,
61
,
136
,
105
,
210
,
16
,
27
,
4
,
171
,
57
,
10
,
61
,
123
,
40
,
189
,
28
,
34
,
207
,
236
,
22
,
45
,
223
,
10
,
189
,
160
,
10
,
6
,
8
,
42
,
134
,
72
,
206
,
61
,
3
,
1
,
7
]);
let
pubKeyBlob
=
{
data
:
pubKeyArray
};
// 公钥的密钥数据
let
priKeyBlob
=
{
data
:
priKeyArray
};
// 私钥的密钥数据
let
asyKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC256
"
);
...
...
@@ -1843,11 +1843,11 @@ import cryptoFramework from "@ohos.security.cryptoFramework"
let
signer1
=
cryptoFramework
.
createSign
(
"
RSA1024|PKCS1|SHA256
"
);
let
si
ng
er2
=
cryptoFramework
.
createSign
(
"
RSA1024|PSS|SHA256|MGF1_SHA256
"
);
let
si
gn
er2
=
cryptoFramework
.
createSign
(
"
RSA1024|PSS|SHA256|MGF1_SHA256
"
);
let
si
ng
er3
=
cryptoFramework
.
createSign
(
"
ECC224|SHA256
"
);
let
si
gn
er3
=
cryptoFramework
.
createSign
(
"
ECC224|SHA256
"
);
let
si
ng
er4
=
cryptoFramework
.
createSign
(
"
DSA2048|SHA256
"
);
let
si
gn
er4
=
cryptoFramework
.
createSign
(
"
DSA2048|SHA256
"
);
```
## Sign
...
...
@@ -2070,8 +2070,8 @@ function signMessageCallback() {
rsaGenerator
.
generateKeyPair
(
function
(
err
,
keyPair
)
{
globalKeyPair
=
keyPair
;
let
priKey
=
globalKeyPair
.
priKey
;
signer
.
init
(
priKey
,
function
(
err
,
data
)
{
signer
.
update
(
input1
,
function
(
err
,
data
)
{
// add first segment of data
signer
.
init
(
priKey
,
err
=>
{
signer
.
update
(
input1
,
err
=>
{
// add first segment of data
signer
.
sign
(
input2
,
function
(
err
,
data
)
{
// add second segment of data, sign input1 and input2
SignMessageBlob
=
data
;
AlertDialog
.
show
({
message
:
"
res
"
+
SignMessageBlob
.
data
});
...
...
@@ -2713,7 +2713,7 @@ try {
// 参数选择请参考上述算法支持范围
md
=
cryptoFramework
.
createMd
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
```
...
...
@@ -2764,7 +2764,7 @@ var md;
try
{
md
=
cryptoFramework
.
createMd
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Md algName is:
"
+
md
.
algName
);
...
...
@@ -2814,7 +2814,7 @@ var md;
try
{
md
=
cryptoFramework
.
createMd
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Md algName is:
"
+
md
.
algName
);
...
...
@@ -2855,7 +2855,7 @@ var md;
try
{
md
=
cryptoFramework
.
createMd
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Md algName is:
"
+
md
.
algName
);
...
...
@@ -2904,7 +2904,7 @@ var md;
try
{
md
=
cryptoFramework
.
createMd
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Md algName is:
"
+
md
.
algName
);
...
...
@@ -2949,7 +2949,7 @@ var md;
try
{
md
=
cryptoFramework
.
createMd
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Md algName is:
"
+
md
.
algName
);
...
...
@@ -3004,7 +3004,7 @@ try {
// 参数选择请参考上述算法支持范围
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
```
...
...
@@ -3051,7 +3051,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
var
KeyBlob
;
var
symKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
AES128
"
);
...
...
@@ -3103,7 +3103,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Mac algName is:
"
+
mac
.
algName
);
...
...
@@ -3155,7 +3155,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
var
symKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
AES128
"
);
symKeyGenerator
.
convertKey
(
KeyBlob
,
(
err
,
symKey
)
=>
{
...
...
@@ -3216,7 +3216,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Mac algName is:
"
+
mac
.
algName
);
...
...
@@ -3267,7 +3267,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Callback]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
var
symKeyGenerator
=
cryptoFramework
.
createSymKeyGenerator
(
"
AES128
"
);
symKeyGenerator
.
convertKey
(
KeyBlob
,
(
err
,
symKey
)
=>
{
...
...
@@ -3325,7 +3325,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Mac algName is:
"
+
mac
.
algName
);
...
...
@@ -3378,7 +3378,7 @@ var mac;
try
{
mac
=
cryptoFramework
.
createMac
(
"
SHA256
"
);
}
catch
(
error
)
{
console
.
error
(
"
[
Promise
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
console
.
error
(
"
Mac algName is:
"
+
mac
.
algName
);
...
...
@@ -3432,7 +3432,7 @@ import cryptoFramework from "@ohos.security.cryptoFramework"
try
{
var
rand
=
cryptoFramework
.
createRandom
();
}
catch
(
error
)
{
console
.
error
(
"
[
Callback]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
```
...
...
@@ -3480,7 +3480,7 @@ var rand;
try
{
rand
=
cryptoFramework
.
createRandom
();
}
catch
(
error
)
{
console
.
error
(
"
[
Callback]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
rand
.
generateRandom
(
12
,
(
err
,
randData
)
=>
{
if
(
err
)
{
...
...
@@ -3528,7 +3528,7 @@ var rand;
try
{
rand
=
cryptoFramework
.
createRandom
();
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
var
promiseGenerateRand
=
rand
.
generateRandom
(
12
);
...
...
@@ -3576,7 +3576,7 @@ var rand;
try
{
rand
=
cryptoFramework
.
createRandom
();
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
try
{
...
...
@@ -3618,18 +3618,18 @@ var rand;
try
{
rand
=
cryptoFramework
.
createRandom
();
}
catch
(
error
)
{
console
.
error
(
"
[
Callback
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
console
.
error
(
"
[
Sync
]: error code:
"
+
error
.
code
+
"
, message is:
"
+
error
.
message
);
}
rand
.
generateRandom
(
12
,
(
err
,
randData
)
=>
{
if
(
err
)
{
console
.
error
(
"
[Callback] err:
"
+
err
.
code
);
}
else
{
console
.
error
(
"
[Callback]: generate random result:
"
+
randData
.
data
);
console
.
info
(
"
[Callback]: generate random result:
"
+
randData
.
data
);
try
{
rand
.
setSeed
(
randData
);
}
catch
(
error
)
{
console
.
log
(
"
setSeed failed, errCode:
"
+
error
.
code
+
"
, errMsg:
"
+
error
.
message
);
console
.
error
(
"
setSeed failed, errCode:
"
+
error
.
code
+
"
, errMsg:
"
+
error
.
message
);
}
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录