Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
aff65486
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看板
未验证
提交
aff65486
编写于
11月 24, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11758 【开发自提单】修复doc中算法库框架对应告警
Merge pull request !11758 from wutiantian_gitee/master
上级
6efb0549
c7277088
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
72 addition
and
27 deletion
+72
-27
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
...application-dev/reference/apis/js-apis-cryptoFramework.md
+72
-27
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
浏览文件 @
aff65486
...
...
@@ -1181,6 +1181,7 @@ getEncoded() : DataBlob
**示例:**
```
js
let
key
;
// key为使用非对称密钥生成器生成的非对称密钥,此处省略生成过程
console
.
info
(
"
key format:
"
+
key
.
format
);
console
.
info
(
"
key algName:
"
+
key
.
algName
);
var
encodedKey
=
key
.
getEncoded
();
...
...
@@ -1234,6 +1235,7 @@ clearMem() : void
**示例:**
```
js
let
key
;
// key为使用非对称密钥生成器生成的keyPair中的prikey
key
.
clearMem
();
```
...
...
@@ -1560,7 +1562,8 @@ convertKey(pubKey : DataBlob, priKey : DataBlob, callback : AsyncCallback\<KeyPa
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
pubKey
;
// X.509规范、DER格式的公钥数据,此处省略数据。
let
priKey
;
// PKCS#8规范、DER格式的私钥数据,此处省略数据。
let
asyKeyGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
ECC256
"
);
asyKeyGenerator
.
convertKey
(
pubKey
,
priKey
,
(
err
,
keyPair
)
=>
{
if
(
err
)
{
...
...
@@ -1987,6 +1990,7 @@ cipher.doFinal(data)
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
plan
=
"
This is rsa cipher test!
"
;
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
let
cipher
=
cryptoFramework
.
createCipher
(
"
RSA1024|PKCS1
"
);
rsaGenerator
.
generateKeyPair
(
function
(
err
,
keyPair
)
{
...
...
@@ -2005,6 +2009,7 @@ rsaGenerator.generateKeyPair(function (err, keyPair) {
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
plan
=
"
This is rsa cipher test!
"
;
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
let
cipher
=
cryptoFramework
.
createCipher
(
"
RSA1024|PKCS1
"
);
let
keyGenPromise
=
rsaGenerator
.
generateKeyPair
();
...
...
@@ -2166,20 +2171,37 @@ sign(data : DataBlob) : Promise\<DataBlob>
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
let
signer
=
cryptoFramework
.
createSign
(
"
RSA1024|PKCS1|SHA256
"
);
rsaGenerator
.
generateKeyPair
(
function
(
err
,
keyPair
)
{
globalKeyPair
=
keyPair
;
let
priKey
=
globalKeyPair
.
priKey
;
signer
.
init
(
priKey
,
function
(
err
,
data
)
{
signer
.
update
(
input1
,
function
(
err
,
data
)
{
signer
.
sign
(
input2
,
function
(
err
,
data
)
{
SignMessageBlob
=
data
;
console
.
info
(
"
sign output is
"
+
SignMessageBlob
.
data
);
function
stringToUint8Array
(
str
)
{
var
arr
=
[];
for
(
var
i
=
0
,
j
=
str
.
length
;
i
<
j
;
++
i
)
{
arr
.
push
(
str
.
charCodeAt
(
i
));
}
var
tmpArray
=
new
Uint8Array
(
arr
);
return
tmpArray
;
}
let
plan1
=
"
This is Sign test plan1
"
;
let
plan2
=
"
This is Sign test plan1
"
;
let
input1
=
{
data
:
stringToUint8Array
(
plan1
)
};
let
input2
=
{
data
:
stringToUint8Array
(
plan2
)
};
let
globalKeyPair
;
// 用于保存密钥对象
function
signMessageCallback
()
{
let
rsaGenerator
=
cfm
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
let
signer
=
cfm
.
createSign
(
"
RSA1024|PKCS1|SHA256
"
);
rsaGenerator
.
generateKeyPair
(
function
(
err
,
keyPair
)
{
globalKeyPair
=
keyPair
;
let
priKey
=
globalKeyPair
.
priKey
;
signer
.
init
(
priKey
,
function
(
err
,
data
)
{
signer
.
update
(
input1
,
function
(
err
,
data
)
{
signer
.
sign
(
input2
,
function
(
err
,
data
)
{
SignMessageBlob
=
data
;
AlertDialog
.
show
({
message
:
"
res
"
+
SignMessageBlob
.
data
});
});
});
});
});
}
);
}
```
**promise示例:**
...
...
@@ -2187,21 +2209,41 @@ rsaGenerator.generateKeyPair(function (err, keyPair) {
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
rsaGenerator
=
cryptoFramework
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
let
signer
=
cryptoFramework
.
createSign
(
"
RSA1024|PKCS1|SHA256
"
);
let
keyGenPromise
=
rsaGenerator
.
generateKeyPair
();
keyGenPromise
.
then
(
keyPair
=>
{
globalKeyPair
=
keyPair
;
let
priKey
=
globalKeyPair
.
priKey
;
return
signer
.
init
(
priKey
);
}).
then
(()
=>
{
return
signer
.
update
(
input1
);
}).
then
(()
=>
{
return
signer
.
sign
(
input2
);
}).
then
(
dataBlob
=>
{
SignMessageBlob
=
dataBlob
;
console
.
info
(
"
sign output is
"
+
SignMessageBlob
.
data
);
});
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
function
stringToUint8Array
(
str
)
{
var
arr
=
[];
for
(
var
i
=
0
,
j
=
str
.
length
;
i
<
j
;
++
i
)
{
arr
.
push
(
str
.
charCodeAt
(
i
));
}
var
tmpArray
=
new
Uint8Array
(
arr
);
return
tmpArray
;
}
let
plan1
=
"
This is Sign test plan1
"
;
let
plan2
=
"
This is Sign test plan1
"
;
let
input1
=
{
data
:
stringToUint8Array
(
plan1
)
};
let
input2
=
{
data
:
stringToUint8Array
(
plan2
)
};
let
globalKeyPair
;
// 用于保存密钥对象
function
signMessagePromise
()
{
let
rsaGenerator
=
cfm
.
createAsyKeyGenerator
(
"
RSA1024|PRIMES_2
"
);
let
signer
=
cfm
.
createSign
(
"
RSA1024|PKCS1|SHA256
"
);
let
keyGenPromise
=
rsaGenerator
.
generateKeyPair
();
keyGenPromise
.
then
(
keyPair
=>
{
globalKeyPair
=
keyPair
;
let
priKey
=
globalKeyPair
.
priKey
;
return
signer
.
init
(
priKey
);
}).
then
(()
=>
{
return
signer
.
update
(
input1
);
}).
then
(()
=>
{
return
signer
.
sign
(
input2
);
}).
then
(
dataBlob
=>
{
SignMessageBlob
=
dataBlob
;
console
.
info
(
"
sign output is
"
+
SignMessageBlob
.
data
);
AlertDialog
.
show
({
message
:
"
output
"
+
SignMessageBlob
.
data
});
});
}
```
## cryptoFramework.createVerify
...
...
@@ -2451,6 +2493,8 @@ generateSecret(priKey : PriKey, pubKey : PubKey) : Promise\<DataBlob>
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
globalKeyPair
;
// 生成的密钥对,此处省略生成过程
let
keyAgreement
=
cryptoFramework
.
createKeyAgreement
(
"
ECC256
"
);
keyAgreement
.
generateSecret
(
globalKeyPair
.
priKey
,
globalKeyPair
.
pubKey
,
function
(
err
,
secret
)
{
if
(
err
)
{
...
...
@@ -2466,6 +2510,7 @@ keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey, function
```
javascript
import
cryptoFramework
from
"
@ohos.security.cryptoFramework
"
let
globalKeyPair
;
// 生成的密钥对,此处省略生成过程
let
keyAgreement
=
cryptoFramework
.
createKeyAgreement
(
"
ECC256
"
);
let
keyAgreementPromise
=
keyAgreement
.
generateSecret
(
globalKeyPair
.
priKey
,
globalKeyPair
.
pubKey
);
keyAgreementPromise
.
then
((
secret
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录