Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Extract SignatureValue from Signed XML

See more XML Digital Signatures Examples

Demonstrates how to extract the signature value from signed XML.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    String sFilePath
    Handle hoSb
    Boolean iSuccess
    String sBase64Sig
    Variant vXml
    Handle hoXml
    Variant vXSigVal
    Handle hoXSigVal
    String sTemp1
    Boolean bTemp1

    // This example will work with the following signed XML, which as been reformatted for readability.

    // <?xml version="1.0" encoding="utf-8"?>
    // <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    //     <SOAP-ENV:Header>
    //         <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1">
    //             <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    //                 <ds:SignedInfo>
    //                     <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
    //                         <InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse SOAP-ENV"/>
    //                     </ds:CanonicalizationMethod>
    //                     <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
    //                     <ds:Reference URI="#Body">
    //                         <ds:Transforms>
    //                             <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    //                         </ds:Transforms>
    //                         <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
    //                         <ds:DigestValue>OwgHPZNfDkXnZsjpfzXqAcT3RV3HzmTsEy2bP44FJ0M=</ds:DigestValue>
    //                     </ds:Reference>
    //                 </ds:SignedInfo>
    //                 <ds:SignatureValue>C+7FWngU....DJFBcdg==</ds:SignatureValue>
    //                 <ds:KeyInfo>
    //                     <ds:KeyValue>
    //                         <ds:RSAKeyValue>
    //                             <ds:Modulus>sXeRhM55P13.....NAcibRw==</ds:Modulus>
    //                             <ds:Exponent>AQAB</ds:Exponent>
    //                         </ds:RSAKeyValue>
    //                     </ds:KeyValue>
    //                 </ds:KeyInfo>
    //             </ds:Signature>
    //         </wsse:Security>
    //     </SOAP-ENV:Header>
    //     <SOAP-ENV:Body xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12" SOAP-SEC:id="Body">
    //         <z:FooBar xmlns:z="http://example.com"/>
    //     </SOAP-ENV:Body>
    // </SOAP-ENV:Envelope>

    // -----------------------------------------------------------------------------------------
    // There are a number of ways we can get the contents of the  <ds:SignatureValue>...</ds:SignatureValue>

    Move "qa_data/xml_dsig_testing/sample_to_show_how_to_extract_sig.xml" To sFilePath

    // If you know there will only be a single SignatureValue in the XML, you don't need to parse XML.
    // Just do quick and simple string search..
    // For example:
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSb
    If (Not(IsComObjectCreated(hoSb))) Begin
        Send CreateComObject of hoSb
    End
    Get ComLoadFile Of hoSb sFilePath "utf-8" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load file."
        Procedure_Return
    End

    Get ComGetBetween Of hoSb "SignatureValue>" "</" To sBase64Sig
    Showln "base64Sig = " sBase64Sig

    // -----------------------------------------------------------------------------------------
    // If the XML might contain multiple signatures, but the signatures will always be located in the 
    // same place, then you can (beforehand) copy a sample signed XML into Chilkat's online tool
    // at Generate Parsing Code from XML
    // to get the path to the SignatureValue.  For example, the line of code generated for the SignatureValue
    // for the above XML is:
    // string ds_SignatureValue = xml.GetChildContent("SOAP-ENV:Header|wsse:Security|ds:Signature|ds:SignatureValue");

    // So you can simply use that path..
    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Get ComLoadXmlFile Of hoXml sFilePath To iSuccess
    // Assume success..

    Get ComGetChildContent Of hoXml "SOAP-ENV:Header|wsse:Security|ds:Signature|ds:SignatureValue" To sBase64Sig
    Showln "base64Sig = " sBase64Sig

    // -----------------------------------------------------------------------------------------
    // Or perhaps you don't know where the signature is located in the XML.
    // You can search for the tag..
    Get pvComObject of hoXml to vXml
    Get ComSearchForTag Of hoXml vXml "*:SignatureValue" To vXSigVal
    If (IsComObject(vXSigVal)) Begin
        Get Create (RefClass(cComChilkatXml)) To hoXSigVal
        Set pvComObject Of hoXSigVal To vXSigVal
    End
    Get ComLastMethodSuccess Of hoXml To bTemp1
    If (bTemp1 = True) Begin
        Get ComContent Of hoXSigVal To sTemp1
        Showln "base64Sig = " sTemp1
        Send Destroy of hoXSigVal
    End
    Else Begin
        Showln "No SignatureValue found."
    End



End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.