From 2036e3036d23ed24d5a7d85307370fc5305d43ee Mon Sep 17 00:00:00 2001 From: haixiangw Date: Fri, 28 Jul 2023 21:12:42 -0700 Subject: [PATCH] =?UTF-8?q?[=E5=90=8C=E6=AD=A54.0-beta2]cert=20getSerialNu?= =?UTF-8?q?mber=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: haixiangw --- .../reference/apis/js-apis-cert.md | 48 ++++++++++++++++++- .../security/cert-guidelines.md | 2 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-cert.md b/zh-cn/application-dev/reference/apis/js-apis-cert.md index 5366247084..45cb1aab4d 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-cert.md +++ b/zh-cn/application-dev/reference/apis/js-apis-cert.md @@ -553,12 +553,16 @@ cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) { }); ``` -### getSerialNumber +### getSerialNumber(deprecated) getSerialNumber() : number 表示获取X509证书序列号。 +> **说明:** +> +> 从API version 9开始支持,从API version 10开始废弃,建议使用[getCertSerialNumber](#getcertserialnumber10)替代。 + **系统能力:** SystemCapability.Security.Cert **返回值**: @@ -589,6 +593,48 @@ cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) { }); ``` +### getCertSerialNumber10+ + +getCertSerialNumber() : bigint + +表示获取X509证书序列号。 + +**系统能力:** SystemCapability.Security.Cert + +**返回值**: + +| 类型 | 说明 | +| ------ | ------------------ | +| bigint | 表示X509证书序列号 | + +**错误码:** + +| 错误码ID | 错误信息 | +| -------- | ------------------------------------------------- | +| 19020002 | runtime error. | + +**示例:** + +```js +import cryptoCert from '@ohos.security.cert'; + +// 证书二进制数据,需业务自行赋值 +let encodingData = null; +let encodingBlob = { + data: encodingData, + // 根据encodingData的格式进行赋值,支持FORMAT_PEM和FORMAT_DER + encodingFormat: cryptoCert.EncodingFormat.FORMAT_PEM +}; +cryptoCert.createX509Cert(encodingBlob, function (error, x509Cert) { + if (error != null) { + console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message); + } else { + console.log("createX509Cert success"); + let serialNumber = x509Cert.getCertSerialNumber(); + } +}); +``` + ### getIssuerName getIssuerName() : DataBlob diff --git a/zh-cn/application-dev/security/cert-guidelines.md b/zh-cn/application-dev/security/cert-guidelines.md index 12a7b66c63..9946b47cb3 100755 --- a/zh-cn/application-dev/security/cert-guidelines.md +++ b/zh-cn/application-dev/security/cert-guidelines.md @@ -34,7 +34,7 @@ | X509Cert | getPublicKey() : cryptoFramework.PubKey | 获取证书公钥 | | X509Cert | checkValidityWithDate(date: string) : void | 校验证书有效期 | | X509Cert | getVersion() : number | 获取证书版本 | -| X509Cert | getSerialNumber() : number | 获取证书序列号 | +| X509Cert | getCertSerialNumber() : bigint10+| 获取证书序列号 | | X509Cert | getIssuerName() : DataBlob | 获取证书颁发者名称 | | X509Cert | getSubjectName() : DataBlob | 获取证书主体名称 | | X509Cert | getNotBeforeTime() : string | 获取证书有效期起始时间 | -- GitLab