On this page
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:
swift
// Verify digital certificates
//
// To verify the trustworthiness of a certificate, you need to verify that all certificates in the certificate chain are trustworthy.
//
// In ComPDFKit, this progress is automatic.
//
// You should first call "signature.verifySignature(with: document)"。
// Then you can check the properties. "CPDFSignatureCertificate.IsTrusted"
//
if let url = URL(string: pdfPath) {
let document = CPDFDocument(url: url)
if let signatures = document?.signatures {
for signature in signatures {
signature.verifySignature(with: document)
if let signer = signature.signers.first, let certificate = signer.certificates.first {
var isCertTrusted = true
if !signer.isCertTrusted {
isCertTrusted = false
}
}
}
}
}
objective-c
// Verify digital certificates
//
// To verify the trustworthiness of a certificate, you need to verify that all certificates in the certificate chain are trustworthy.
//
// In ComPDFKit, this progress is automatic.
//
// You should first call "signature.verifySignature(with: document)"。
// Then you can check the properties "isCertTrusted"
//
NSURL *url = [NSURL fileURLWithPath:@"file path"];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
NSArray *signatures = [document signatures];
for (CPDFSignature *signature in signatures) {
[sign verifySignatureWithDocument:document];
CPDFSigner *signer = signature.signers.firstObject;
BOOL isCertTrusted = YES;
if (!signer.isCertTrusted) {
isCertTrusted = NO;
}
}