Sample code for 30+ languages & platforms
Xbase++

Verify XAdES with External File Reference

See more XML Digital Signatures Examples

Demonstrates how to validate an XML digital signature that contains a reference to an external file. (This is one way of doing it..)

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSbXml
LOCAL oValidator
LOCAL i
LOCAL nValid

nSuccess := 0

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

//  Load the XAdES file to be validated..
oSbXml := CreateObject("Chilkat.StringBuilder")
nSuccess := oSbXml:LoadFile("qa_data/xml_dsig_valid_samples/externalFile/test.pdf.XAdES", "utf-8")
IF (nSuccess == 0)
    ? "Failed to load XAdES input file."
    oSbXml:destroy()
    RETURN
ENDIF

oValidator := CreateObject("Chilkat.XmlDSig")

//  Specify a set of absolute or relative directory paths to be searched for any external file references.
//  Directory paths are separated by semicolon chars.
oValidator:ExternalRefDirs := "qa_data/externalFiles;qa_data/xml_dsig_valid_samples/externalFile;c:/someOtherDir"

nSuccess := oValidator:LoadSignatureSb(oSbXml)
IF (nSuccess == 0)
    ? oValidator:LastErrorText
    oSbXml:destroy()
    oValidator:destroy()
    RETURN
ENDIF

//  Validate signatures as usual..
i := 0
DO WHILE i < oValidator:NumSignatures
    oValidator:Selector := i

    nValid := oValidator:VerifySignature(1)
    ? "Signature " + Str(i + 1) + " and all reference digests OK = " + Str(nValid)

    i := i + 1
ENDDO

oSbXml:destroy()
oValidator:destroy()