未验证 提交 aff65486 编写于 作者: O openharmony_ci 提交者: Gitee

!11758 【开发自提单】修复doc中算法库框架对应告警

Merge pull request !11758 from wutiantian_gitee/master
...@@ -1181,6 +1181,7 @@ getEncoded() : DataBlob ...@@ -1181,6 +1181,7 @@ getEncoded() : DataBlob
**示例:** **示例:**
```js ```js
let key; // key为使用非对称密钥生成器生成的非对称密钥,此处省略生成过程
console.info("key format:" + key.format); console.info("key format:" + key.format);
console.info("key algName:" + key.algName); console.info("key algName:" + key.algName);
var encodedKey = key.getEncoded(); var encodedKey = key.getEncoded();
...@@ -1234,6 +1235,7 @@ clearMem() : void ...@@ -1234,6 +1235,7 @@ clearMem() : void
**示例:** **示例:**
```js ```js
let key; // key为使用非对称密钥生成器生成的keyPair中的prikey
key.clearMem(); key.clearMem();
``` ```
...@@ -1560,7 +1562,8 @@ convertKey(pubKey : DataBlob, priKey : DataBlob, callback : AsyncCallback\<KeyPa ...@@ -1560,7 +1562,8 @@ convertKey(pubKey : DataBlob, priKey : DataBlob, callback : AsyncCallback\<KeyPa
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let pubKey; // X.509规范、DER格式的公钥数据,此处省略数据。
let priKey; // PKCS#8规范、DER格式的私钥数据,此处省略数据。
let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator("ECC256"); let asyKeyGenerator = cryptoFramework.createAsyKeyGenerator("ECC256");
asyKeyGenerator.convertKey(pubKey, priKey, (err, keyPair) => { asyKeyGenerator.convertKey(pubKey, priKey, (err, keyPair) => {
if (err) { if (err) {
...@@ -1987,6 +1990,7 @@ cipher.doFinal(data) ...@@ -1987,6 +1990,7 @@ cipher.doFinal(data)
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let plan = "This is rsa cipher test!";
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2"); let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2");
let cipher = cryptoFramework.createCipher("RSA1024|PKCS1"); let cipher = cryptoFramework.createCipher("RSA1024|PKCS1");
rsaGenerator.generateKeyPair(function (err, keyPair) { rsaGenerator.generateKeyPair(function (err, keyPair) {
...@@ -2005,6 +2009,7 @@ rsaGenerator.generateKeyPair(function (err, keyPair) { ...@@ -2005,6 +2009,7 @@ rsaGenerator.generateKeyPair(function (err, keyPair) {
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let plan = "This is rsa cipher test!";
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2"); let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2");
let cipher = cryptoFramework.createCipher("RSA1024|PKCS1"); let cipher = cryptoFramework.createCipher("RSA1024|PKCS1");
let keyGenPromise = rsaGenerator.generateKeyPair(); let keyGenPromise = rsaGenerator.generateKeyPair();
...@@ -2166,20 +2171,37 @@ sign(data : DataBlob) : Promise\<DataBlob> ...@@ -2166,20 +2171,37 @@ sign(data : DataBlob) : Promise\<DataBlob>
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2"); function stringToUint8Array(str) {
let signer = cryptoFramework.createSign("RSA1024|PKCS1|SHA256"); var arr = [];
rsaGenerator.generateKeyPair(function (err, keyPair) { for (var i = 0, j = str.length; i < j; ++i) {
globalKeyPair = keyPair; arr.push(str.charCodeAt(i));
let priKey = globalKeyPair.priKey; }
signer.init(priKey, function (err, data) { var tmpArray = new Uint8Array(arr);
signer.update(input1, function (err, data) { return tmpArray;
signer.sign(input2, function (err, data) { }
SignMessageBlob = data;
console.info("sign output is " + SignMessageBlob.data); 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示例:** **promise示例:**
...@@ -2187,21 +2209,41 @@ rsaGenerator.generateKeyPair(function (err, keyPair) { ...@@ -2187,21 +2209,41 @@ rsaGenerator.generateKeyPair(function (err, keyPair) {
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let rsaGenerator = cryptoFramework.createAsyKeyGenerator("RSA1024|PRIMES_2"); import cryptoFramework from "@ohos.security.cryptoFramework"
let signer = cryptoFramework.createSign("RSA1024|PKCS1|SHA256");
let keyGenPromise = rsaGenerator.generateKeyPair(); function stringToUint8Array(str) {
keyGenPromise.then( keyPair => { var arr = [];
globalKeyPair = keyPair; for (var i = 0, j = str.length; i < j; ++i) {
let priKey = globalKeyPair.priKey; arr.push(str.charCodeAt(i));
return signer.init(priKey); }
}).then(() => { var tmpArray = new Uint8Array(arr);
return signer.update(input1); return tmpArray;
}).then(() => { }
return signer.sign(input2);
}).then(dataBlob => { let plan1 = "This is Sign test plan1";
SignMessageBlob = dataBlob; let plan2 = "This is Sign test plan1";
console.info("sign output is " + SignMessageBlob.data); 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 ## cryptoFramework.createVerify
...@@ -2451,6 +2493,8 @@ generateSecret(priKey : PriKey, pubKey : PubKey) : Promise\<DataBlob> ...@@ -2451,6 +2493,8 @@ generateSecret(priKey : PriKey, pubKey : PubKey) : Promise\<DataBlob>
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let globalKeyPair; // 生成的密钥对,此处省略生成过程
let keyAgreement = cryptoFramework.createKeyAgreement("ECC256"); let keyAgreement = cryptoFramework.createKeyAgreement("ECC256");
keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey, function (err, secret) { keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey, function (err, secret) {
if (err) { if (err) {
...@@ -2466,6 +2510,7 @@ keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey, function ...@@ -2466,6 +2510,7 @@ keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey, function
```javascript ```javascript
import cryptoFramework from "@ohos.security.cryptoFramework" import cryptoFramework from "@ohos.security.cryptoFramework"
let globalKeyPair; // 生成的密钥对,此处省略生成过程
let keyAgreement = cryptoFramework.createKeyAgreement("ECC256"); let keyAgreement = cryptoFramework.createKeyAgreement("ECC256");
let keyAgreementPromise = keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey); let keyAgreementPromise = keyAgreement.generateSecret(globalKeyPair.priKey, globalKeyPair.pubKey);
keyAgreementPromise.then((secret) => { keyAgreementPromise.then((secret) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册