# 证书链校验时从PKCS #12文件构造TrustAnchor对象数组

证书链校验时从PKCS #12文件构造TrustAnchor对象数组。

#### 开发步骤

1.  导入证书模块。
    
2.  基于现有的PKCS #12文件数据，调用cert.createTrustAnchorsWithKeyStore创建X509TrustAnchor数组对象，并返回结果。
    

```
import { cert } from '@kit.DeviceCertificateKit';
import { BusinessError } from '@kit.BasicServicesKit';

function test() {
  // ...
  try {
    cert.createTrustAnchorsWithKeyStore(p12Data, '123456').then((data) => {
      console.info('createTrustAnchorsWithKeyStore result: success, the num of result is :' + data.length);
    }).catch((err: BusinessError) => {
      console.error(`createTrustAnchorsWithKeyStore failed, errCode: ${err.code}, message: ${err.message}`);
    })
  } catch (error) {
    console.error(`createTrustAnchorsWithKeyStore failed, errCode: ${error.code}, message: ${error.message}`);
  }
}
```