Skip to content

信任证书

信任证书分为两个步骤:

  1. SDK内部会指定一个文件夹作为信任路径用来放置信任证书。执行信任证书的方法,证书将会被添加到信任路径下。在检查证书是否可信时会在该文件夹下寻找对应证书。
  2. 执行信任证书的方法,证书将会被添加到信任路径下。

信任证书的关键代码如下:

C#
// 将本地存储中的证书添加为可信任证书
String certFilePath = rootDir+"/certificate/Certificate.pfx";
String password = "ComPDFKit";
if (CPDFSignature.checkPKCS12Password(certFilePath, password)) {
    CPDFX509 x509 = CPDFSignature.getX509ByPKCS12Cert(certFilePath, password);
    // Add your certificate to the trust path.
    boolean result = x509.addToTrustedCertificates(rootDir + "/trusted","compdfkit.pem");
    if (result) {
        System.out.println("add to trusted certificates success");
    }else {
        System.out.println("add to trusted certificates fail");
    }
}
// Add digital signature certificate in pdf file as trusted certificate.
CPDFSignature signature = document.getPdfSignature(0);
CPDFSigner signer = signature.getSignerArr()[0];
CPDFX509 cpdfx509 = signer.getCert();

boolean result = cpdfx509.addToTrustedCertificates(rootDir + "/trusted","compdfkit.pem");
if (result) {
    System.out.println("add to trusted certificates success");
}else {
    System.out.println("add to trusted certificates fail");
}