Skip to content
Guides

Trust Certificate

Trusting certificates involve two steps:

  1. Specify the trust path (folder) for certificates. This path serves as the location where certificates are placed when they are trusted. Additionally, when checking the trustworthiness of certificates, the SDK will look for the corresponding certificates within this folder. Please ensure that this path is valid. If the path does not exist or is inaccessible, the ComPDFKit SDK will not automatically create the trust path folder.
  2. Execute the method to trust certificates, and the certificates will be added to the trust path.

This example shows how to trust certificates:

java
// Add the certificate in the local storage as a trusted certificate.
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");
}