Xbase++
Xbase++
Get Certificates within XML Signature
See more XML Digital Signatures Examples
Demonstrates how to get the certificates contained within an XML signature.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oSbXml
LOCAL oDsig
LOCAL i
LOCAL oSaCerts
LOCAL oCert
LOCAL nBVerifyReferenceDigests
LOCAL nBVerified
LOCAL j
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oSbXml := CreateObject("Chilkat.StringBuilder")
// Load XML containing one or more signatures.
nSuccess := oSbXml:LoadFile("qa_data/xml_dsig_valid_samples/multipleSigners/sp.pdf.XAdES.xml", "utf-8")
IF (nSuccess == 0)
? "Failed to load the XML file.."
oSbXml:destroy()
RETURN
ENDIF
oDsig := CreateObject("Chilkat.XmlDSig")
// First load the XML containing the signatures to be verified.
// Note that this particular Signature already contains the RSA public key that will be used
// for verification.
nSuccess := oDsig:LoadSignatureSb(oSbXml)
IF (nSuccess == 0)
? oDsig:LastErrorText
oSbXml:destroy()
oDsig:destroy()
RETURN
ENDIF
// For each signature, verify and also get the certificate(s) contained within each Signature.
i := 0
oSaCerts := CreateObject("Chilkat.StringArray")
oCert := CreateObject("Chilkat.Cert")
? "numSignatures = " + Str(oDsig:NumSignatures)
DO WHILE i < oDsig:NumSignatures
// Select the Nth signature by setting the Selector property.
oDsig:Selector := i
nBVerifyReferenceDigests := 1
nBVerified := oDsig:VerifySignature(nBVerifyReferenceDigests)
? "Signature " + Str(i + 1) + " verified = " + Str(nBVerified)
// Get the certificates embedded in this signature.
oSaCerts:Clear()
nSuccess := oDsig:GetCerts(oSaCerts)
IF (nSuccess == 1)
j := 0
DO WHILE j < oSaCerts:Count
nSuccess := oCert:LoadFromBase64(oSaCerts:GetString(j))
IF (nSuccess == 1)
? " " + oCert:SubjectDN
ENDIF
j := j + 1
ENDDO
ENDIF
i := i + 1
ENDDO
oSbXml:destroy()
oDsig:destroy()
oSaCerts:destroy()
oCert:destroy()