Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
69d20154
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
69d20154
编写于
7月 14, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 14, 2023
浏览文件
操作
浏览文件
下载
差异文件
!20879 【开发自提单】优化加解密算法库开发指南和api文档代码
Merge pull request !20879 from 胡啸天/master
上级
0a53e2d3
868f5778
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
430 addition
and
384 deletion
+430
-384
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
...application-dev/reference/apis/js-apis-cryptoFramework.md
+35
-35
zh-cn/application-dev/security/cryptoFramework-guidelines.md
zh-cn/application-dev/security/cryptoFramework-guidelines.md
+395
-349
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
浏览文件 @
69d20154
...
...
@@ -342,7 +342,7 @@ buffer数组。
### 属性
**系统能力:**
SystemCapability.Security.CryptoFramework
**系统能力:**
SystemCapability.Security.CryptoFramework
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------ | ---- | ---- | ---------------------------- |
...
...
@@ -426,7 +426,7 @@ console.info("key hex:" + uint8ArrayToShowStr(encodedKey.data)); // 输出全
### 属性
**系统能力:**
SystemCapability.Security.CryptoFramework
**系统能力:**
SystemCapability.Security.CryptoFramework
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------ | ---- | ---- | ---------------------------- |
...
...
@@ -475,7 +475,7 @@ console.info("ecc item --- p: " + p.toString(16));
### 属性
**系统能力:**
SystemCapability.Security.CryptoFramework
**系统能力:**
SystemCapability.Security.CryptoFramework
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------ | ---- | ---- | ---------------------------- |
...
...
@@ -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
"
);
...
...
@@ -1572,7 +1572,7 @@ doFinal(data: DataBlob, callback: AsyncCallback\<DataBlob>): void
(2)在RSA、SM2非对称加解密中,doFinal加/解密本次传入的数据,通过注册回调函数获取加密或者解密数据。如果数据量较大,可以多次调用doFinal,拼接结果得到完整的明文/密文。
> **说明:**
> **说明:**
>
> 1. 对称加解密中,调用doFinal标志着一次加解密流程已经完成,即[Cipher](#cipher)实例的状态被清除,因此当后续开启新一轮加解密流程时,需要重新调用[init()](init-2)并传入完整的参数列表进行初始化<br/>(比如即使是对同一个Cipher实例,采用同样的对称密钥,进行加密然后解密,则解密中调用init的时候仍需填写params参数,而不能直接省略为null)。
> 2. 如果遇到解密失败,需检查加解密数据和[init](#init-2)时的参数是否匹配,包括GCM模式下加密得到的authTag是否填入解密时的GcmParamsSpec等。
...
...
@@ -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
);
}
}
});
...
...
zh-cn/application-dev/security/cryptoFramework-guidelines.md
浏览文件 @
69d20154
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录