Sample code for 30+ languages & platforms
Xbase++

Verify XML Digital Signature

See more XML Digital Signatures Examples

Verifies XML signatures in an XML file.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSbXml
LOCAL oDsig
LOCAL i
LOCAL nBVerifyReferenceDigests
LOCAL nBVerified

nSuccess := 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oSbXml := CreateObject("Chilkat.StringBuilder")
nSuccess := oSbXml:LoadFile("qa_data/xml_dsig_verify/csioz_sample.xml", "utf-8")
IF (nSuccess != 1)
    ? "Failed to load XML file."
    oSbXml:destroy()
    RETURN
ENDIF

oDsig := CreateObject("Chilkat.XmlDSig")

//  First load the XML containing the signatures to be verified.
nSuccess := oDsig:LoadSignatureSb(oSbXml)
IF (nSuccess != 1)
    ? oDsig:LastErrorText
    oSbXml:destroy()
    oDsig:destroy()
    RETURN
ENDIF

//  It's possible that an XML document can contain multiple signatures.
//  Each can be verified as follows:
i := 0
DO WHILE i < oDsig:NumSignatures
    //  Select the Nth signature by setting the Selector property.
    oDsig:Selector := i

    //  The bVerifyReferenceDigests argument determines if we want
    //  to also verify each reference digest.  If set to 0,
    //  then only the SignedInfo part of the Signature is verified.
    nBVerifyReferenceDigests := 1
    nBVerified := oDsig:VerifySignature(nBVerifyReferenceDigests)
    ? "Signature " + Str(i + 1) + " verified = " + Str(nBVerified)

    i := i + 1
ENDDO

oSbXml:destroy()
oDsig:destroy()