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

!24098 【证书算法库】cert api文档ArkTS适配

Merge pull request !24098 from HaixiangW/master
......@@ -4,14 +4,13 @@
> **说明:**
>
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 以下示例代码片段仅适用于JS语言开发。
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```javascript
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
```ts
import certFramework from '@ohos.security.cert';
import cryptoFramework from '@ohos.security.cryptoFramework';
```
## CertResult
......@@ -150,21 +149,40 @@ createX509Cert(inStream : EncodingBlob, callback : AsyncCallback\<X509Cert>) : v
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
}
});
```
......@@ -197,20 +215,40 @@ createX509Cert(inStream : EncodingBlob) : Promise\<X509Cert>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
console.log("createX509Cert success");
}, error => {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
certFramework.createX509Cert(encodingBlob).then(x509Cert => {
console.log('createX509Cert success');
}).catch((error: BusinessError) => {
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -241,30 +279,58 @@ verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
// 业务需通过上级X509Cert证书对象的getPublicKey获取PubKey
let pubKey = null;
x509Cert.verify(pubKey, function (error, data) {
if (error != null) {
console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
console.log('createX509Cert success');
// 业务需通过上级X509Cert证书对象(或当前证书对象为自签名的证书)的getPublicKey获取PubKey
try {
let pubKey = x509Cert.getPublicKey();
// 验证证书签名
x509Cert.verify(pubKey, (err, data) => {
if (err == null) {
console.log('verify success');
} else {
console.log("verify success");
console.error('verify failed, errCode: ' + err.code + ', errMsg: ' + err.message);
}
});
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getPublicKey failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -297,27 +363,52 @@ verify(key : cryptoFramework.PubKey) : Promise\<void>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
console.log("createX509Cert success");
// 业务可通过上级X509Cert证书对象的getPublicKey获取PubKey
let pubKey = null;
certFramework.createX509Cert(encodingBlob).then(x509Cert => {
console.log('createX509Cert success');
try {
// 业务需通过上级X509Cert证书对象(或当前证书对象为自签名的证书)的getPublicKey获取PubKey
let pubKey = x509Cert.getPublicKey();
x509Cert.verify(pubKey).then(result => {
console.log("verify success");
}, error => {
console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
console.log('verify success');
}).catch((error: BusinessError) => {
console.error('verify failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
}, error => {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
} catch (err) {
console.error('get public key failed');
}
}).catch((error: BusinessError) => {
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -345,26 +436,45 @@ getEncoded(callback : AsyncCallback\<EncodingBlob>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
x509Cert.getEncoded(function (error, data) {
console.log('createX509Cert success');
x509Cert.getEncoded((error, data) => {
if (error != null) {
console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("getEncoded success");
console.log('getEncoded success');
}
});
}
......@@ -395,25 +505,45 @@ getEncoded() : Promise\<EncodingBlob>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' +
'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' +
'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' +
'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' +
'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' +
'0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' +
'BetUokslUfjT6+s/X4ByaxycAA==\n' +
'-----END CERTIFICATE-----\n';
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
console.log("createX509Cert success");
certFramework.createX509Cert(encodingBlob).then(x509Cert => {
console.log('createX509Cert success');
x509Cert.getEncoded().then(result => {
console.log("getEncoded success");
}, error => {
console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
console.log('getEncoded success');
}).catch((error: BusinessError) => {
console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
}, error => {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
}).catch((error: BusinessError) => {
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -440,27 +570,46 @@ getPublicKey() : cryptoFramework.PubKey
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
let pubKey = null;
console.log('createX509Cert success');
try {
pubKey = x509Cert.getPublicKey();
let pubKey = x509Cert.getPublicKey();
} catch (error) {
console.log("getPublicKey failed, errCode: " + error.code + ", errMsg: " + error.message);
let e: BusinessError = error as BusinessError;
console.error('getPublicKey failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
......@@ -491,28 +640,49 @@ checkValidityWithDate(date: string) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
let date = "150527000001Z";
console.log('createX509Cert success');
// 校验证书有效期
let date = '231001000001Z';
// Verify the certificate validity period.
try {
x509Cert.checkValidityWithDate(date);
} catch (error) {
console.log("checkValidityWithDate failed, errCode: " + error.code + ", errMsg: " + error.message);
let e: BusinessError = error as BusinessError;
console.error('checkValidityWithDate failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
......@@ -534,21 +704,39 @@ getVersion() : number
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
let version = x509Cert.getVersion();
}
});
......@@ -574,21 +762,40 @@ getSerialNumber() : number
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
let serialNumber = x509Cert.getSerialNumber();
}
});
......@@ -616,22 +823,47 @@ getCertSerialNumber() : bigint
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let serialNumber = x509Cert.getCertSerialNumber();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getCertSerialNumber failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -660,22 +892,47 @@ getIssuerName() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let issuerName = x509Cert.getIssuerName();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getIssuerName failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -704,22 +961,47 @@ getSubjectName() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let subjectName = x509Cert.getSubjectName();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSubjectName failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -748,22 +1030,47 @@ getNotBeforeTime() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let notBefore = x509Cert.getNotBeforeTime();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -792,22 +1099,48 @@ getNotAfterTime() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let notAfter = x509Cert.getNotAfterTime();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getNotAfterTime failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -836,22 +1169,48 @@ getSignature() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let signature = x509Cert.getSignature();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignature failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -880,22 +1239,48 @@ getSignatureAlgName() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let sigAlgName = x509Cert.getSignatureAlgName();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignatureAlgName failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -924,22 +1309,47 @@ getSignatureAlgOid() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let sigAlgOid = x509Cert.getSignatureAlgOid();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignatureAlgOid failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -968,22 +1378,47 @@ getSignatureAlgParams() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let sigAlgParams = x509Cert.getSignatureAlgParams();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignatureAlgParams failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1011,22 +1446,47 @@ getKeyUsage() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let keyUsage = x509Cert.getKeyUsage();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getKeyUsage failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1055,22 +1515,47 @@ getExtKeyUsage() : DataArray
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let extKeyUsage = x509Cert.getExtKeyUsage();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1091,21 +1576,40 @@ getBasicConstraints() : number
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
let basicConstraints = x509Cert.getBasicConstraints();
}
});
......@@ -1135,22 +1639,47 @@ getSubjectAltNames() : DataArray
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let subjectAltNames = x509Cert.getSubjectAltNames();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSubjectAltNames failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1179,22 +1708,47 @@ getIssuerAltNames() : DataArray
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
console.log('createX509Cert success');
try {
let issuerAltNames = x509Cert.getIssuerAltNames();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getIssuerAltNames failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1223,23 +1777,48 @@ getItem(itemType: CertItemType) : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
// 证书二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n' +
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n' +
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n' +
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n' +
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n' +
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n' +
'Qw==\n' +
'-----END CERTIFICATE-----\n';
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) {
certFramework.createX509Cert(encodingBlob, (error, x509Cert) => {
if (error != null) {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Cert success");
let tbs = x509Cert.getItem(cryptoCert.CertItemType.CERT_ITEM_TYPE_TBS);
let pubKey = x509Cert.getItem(cryptoCert.CertItemType.CERT_ITEM_TYPE_PUBLIC_KEY);
console.log('createX509Cert success');
try {
let tbs = x509Cert.getItem(certFramework.CertItemType.CERT_ITEM_TYPE_TBS);
let pubKey = x509Cert.getItem(certFramework.CertItemType.CERT_ITEM_TYPE_PUBLIC_KEY);
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getItem failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1267,21 +1846,33 @@ createCertExtension(inStream : EncodingBlob, callback : AsyncCallback\<CertExten
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// 证书扩展域段二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let extData = new Uint8Array([
0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D,
0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03,
0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55,
0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C,
0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86,
0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0,
0xD9, 0xE4
]);
let encodingBlob: certFramework.EncodingBlob = {
data: extData,
// 根据encodingData的格式进行赋值,仅支持FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_DER
};
cryptoCert.createCertExtension(encodingBlob, function (error, certExt) {
certFramework.createCertExtension(encodingBlob, (error, certExt) => {
if (error != null) {
console.log("createCertExtension failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createCertExtension success");
console.log('createCertExtension success');
}
});
```
......@@ -1314,20 +1905,33 @@ createCertExtension(inStream : EncodingBlob) : Promise\<CertExtension>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 证书扩展域段二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let extData = new Uint8Array([
0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D,
0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03,
0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55,
0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C,
0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86,
0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0,
0xD9, 0xE4
]);
let encodingBlob: certFramework.EncodingBlob = {
data: extData,
// 根据encodingData的格式进行赋值,仅支持FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_DER
};
cryptoCert.createCertExtension(encodingBlob).then(certExt => {
console.log("createCertExtension success");
}, error => {
console.log("createCertExtension failed, errCode: " + error.code + ", errMsg: " + error.message);
certFramework.createCertExtension(encodingBlob).then(certExt => {
console.log('createCertExtension success');
}).catch((error: BusinessError) => {
console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -1359,22 +1963,40 @@ getEncoded() : EncodingBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 证书扩展域段二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let extData = new Uint8Array([
0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D,
0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03,
0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55,
0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C,
0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86,
0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0,
0xD9, 0xE4
]);
let encodingBlob: certFramework.EncodingBlob = {
data: extData,
// 根据encodingData的格式进行赋值,仅支持FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_DER
};
cryptoCert.createCertExtension(encodingBlob, function (error, certExt) {
certFramework.createCertExtension(encodingBlob, (error, certExt) => {
if (error != null) {
console.log("createCertExtension failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createCertExtension success");
let encodingBlob = certExt.getEncoded()
console.log('createCertExtension success');
try {
let extEncodedBlob = certExt.getEncoded();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('ext getEncoded failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1409,22 +2031,40 @@ getOidList(valueType : ExtensionOidType) : DataArray
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 证书扩展域段二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let extData = new Uint8Array([
0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D,
0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03,
0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55,
0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C,
0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86,
0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0,
0xD9, 0xE4
]);
let encodingBlob: certFramework.EncodingBlob = {
data: extData,
// 根据encodingData的格式进行赋值,仅支持FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_DER
};
cryptoCert.createCertExtension(encodingBlob, function (error, certExt) {
certFramework.createCertExtension(encodingBlob, (error, certExt) => {
if (error != null) {
console.log("createCertExtension failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createCertExtension success");
let oidList = certExt.getOidList(cryptoCert.ExtensionOidType.EXTENSION_OID_TYPE_ALL)
console.log('createCertExtension success');
try {
let oidList = certExt.getOidList(certFramework.ExtensionOidType.EXTENSION_OID_TYPE_ALL);
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('ext getOidList failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1460,26 +2100,44 @@ getEntry(valueType: ExtensionEntryType, oid : DataBlob) : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 证书扩展域段二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let extData = new Uint8Array([
0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D,
0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03,
0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55,
0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C,
0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86,
0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0,
0xD9, 0xE4
]);
let encodingBlob: certFramework.EncodingBlob = {
data: extData,
// 根据encodingData的格式进行赋值,仅支持FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_DER
};
cryptoCert.createCertExtension(encodingBlob, function (error, certExt) {
certFramework.createCertExtension(encodingBlob, (error, certExt) => {
if (error != null) {
console.log("createCertExtension failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createCertExtension success");
let oid = new Uint8Array([0x31, 0x2e, 0x32, 0x2e, 0x38, 0x2e, 0x31])
let oidBlob = {
console.log('createCertExtension success');
let oid = new Uint8Array([0x32, 0x2e, 0x35, 0x2e, 0x32, 0x39, 0x2e, 0x31, 0x35]);
let oidBlob: certFramework.DataBlob = {
data: oid
}
let entry = certExt.getEntry(cryptoCert.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, oidBlob)
try {
let entry = certExt.getEntry(certFramework.ExtensionEntryType.EXTENSION_ENTRY_TYPE_ENTRY, oidBlob);
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('ext getEntry failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1509,22 +2167,39 @@ checkCA() : number
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 证书扩展域段二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let extData = new Uint8Array([
0x30, 0x40, 0x30, 0x0F, 0x06, 0x03, 0x55, 0x1D,
0x13, 0x01, 0x01, 0xFF, 0x04, 0x05, 0x30, 0x03,
0x01, 0x01, 0xFF, 0x30, 0x0E, 0x06, 0x03, 0x55,
0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04, 0x03,
0x02, 0x01, 0xC6, 0x30, 0x1D, 0x06, 0x03, 0x55,
0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE0, 0x8C,
0x9B, 0xDB, 0x25, 0x49, 0xB3, 0xF1, 0x7C, 0x86,
0xD6, 0xB2, 0x42, 0x87, 0x0B, 0xD0, 0x6B, 0xA0,
0xD9, 0xE4
]);
let encodingBlob: certFramework.EncodingBlob = {
data: extData,
// 根据encodingData的格式进行赋值,仅支持FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_DER
};
cryptoCert.createCertExtension(encodingBlob, function (error, certExt) {
certFramework.createCertExtension(encodingBlob, (error, certExt) => {
if (error != null) {
console.log("createCertExtension failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createCertExtension failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createCertExtension success");
let res = certExt.checkCA()
console.log('createCertExtension success');
try {
let res = certExt.checkCA();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('ext checkCA failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1552,21 +2227,39 @@ createX509Crl(inStream : EncodingBlob, callback : AsyncCallback\<X509Crl>) : voi
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
}
});
```
......@@ -1599,20 +2292,39 @@ createX509Crl(inStream : EncodingBlob) : Promise\<X509Crl>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
console.log("createX509Crl success");
}, error => {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
certFramework.createX509Crl(encodingBlob).then(x509Crl => {
console.log('createX509Crl success');
}).catch((error: BusinessError) => {
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -1642,29 +2354,68 @@ isRevoked(cert : X509Cert) : boolean
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
let certData = '-----BEGIN CERTIFICATE-----\n' +
'MIIBLzCB1QIUO/QDVJwZLIpeJyPjyTvE43xvE5cwCgYIKoZIzj0EAwIwGjEYMBYG\n' +
'A1UEAwwPRXhhbXBsZSBSb290IENBMB4XDTIzMDkwNDExMjAxOVoXDTI2MDUzMDEx\n' +
'MjAxOVowGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYI\n' +
'KoZIzj0DAQcDQgAEHjG74yMIueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTa\n' +
'tUsU0i/sePnrKglj2H8Abbx9PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEA\n' +
'0ce/fvA4tckNZeB865aOApKXKlBjiRlaiuq5mEEqvNACIQDPD9WyC21MXqPBuRUf\n' +
'BetUokslUfjT6+s/X4ByaxycAA==\n' +
'-----END CERTIFICATE-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
let certEncodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
// 业务需自行生成X509Cert证书对象
let x509Cert = null;
console.log('createX509Crl success');
// Create an X509Cert instance.
certFramework.createX509Cert(certEncodingBlob, (error, x509Cert) => {
if (error == null) {
try {
let revokedFlag = x509Crl.isRevoked(x509Cert);
} catch (error) {
console.log("isRevoked failed, errCode: " + error.code + ", errMsg: " + error.message);
let e: BusinessError = error as BusinessError;
console.error('isRevoked failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
}
});
```
......@@ -1684,21 +2435,39 @@ getType() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
let type = x509Crl.getType();
}
});
......@@ -1728,26 +2497,44 @@ getEncoded(callback : AsyncCallback\<EncodingBlob>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
x509Crl.getEncoded(function (error, data) {
console.log('createX509Crl success');
x509Crl.getEncoded((error, data) => {
if (error != null) {
console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("getEncoded success");
console.log('getEncoded success');
}
});
}
......@@ -1778,25 +2565,44 @@ getEncoded() : Promise\<EncodingBlob>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
console.log("createX509Crl success");
certFramework.createX509Crl(encodingBlob).then(x509Crl => {
console.log('createX509Crl success');
x509Crl.getEncoded().then(result => {
console.log("getEncoded success");
}, error => {
console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
console.log('getEncoded success');
}).catch((error: BusinessError) => {
console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
}, error => {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
}).catch((error: BusinessError) => {
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -1823,31 +2629,126 @@ verify(key : cryptoFramework.PubKey, callback : AsyncCallback\<void>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
```ts
import certFramework from '@ohos.security.cert';
import cryptoFramework from '@ohos.security.cryptoFramework';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
let pubKeyData = new Uint8Array([
0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D,
0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE,
0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C,
0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66,
0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0,
0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C,
0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65,
0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA,
0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01,
0x00, 0x01
]);
let priKeyData = new Uint8Array([
0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x02, 0x61, 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01,
0x00, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED,
0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67,
0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20,
0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4,
0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23,
0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22,
0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14,
0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91,
0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x5A, 0xCF, 0x0F,
0xF5, 0xA6, 0x1C, 0x19, 0x65, 0x8C, 0x94, 0x40, 0xF6, 0x84, 0x28, 0x74, 0x40, 0x42, 0x34, 0xDE,
0xC3, 0x00, 0x5E, 0x72, 0x4D, 0x96, 0xE9, 0x4C, 0xBD, 0xC9, 0xDB, 0x14, 0x9F, 0xD5, 0xBB, 0xA9,
0x0C, 0x20, 0xC2, 0xBE, 0x7A, 0x80, 0x89, 0xEC, 0x99, 0x04, 0xF0, 0xEE, 0x7B, 0x83, 0x20, 0x1D,
0x37, 0x19, 0x55, 0x85, 0xF6, 0x8E, 0x3B, 0xFB, 0x16, 0xF3, 0xD3, 0x6F, 0xEE, 0x73, 0x12, 0x53,
0xCA, 0x77, 0xD7, 0x6C, 0x29, 0xF5, 0x08, 0xA3, 0x09, 0x01, 0x0B, 0x00, 0x05, 0x57, 0xAD, 0x4D,
0xF0, 0x92, 0xB2, 0x5A, 0x8B, 0x19, 0x09, 0x81, 0x86, 0xFE, 0x66, 0xB9, 0x33, 0x88, 0x28, 0xF3,
0x37, 0x73, 0x09, 0x5F, 0xD7, 0xC9, 0xC6, 0xFA, 0x13, 0x74, 0xFE, 0xAE, 0x53, 0xA9, 0x71, 0x67,
0xCE, 0x3A, 0xE6, 0x8D, 0x35, 0xD1, 0xB8, 0xFD, 0x6F, 0x0D, 0x43, 0xC2, 0xD1, 0x02, 0x41, 0x00,
0xF7, 0x33, 0xE5, 0x6C, 0x29, 0x5A, 0x30, 0x58, 0xA4, 0x52, 0x65, 0xA0, 0x39, 0xC2, 0xE8, 0xAE,
0x5F, 0xA3, 0x2D, 0x0C, 0x65, 0xB1, 0x7B, 0xFD, 0x92, 0xBF, 0x47, 0x87, 0x97, 0x40, 0xCB, 0x54,
0xF9, 0xBB, 0x50, 0x27, 0x70, 0x51, 0xD0, 0xD8, 0x48, 0x0D, 0xC6, 0x47, 0x60, 0xF8, 0x4E, 0x0A,
0x32, 0x76, 0x6D, 0xA4, 0xBA, 0x40, 0xE5, 0x58, 0xF8, 0x4A, 0x39, 0x4E, 0xF8, 0x3F, 0x4E, 0x2D,
0x02, 0x41, 0x00, 0xE4, 0x23, 0x2A, 0x5F, 0x59, 0xCF, 0x7C, 0x91, 0x24, 0x0D, 0xA2, 0x44, 0x17,
0xCD, 0x37, 0xDE, 0x1F, 0x53, 0x4D, 0x33, 0x9F, 0x90, 0x4D, 0xD9, 0x72, 0x64, 0x25, 0xBA, 0xAB,
0x47, 0x91, 0xC4, 0x99, 0x95, 0x86, 0xB5, 0x8A, 0xEA, 0x77, 0xF7, 0x64, 0x72, 0x5E, 0xB7, 0xBB,
0x16, 0xA1, 0x64, 0xA4, 0xE1, 0x2D, 0x76, 0x6D, 0xEF, 0xB1, 0x5E, 0xD6, 0x17, 0xE8, 0xAA, 0xB6,
0xA0, 0xD9, 0x85, 0x02, 0x41, 0x00, 0xDF, 0xC8, 0x5B, 0x28, 0x4F, 0x47, 0x15, 0xFD, 0x28, 0xC4,
0x6E, 0xBB, 0x5D, 0x8E, 0xD4, 0x95, 0x06, 0x7E, 0xF1, 0x89, 0x07, 0x86, 0x64, 0x78, 0x69, 0x20,
0x3F, 0xE0, 0xBF, 0x4C, 0x28, 0xC6, 0x04, 0x4D, 0x4D, 0x82, 0x66, 0x6B, 0xAA, 0x64, 0x20, 0xD6,
0x57, 0x68, 0xC6, 0xA0, 0x02, 0x05, 0xB9, 0x28, 0xFC, 0x98, 0xE3, 0x03, 0x5C, 0x9B, 0xEE, 0x29,
0x43, 0x37, 0xFA, 0x03, 0x55, 0x01, 0x02, 0x40, 0x69, 0x5B, 0x7C, 0x24, 0x10, 0xDB, 0xEB, 0x91,
0x33, 0xEF, 0x3F, 0xF2, 0xE6, 0x73, 0x15, 0xCB, 0xF4, 0xF7, 0x89, 0x7D, 0xBF, 0xC0, 0xEA, 0xD2,
0xF3, 0x2B, 0x20, 0xE9, 0x76, 0x54, 0x55, 0x13, 0x50, 0x42, 0x67, 0xB5, 0xCB, 0x73, 0xC0, 0xF7,
0x75, 0x62, 0x04, 0x30, 0x21, 0xAC, 0xAF, 0xD8, 0x44, 0xF4, 0xE1, 0x04, 0x02, 0x7D, 0x61, 0x92,
0x84, 0x99, 0x02, 0x10, 0x64, 0xCB, 0x1F, 0xE9, 0x02, 0x41, 0x00, 0xAB, 0x4B, 0x7D, 0x90, 0x7C,
0x57, 0x08, 0x6B, 0xC0, 0x43, 0x72, 0x09, 0x8A, 0x18, 0x35, 0x36, 0x64, 0x9D, 0x84, 0x8D, 0xF1,
0x84, 0x94, 0x48, 0xC6, 0x80, 0x9D, 0xB9, 0xA2, 0x58, 0x0A, 0x4D, 0x0A, 0xCA, 0x1E, 0xD6, 0x05,
0x55, 0x5B, 0xFE, 0xD7, 0xAA, 0x70, 0xED, 0x76, 0xB3, 0x40, 0x2E, 0xA0, 0xB3, 0x32, 0x37, 0xB0,
0xA0, 0xB9, 0x96, 0x2D, 0xC4, 0x70, 0xE9, 0x99, 0x10, 0x67, 0x8D
]);
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
// 业务需通过AsyKeyGenerator生成PubKey
let pubKey = null;
x509Crl.verify(pubKey, function (error, data) {
if (error != null) {
console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
console.log('createX509Crl success');
try {
// Generate the public key by AsyKeyGenerator.
let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3');
console.log('createAsyKeyGenerator success');
let priEncodingBlob: cryptoFramework.DataBlob = {
data: priKeyData,
};
let pubEncodingBlob: cryptoFramework.DataBlob = {
data: pubKeyData,
};
keyGenerator.convertKey(pubEncodingBlob, priEncodingBlob, (e, keyPair) => {
if (e == null) {
console.log('convert key success');
x509Crl.verify(keyPair.pubKey, (err, data) => {
if (err == null) {
console.log('verify success');
} else {
console.log("verify success");
console.error('verify failed, errCode: ' + err.code + ', errMsg: ' + err.message);
}
});
} else {
console.error('convert key failed, message: ' + e.message + 'code: ' + e.code);
}
})
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('get pubKey failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -1880,28 +2781,122 @@ verify(key : cryptoFramework.PubKey) : Promise\<void>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
import cryptoFramework from "@ohos.security.cryptoFramework"
```ts
import certFramework from '@ohos.security.cert';
import cryptoFramework from '@ohos.security.cryptoFramework'
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
let pubKeyData = new Uint8Array([
0x30, 0x81, 0x9F, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01,
0x05, 0x00, 0x03, 0x81, 0x8D, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D,
0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED, 0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE,
0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67, 0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C,
0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20, 0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66,
0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4, 0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0,
0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23, 0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C,
0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22, 0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65,
0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14, 0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA,
0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91, 0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01,
0x00, 0x01
]);
let priKeyData = new Uint8Array([
0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7,
0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x02, 0x61, 0x30, 0x82, 0x02, 0x5D, 0x02, 0x01,
0x00, 0x02, 0x81, 0x81, 0x00, 0xDC, 0x4C, 0x2D, 0x57, 0x49, 0x3D, 0x42, 0x52, 0x1A, 0x09, 0xED,
0x3E, 0x90, 0x29, 0x51, 0xF7, 0x70, 0x15, 0xFE, 0x76, 0xB0, 0xDB, 0xDF, 0xA1, 0x2C, 0x6C, 0x67,
0x95, 0xDA, 0x63, 0x3D, 0x4F, 0x71, 0x48, 0x8C, 0x3E, 0xFA, 0x24, 0x79, 0xE9, 0xF2, 0xF2, 0x20,
0xCB, 0xF1, 0x59, 0x6B, 0xED, 0xC8, 0x72, 0x66, 0x6E, 0x31, 0xD4, 0xF3, 0xCE, 0x0B, 0x12, 0xC4,
0x17, 0x39, 0xB4, 0x52, 0x16, 0xD3, 0xE3, 0xC0, 0xF8, 0x48, 0xB3, 0xF6, 0x40, 0xD5, 0x47, 0x23,
0x30, 0x7F, 0xA7, 0xC5, 0x5A, 0x5A, 0xBB, 0x5C, 0x7B, 0xEF, 0x69, 0xE2, 0x74, 0x35, 0x24, 0x22,
0x25, 0x45, 0x7E, 0xFC, 0xE8, 0xC4, 0x52, 0x65, 0xA0, 0x4E, 0xBC, 0xFD, 0x3F, 0xD9, 0x85, 0x14,
0x8A, 0x5A, 0x93, 0x02, 0x24, 0x6C, 0x19, 0xBA, 0x81, 0xBE, 0x65, 0x2E, 0xCB, 0xBB, 0xE9, 0x91,
0x7B, 0x7C, 0x47, 0xC2, 0x61, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x81, 0x80, 0x5A, 0xCF, 0x0F,
0xF5, 0xA6, 0x1C, 0x19, 0x65, 0x8C, 0x94, 0x40, 0xF6, 0x84, 0x28, 0x74, 0x40, 0x42, 0x34, 0xDE,
0xC3, 0x00, 0x5E, 0x72, 0x4D, 0x96, 0xE9, 0x4C, 0xBD, 0xC9, 0xDB, 0x14, 0x9F, 0xD5, 0xBB, 0xA9,
0x0C, 0x20, 0xC2, 0xBE, 0x7A, 0x80, 0x89, 0xEC, 0x99, 0x04, 0xF0, 0xEE, 0x7B, 0x83, 0x20, 0x1D,
0x37, 0x19, 0x55, 0x85, 0xF6, 0x8E, 0x3B, 0xFB, 0x16, 0xF3, 0xD3, 0x6F, 0xEE, 0x73, 0x12, 0x53,
0xCA, 0x77, 0xD7, 0x6C, 0x29, 0xF5, 0x08, 0xA3, 0x09, 0x01, 0x0B, 0x00, 0x05, 0x57, 0xAD, 0x4D,
0xF0, 0x92, 0xB2, 0x5A, 0x8B, 0x19, 0x09, 0x81, 0x86, 0xFE, 0x66, 0xB9, 0x33, 0x88, 0x28, 0xF3,
0x37, 0x73, 0x09, 0x5F, 0xD7, 0xC9, 0xC6, 0xFA, 0x13, 0x74, 0xFE, 0xAE, 0x53, 0xA9, 0x71, 0x67,
0xCE, 0x3A, 0xE6, 0x8D, 0x35, 0xD1, 0xB8, 0xFD, 0x6F, 0x0D, 0x43, 0xC2, 0xD1, 0x02, 0x41, 0x00,
0xF7, 0x33, 0xE5, 0x6C, 0x29, 0x5A, 0x30, 0x58, 0xA4, 0x52, 0x65, 0xA0, 0x39, 0xC2, 0xE8, 0xAE,
0x5F, 0xA3, 0x2D, 0x0C, 0x65, 0xB1, 0x7B, 0xFD, 0x92, 0xBF, 0x47, 0x87, 0x97, 0x40, 0xCB, 0x54,
0xF9, 0xBB, 0x50, 0x27, 0x70, 0x51, 0xD0, 0xD8, 0x48, 0x0D, 0xC6, 0x47, 0x60, 0xF8, 0x4E, 0x0A,
0x32, 0x76, 0x6D, 0xA4, 0xBA, 0x40, 0xE5, 0x58, 0xF8, 0x4A, 0x39, 0x4E, 0xF8, 0x3F, 0x4E, 0x2D,
0x02, 0x41, 0x00, 0xE4, 0x23, 0x2A, 0x5F, 0x59, 0xCF, 0x7C, 0x91, 0x24, 0x0D, 0xA2, 0x44, 0x17,
0xCD, 0x37, 0xDE, 0x1F, 0x53, 0x4D, 0x33, 0x9F, 0x90, 0x4D, 0xD9, 0x72, 0x64, 0x25, 0xBA, 0xAB,
0x47, 0x91, 0xC4, 0x99, 0x95, 0x86, 0xB5, 0x8A, 0xEA, 0x77, 0xF7, 0x64, 0x72, 0x5E, 0xB7, 0xBB,
0x16, 0xA1, 0x64, 0xA4, 0xE1, 0x2D, 0x76, 0x6D, 0xEF, 0xB1, 0x5E, 0xD6, 0x17, 0xE8, 0xAA, 0xB6,
0xA0, 0xD9, 0x85, 0x02, 0x41, 0x00, 0xDF, 0xC8, 0x5B, 0x28, 0x4F, 0x47, 0x15, 0xFD, 0x28, 0xC4,
0x6E, 0xBB, 0x5D, 0x8E, 0xD4, 0x95, 0x06, 0x7E, 0xF1, 0x89, 0x07, 0x86, 0x64, 0x78, 0x69, 0x20,
0x3F, 0xE0, 0xBF, 0x4C, 0x28, 0xC6, 0x04, 0x4D, 0x4D, 0x82, 0x66, 0x6B, 0xAA, 0x64, 0x20, 0xD6,
0x57, 0x68, 0xC6, 0xA0, 0x02, 0x05, 0xB9, 0x28, 0xFC, 0x98, 0xE3, 0x03, 0x5C, 0x9B, 0xEE, 0x29,
0x43, 0x37, 0xFA, 0x03, 0x55, 0x01, 0x02, 0x40, 0x69, 0x5B, 0x7C, 0x24, 0x10, 0xDB, 0xEB, 0x91,
0x33, 0xEF, 0x3F, 0xF2, 0xE6, 0x73, 0x15, 0xCB, 0xF4, 0xF7, 0x89, 0x7D, 0xBF, 0xC0, 0xEA, 0xD2,
0xF3, 0x2B, 0x20, 0xE9, 0x76, 0x54, 0x55, 0x13, 0x50, 0x42, 0x67, 0xB5, 0xCB, 0x73, 0xC0, 0xF7,
0x75, 0x62, 0x04, 0x30, 0x21, 0xAC, 0xAF, 0xD8, 0x44, 0xF4, 0xE1, 0x04, 0x02, 0x7D, 0x61, 0x92,
0x84, 0x99, 0x02, 0x10, 0x64, 0xCB, 0x1F, 0xE9, 0x02, 0x41, 0x00, 0xAB, 0x4B, 0x7D, 0x90, 0x7C,
0x57, 0x08, 0x6B, 0xC0, 0x43, 0x72, 0x09, 0x8A, 0x18, 0x35, 0x36, 0x64, 0x9D, 0x84, 0x8D, 0xF1,
0x84, 0x94, 0x48, 0xC6, 0x80, 0x9D, 0xB9, 0xA2, 0x58, 0x0A, 0x4D, 0x0A, 0xCA, 0x1E, 0xD6, 0x05,
0x55, 0x5B, 0xFE, 0xD7, 0xAA, 0x70, 0xED, 0x76, 0xB3, 0x40, 0x2E, 0xA0, 0xB3, 0x32, 0x37, 0xB0,
0xA0, 0xB9, 0x96, 0x2D, 0xC4, 0x70, 0xE9, 0x99, 0x10, 0x67, 0x8D
]);
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
console.log("createX509Crl success");
// 业务需通过AsyKeyGenerator生成PubKey
let pubKey = null;
x509Crl.verify(pubKey).then(result => {
console.log("verify success");
}, error => {
console.log("verify failed, errCode: " + error.code + ", errMsg: " + error.message);
certFramework.createX509Crl(encodingBlob).then(x509Crl => {
console.log('createX509Crl success');
try {
// 生成公钥对象
let keyGenerator = cryptoFramework.createAsyKeyGenerator('RSA1024|PRIMES_3');
console.log('createAsyKeyGenerator success');
let priEncodingBlob: cryptoFramework.DataBlob = {
data: priKeyData,
};
let pubEncodingBlob: cryptoFramework.DataBlob = {
data: pubKeyData,
};
keyGenerator.convertKey(pubEncodingBlob, priEncodingBlob).then((keyPair) => {
console.log('convert key success');
x509Crl.verify(keyPair.pubKey).then(result => {
console.log('verify success');
}).catch((error: BusinessError) => {
console.error('verify failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
}).catch((error: BusinessError) => {
console.error('convert key failed, message: ' + error.message + 'code: ' + error.code);
});
}, error => {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('get pubKey failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}).catch((error: BusinessError) => {
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -1921,21 +2916,39 @@ getVersion() : number
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
let version = x509Crl.getVersion();
}
});
......@@ -1965,22 +2978,46 @@ getIssuerName() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let issuerName = x509Crl.getIssuerName();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getIssuerName failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2009,22 +3046,46 @@ getLastUpdate() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let lastUpdate = x509Crl.getLastUpdate();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getLastUpdate failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2053,22 +3114,46 @@ getNextUpdate() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let nextUpdate = x509Crl.getNextUpdate();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getNextUpdate failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2102,27 +3187,46 @@ getRevokedCert(serialNumber : number) : X509CrlEntry
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
// 业务需赋值为对应证书的序列号
console.log('createX509Crl success');
let serialNumber = 1000;
try {
let entry = x509Crl.getRevokedCert(serialNumber);
} catch (error) {
console.log("getRevokedCert failed, errCode: " + error.code + ", errMsg: " + error.message);
let e: BusinessError = error as BusinessError;
console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
......@@ -2157,28 +3261,68 @@ getRevokedCertWithCert(cert : X509Cert) : X509CrlEntry
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书二进制数据,需业务自行赋值
let certData = '-----BEGIN CERTIFICATE-----\n'
'MIIBHTCBwwICA+gwCgYIKoZIzj0EAwIwGjEYMBYGA1UEAwwPRXhhbXBsZSBSb290\n'
'IENBMB4XDTIzMDkwNTAyNDgyMloXDTI2MDUzMTAyNDgyMlowGjEYMBYGA1UEAwwP\n'
'RXhhbXBsZSBSb290IENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHjG74yMI\n'
'ueO7z3T+dyuEIrhxTg2fqgeNB3SGfsIXlsiUfLTatUsU0i/sePnrKglj2H8Abbx9\n'
'PK0tsW/VgqwDIDAKBggqhkjOPQQDAgNJADBGAiEApVZno/Z7WyDc/muRN1y57uaY\n'
'Mjrgnvp/AMdE8qmFiDwCIQCrIYdHVO1awaPgcdALZY+uLQi6mEs/oMJLUcmaag3E\n'
'Qw==\n'
'-----END CERTIFICATE-----\n';
let certEncodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(certData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
// 业务需自行生成X509Cert证书对象
let x509Cert = null;
console.log('createX509Crl success');
// 创建X509证书对象.
certFramework.createX509Cert(certEncodingBlob).then((x509Cert) => {
try {
let entry = x509Crl.getRevokedCertWithCert(x509Cert);
} catch (error) {
console.log("getRevokedCertWithCert failed, errCode: " + error.code + ", errMsg: " + error.message);
let e: BusinessError = error as BusinessError;
console.error('getRevokedCertWithCert failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}).catch((error: BusinessError) => {
console.error('createX509Cert failed, errCode: ' + error.code + ', errMsg: ' + error.message);
})
}
});
```
......@@ -2206,26 +3350,45 @@ getRevokedCerts(callback : AsyncCallback<Array\<X509CrlEntry>>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
x509Crl.getRevokedCerts(function (error, array) {
console.log('createX509Crl success');
x509Crl.getRevokedCerts((error, array) => {
if (error != null) {
console.log("getRevokedCerts failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('getRevokedCerts failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("getRevokedCerts success");
console.log('getRevokedCerts success');
}
});
}
......@@ -2255,25 +3418,44 @@ getRevokedCerts() : Promise<Array\<X509CrlEntry>>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob).then(x509Crl => {
console.log("createX509Crl success");
certFramework.createX509Crl(encodingBlob).then(x509Crl => {
console.log('createX509Crl success');
x509Crl.getRevokedCerts().then(array => {
console.log("getRevokedCerts success");
}, error => {
console.log("getRevokedCerts failed, errCode: " + error.code + ", errMsg: " + error.message);
console.log('getRevokedCerts success');
}).catch((error: BusinessError) => {
console.error('getRevokedCerts failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
}, error => {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
}).catch((error: BusinessError) => {
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
```
......@@ -2301,25 +3483,45 @@ getTbsInfo() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let tbsInfo = x509Crl.getTbsInfo();
} catch (error) {
console.log("getTbsInfo failed, errCode: " + error.code + ", errMsg: " + error.message);
let e: BusinessError = error as BusinessError;
console.error('getTbsInfo failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
......@@ -2349,22 +3551,46 @@ getSignature() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let signature = x509Crl.getSignature();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignature failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2393,22 +3619,46 @@ getSignatureAlgName() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let sigAlgName = x509Crl.getSignatureAlgName();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignatureAlgName failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2437,22 +3687,46 @@ getSignatureAlgOid() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let sigAlgOid = x509Crl.getSignatureAlgOid();
} catch (err) {
let e: BusinessError = err as BusinessError;
console.error('getSignatureAlgOid failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2481,22 +3755,46 @@ getSignatureAlgParams() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n';
// 证书吊销列表二进制数据,需业务自行赋值
let encodingData = null;
let encodingBlob = {
data: encodingData,
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
cryptoCert.createX509Crl(encodingBlob, function (error, x509Crl) {
certFramework.createX509Crl(encodingBlob, (error, x509Crl) => {
if (error != null) {
console.log("createX509Crl failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('createX509Crl failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("createX509Crl success");
console.log('createX509Crl success');
try {
let sigAlgParams = x509Crl.getSignatureAlgParams();
} catch (err) {
let e: BusinessError = error as BusinessError;
console.error('getSignatureAlgParams failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
});
```
......@@ -2531,10 +3829,16 @@ createCertChainValidator(algorithm :string) : CertChainValidator
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
let validator = cryptoCert.createCertChainValidator("PKIX");
try {
let validator = certFramework.createCertChainValidator('PKIX');
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('createCertChainValidator failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
```
## CertChainValidator
......@@ -2583,27 +3887,34 @@ validate(certChain : CertChainData, callback : AsyncCallback\<void>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
let validator = cryptoCert.createCertChainValidator("PKIX");
// 证书链二进制数据,需业务自行赋值
let encodingData = null;
// 证书链包含的证书个数,需业务自行赋值
let certCount = 2;
let certChainData = {
data: encodingData,
count: certCount,
let certChainBuff = new Uint8Array([0x30, 0x82, 0x44]);
let certChainData: certFramework.CertChainData = {
data: certChainBuff,
// 证书链包含的证书个数,需业务自行赋值
count: 2,
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
validator.validate(certChainData, function (error, data) {
try {
let validator = certFramework.createCertChainValidator('PKIX');
validator.validate(certChainData, (error, data) => {
if (error != null) {
console.log("validate failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('validate failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("validate success");
console.log('validate success');
}
});
});
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
```
### validate
......@@ -2643,25 +3954,32 @@ validate(certChain : CertChainData) : Promise\<void>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
let validator = cryptoCert.createCertChainValidator("PKIX");
// 证书链二进制数据,需业务自行赋值
let encodingData = null;
// 证书链包含的证书个数,需业务自行赋值
let certCount = 2;
let certChainData = {
data: encodingData,
count: certCount,
let certChainBuff = new Uint8Array([0x30, 0x82, 0x44]);
let certChainData: certFramework.CertChainData = {
data: certChainBuff,
// 证书链包含的证书个数,需业务自行赋值
count: 2,
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
validator.validate(certChainData).then(result => {
console.log("validate success");
}, error => {
console.log("validate failed, errCode: " + error.code + ", errMsg: " + error.message);
});
try {
let validator = certFramework.createCertChainValidator('PKIX');
validator.validate(certChainData).then(result => {
console.log('validate success');
}).catch((error: BusinessError) => {
console.error('validate failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getNotBeforeTime failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
```
### algorithm
......@@ -2680,11 +3998,17 @@ algorithm : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
let validator = cryptoCert.createCertChainValidator("PKIX");
let algorithm = validator.algorithm;
try {
let validator = certFramework.createCertChainValidator('PKIX');
let algorithm = validator.algorithm;
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('createCertChainValidator failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
```
## X509CrlEntry
......@@ -2715,18 +4039,56 @@ getEncoded(callback : AsyncCallback\<EncodingBlob>) : void
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 业务需通过X509Crl的getRevokedCert相关方法获取X509CrlEntry
let x509CrlEntry = null;
x509CrlEntry.getEncoded(function (error, data) {
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n'
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
certFramework.createX509Crl(encodingBlob, (err, x509Crl) => {
if (err != null) {
console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message);
} else {
console.log('create x509 crl success');
try {
let serialNumber = 1000;
let crlEntry = x509Crl.getRevokedCert(serialNumber);
crlEntry.getEncoded((error, data) => {
if (error != null) {
console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message);
} else {
console.log("getEncoded success");
console.log('getEncoded success');
}
});
});
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
})
```
### getEncoded
......@@ -2753,16 +4115,54 @@ getEncoded() : Promise\<EncodingBlob>
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 业务需通过X509Crl的getRevokedCert相关方法获取X509CrlEntry
let x509CrlEntry = null;
x509CrlEntry.getEncoded().then(result => {
console.log("getEncoded success");
}, error => {
console.log("getEncoded failed, errCode: " + error.code + ", errMsg: " + error.message);
});
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n'
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
certFramework.createX509Crl(encodingBlob, (err, x509Crl) => {
if (err != null) {
console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message);
} else {
console.log('create x509 crl success');
try {
let serialNumber = 1000;
let crlEntry = x509Crl.getRevokedCert(serialNumber);
crlEntry.getEncoded().then(result => {
console.log('getEncoded success');
}).catch((error: BusinessError) => {
console.error('getEncoded failed, errCode: ' + error.code + ', errMsg: ' + error.message);
});
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getRevokedCert failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
})
```
### getSerialNumber
......@@ -2781,12 +4181,50 @@ getSerialNumber() : number
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n'
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
certFramework.createX509Crl(encodingBlob, (err, x509Crl) => {
if (err != null) {
console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message);
} else {
console.log('create x509 crl success');
// 业务需通过X509Crl的getRevokedCert相关方法获取X509CrlEntry
let x509CrlEntry = null;
let serialNumber = x509CrlEntry.getSerialNumber();
try {
let serialNumber = 1000;
let crlEntry = x509Crl.getRevokedCert(serialNumber);
serialNumber = crlEntry.getSerialNumber();
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getRevokedCert or getSerialNumber failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
})
```
### getCertIssuer
......@@ -2812,16 +4250,50 @@ getCertIssuer() : DataBlob
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 业务需通过X509Crl的getRevokedCert相关方法获取X509CrlEntry
let x509CrlEntry = null;
try {
let issuer = x509CrlEntry.getCertIssuer();
} catch (error) {
console.log("getCertIssuer failed, errCode: " + error.code + ", errMsg: " + error.message);
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n'
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
certFramework.createX509Crl(encodingBlob, (err, x509Crl) => {
if (err != null) {
console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message);
} else {
console.log('create x509 crl success');
try {
let serialNumber = 1000;
let crlEntry = x509Crl.getRevokedCert(serialNumber);
let issuer = crlEntry.getCertIssuer();
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getRevokedCert or getCertIssuer failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
})
```
### getRevocationDate
......@@ -2848,14 +4320,48 @@ getRevocationDate() : string
**示例:**
```js
import cryptoCert from '@ohos.security.cert';
```ts
import certFramework from '@ohos.security.cert';
import { BusinessError } from '@ohos.base';
// 业务需通过X509Crl的getRevokedCert相关方法获取X509CrlEntry
let x509CrlEntry = null;
try {
let date = x509CrlEntry.getRevocationDate();
} catch (error) {
console.log("getRevocationDate failed, errCode: " + error.code + ", errMsg: " + error.message);
// string转Uint8Array
function stringToUint8Array(str: string): Uint8Array {
let arr: Array<number> = [];
for (let i = 0, j = str.length; i < j; i++) {
arr.push(str.charCodeAt(i));
}
return new Uint8Array(arr);
}
let crlData = '-----BEGIN X509 CRL-----\n' +
'MIHzMF4CAQMwDQYJKoZIhvcNAQEEBQAwFTETMBEGA1UEAxMKQ1JMIGlzc3VlchcN\n' +
'MTcwODA3MTExOTU1WhcNMzIxMjE0MDA1MzIwWjAVMBMCAgPoFw0zMjEyMTQwMDUz\n' +
'MjBaMA0GCSqGSIb3DQEBBAUAA4GBACEPHhlaCTWA42ykeaOyR0SGQIHIOUR3gcDH\n' +
'J1LaNwiL+gDxI9rMQmlhsUGJmPIPdRs9uYyI+f854lsWYisD2PUEpn3DbEvzwYeQ\n' +
'5SqQoPDoM+YfZZa23hoTLsu52toXobP74sf/9K501p/+8hm4ROMLBoRT86GQKY6g\n' +
'eavsH0Q3\n' +
'-----END X509 CRL-----\n'
let encodingBlob: certFramework.EncodingBlob = {
data: stringToUint8Array(crlData),
// 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER
encodingFormat: certFramework.EncodingFormat.FORMAT_PEM
};
certFramework.createX509Crl(encodingBlob, (err, x509Crl) => {
if (err != null) {
console.error('createX509Crl failed, errCode: ' + err.code + ', errMsg: ' + err.message);
} else {
console.log('create x509 crl success');
try {
let serialNumber = 1000;
let crlEntry = x509Crl.getRevokedCert(serialNumber);
let date = crlEntry.getRevocationDate();
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error('getRevokedCert or getRevocationDate failed, errCode: ' + e.code + ', errMsg: ' + e.message);
}
}
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册