HarmonyOS 鸿蒙Next createX509Cert 创建的证书信息无法获取
HarmonyOS 鸿蒙Next createX509Cert 创建的证书信息无法获取
let encodingBlob: cryptoCert.EncodingBlob = {
data: certBytes,
encodingFormat: cryptoCert.EncodingFormat.FORMAT_DER
}
cryptoCert.createX509Cert(encodingBlob).then(x509Cert => {
console.log(“createX509Cert success”);
resolve(x509Cert)
}, error => {
console.log("createX509Cert failed, errCode: " + error.code + ", errMsg: " + error.message);
reject(error)
});
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
certBytes:服务器返回的证书数据,在java中可以成功创建证书,也可以获取证书的信息,用于下次RSA获取公钥进行加密,但是ARKTS里我用createX509Cert 创建的证书getPublicKey() .getEncoded() 得到的是undefined,algName和format也是undefined,有哪位大神知道是什么情况吗?
关于HarmonyOS 鸿蒙Next createX509Cert 创建的证书信息无法获取的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
希望HarmonyOS能继续加强在安全性方面的研发,保护用户的隐私和数据安全。
参考以下案例:
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’ +
‘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: certFramework.EncodingFormat.FORMAT_PEM
};
certFramework.createX509Cert(encodingBlob).then(x509Cert => {
console.log(‘createX509Cert success’);
}).catch((error: BusinessError) => {
console.error('createX509Cert failed, errCode: ’ + error.code + ', errMsg: ’ + error.message);
});
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>