Sample code for 30+ languages & platforms
DataFlex

Verify XML Digital Signature

See more XML Digital Signatures Examples

Verifies XML signatures in an XML file.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vSbXml
    Handle hoSbXml
    Handle hoDsig
    Integer i
    Boolean iBVerifyReferenceDigests
    Boolean iBVerified
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
    If (Not(IsComObjectCreated(hoSbXml))) Begin
        Send CreateComObject of hoSbXml
    End
    Get ComLoadFile Of hoSbXml "qa_data/xml_dsig_verify/csioz_sample.xml" "utf-8" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Failed to load XML file."
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatXmlDSig)) To hoDsig
    If (Not(IsComObjectCreated(hoDsig))) Begin
        Send CreateComObject of hoDsig
    End

    // First load the XML containing the signatures to be verified.
    Get pvComObject of hoSbXml to vSbXml
    Get ComLoadSignatureSb Of hoDsig vSbXml To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoDsig To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // It's possible that an XML document can contain multiple signatures.
    // Each can be verified as follows:
    Move 0 To i
    While (i < (ComNumSignatures(hoDsig)))
        // Select the Nth signature by setting the Selector property.
        Set ComSelector Of hoDsig To i

        // The bVerifyReferenceDigests argument determines if we want
        // to also verify each reference digest.  If set to False,
        // then only the SignedInfo part of the Signature is verified.
        Move True To iBVerifyReferenceDigests
        Get ComVerifySignature Of hoDsig iBVerifyReferenceDigests To iBVerified
        Showln "Signature " (i + 1) " verified = " iBVerified

        Move (i + 1) To i
    Loop



End_Procedure