Skip to content
Guides

Verify Digital Certificates

When verifying digital certificates, the system automatically checks the trustworthiness of all certificates in the certificate chain and also verifies whether the certificates have expired. Only certificates that are both not expired and considered trustworthy in the entire certificate chain are considered trusted digital certificates.

This example shows how to verify digital certificates:

java
// Verify whether the specified certificate file is trusted.
// 
// To verify the trustworthiness of a certificate, you need to validate that all certificates in the certificate chain are trustworthy.
String certFilePath = FileUtils.getAssetsTempFile(context, "Certificate.pfx");
String password = "ComPDFKit";
if (CPDFSignature.checkPKCS12Password(certFilePath, password)) {
  CPDFX509 x509 = CPDFSignature.getX509ByPKCS12Cert(certFilePath, password);
  boolean isTrusted = x509.checkCertificateIsTrusted(context);
  if (isTrusted) {
    // Certificate is trusted.
  } else {
    // Certificate is trusted.
  }
}
kotlin
// Verify whether the specified certificate file is trusted.
// 
// To verify the trustworthiness of a certificate, you need to validate that all certificates in the certificate chain are trustworthy.。
val certFilePath: String = FileUtils.getAssetsTempFile(context, "Certificate.pfx")
val password = "ComPDFKit"
if (CPDFSignature.checkPKCS12Password(certFilePath, password)) {
  val x509 = CPDFSignature.getX509ByPKCS12Cert(certFilePath, password)
  val isTrusted = x509.checkCertificateIsTrusted(context)
  if (isTrusted) {
    // Certificate is trusted。
  } else {
    // Certificate is not trusted.
  }
}