Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_SbXml
oleobject loo_Validator
integer i
integer li_Valid

li_Success = 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..
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_SbXml
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_SbXml.LoadFile("qa_data/xml_dsig_valid_samples/externalFile/test.pdf.XAdES","utf-8")
if li_Success = 0 then
    Write-Debug "Failed to load XAdES input file."
    destroy loo_SbXml
    return
end if

loo_Validator = create oleobject
li_rc = loo_Validator.ConnectToNewObject("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.
loo_Validator.ExternalRefDirs = "qa_data/externalFiles;qa_data/xml_dsig_valid_samples/externalFile;c:/someOtherDir"

li_Success = loo_Validator.LoadSignatureSb(loo_SbXml)
if li_Success = 0 then
    Write-Debug loo_Validator.LastErrorText
    destroy loo_SbXml
    destroy loo_Validator
    return
end if

// Validate signatures as usual..
i = 0
do while i < loo_Validator.NumSignatures
    loo_Validator.Selector = i

    li_Valid = loo_Validator.VerifySignature(1)
    Write-Debug "Signature " + string(i + 1) + " and all reference digests OK = " + string(li_Valid)

    i = i + 1
loop


destroy loo_SbXml
destroy loo_Validator