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 = FileUtils.getAssetsTempFile(context, "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(context);
}

// Add digital signature certificate in pdf file as trusted certificate.
CPDFDocument document = new CPDFDocument(context);
document.open(FileUtils.getAssetsTempFile(context, "Signed.pdf"));
CPDFSignature signature = document.getPdfSignature(0);
CPDFSigner signer = signature.getSignerArr()[0];
CPDFX509 cpdfx509 = signer.getCert();

boolean result = cpdfx509.addToTrustedCertificates(context);
KOTLIN
// Add the certificate in the local storage as a trusted certificate.
val certFilePath: String = FileUtils.getAssetsTempFile(context, "Certificate.pfx")
val password = "ComPDFKit"
if (CPDFSignature.checkPKCS12Password(certFilePath, password)) {
  val x509 = CPDFSignature.getX509ByPKCS12Cert(certFilePath, password)
  //  Add your certificate to the trust path.
  val result = x509.addToTrustedCertificates(context)
}

// Add digital signature certificate in pdf file as trusted certificate.
val document = CPDFDocument(context)
document.open(FileUtils.getAssetsTempFile(context, "Signed.pdf"))
val signature = document.getPdfSignature(0)
val signer = signature.signerArr[0]
val cpdfx509 = signer.cert

val result = cpdfx509.addToTrustedCertificates(context)