Xbase++
Xbase++
Get PDF Signer Certs
See more PDF Signatures Examples
This example demonstrates how to validate the signatures in a PDF and also shows how to getChilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oPdf
LOCAL oSigInfo
LOCAL nNumSignatures
LOCAL nValidated
LOCAL oCert
LOCAL i
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oPdf := CreateObject("Chilkat.Pdf")
// Load a PDF that has cryptographic signatures to be validated
nSuccess := oPdf:LoadFile("qa_data/pdf/sign_testing_1/helloSigned2.pdf")
IF (nSuccess == 0)
? oPdf:LastErrorText
oPdf:destroy()
RETURN
ENDIF
// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
oSigInfo := CreateObject("Chilkat.JsonObject")
// Iterate over each signature and validate each.
nNumSignatures := oPdf:NumSignatures
nValidated := 0
oCert := CreateObject("Chilkat.Cert")
i := 0
DO WHILE i < nNumSignatures
nValidated := oPdf:VerifySignature(i, oSigInfo)
? "Signature " + Str(i) + " validated: " + Str(nValidated)
// After calling VerifySignature, you can get the signer certificate by calling
// GetSignerCert with the same index.
nSuccess := oPdf:GetSignerCert(i, oCert)
IF (nSuccess != 0)
? "PDF signer certificate: " + oCert:SubjectDN
ENDIF
i := i + 1
ENDDO
? "Finished."
oPdf:destroy()
oSigInfo:destroy()
oCert:destroy()