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
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) Decrypt a govtalk.gov.uk SOAP GovTalkMessage

Demonstrates how to decrypt the content contained in the XML of a GovTalkMessage SOAP response.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoXml
    Boolean iSuccess
    String sBody
    Variant vCert
    Handle hoCert
    Handle hoCrypt
    Variant vBd
    Handle hoBd
    String sTemp1

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

    // The GovTalkMessage response looks something like this:

    // <?xml version="1.0" encoding="utf-8"?>
    // <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
    //   <EnvelopeVersion>3.1</EnvelopeVersion>
    //   <Header>
    //     <MessageDetails>
    //       <Class>CSSZ_DZDPN</Class>
    //       <Qualifier>request</Qualifier>
    //       <Function>submit</Function>
    //       <TransactionID />
    //       <AuditID />
    //       <CorrelationID>aaaaa</CorrelationID>
    //       <ResponseEndPoint PollInterval="0" />
    //       <Transformation>XML</Transformation>
    //       <GatewayTest />
    //       <GatewayTimestamp />
    //     </MessageDetails>
    //     <SenderDetails>
    //       <IDAuthentication>
    //         <SenderID />
    //         <Authentication>
    //           <Method>clear</Method>
    //           <Role />
    //           <Value />
    //         </Authentication>
    //       </IDAuthentication>
    //       <X509Certificate />
    //       <EmailAddress>somebody@example.com</EmailAddress>
    //     </SenderDetails>
    //   </Header>
    //   <GovTalkDetails>
    //     <Keys>
    //       <Key Type="vars">9999999999</Key>
    //     </Keys>
    //     <GatewayAdditions>
    //       <Source>VREP</Source>
    //     </GatewayAdditions>
    //   </GovTalkDetails>
    //   <Body>
    //     <Message xmlns="http://www.cssz.cz/XMLSchema/envelope" version="1.2" eType="DZDPN20">
    //       <Header>
    //         <Signature xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">MIIJ0A ... UMw=
    // </Signature>
    //         <Vendor productName="some product name" version="2019" />
    //       </Header>
    //       <Body xmlns:dt="urn:schemas-microsoft-com:datatypes" encrypted="yes" contentEncoding="gzip" dt:dt="bin.base64">MIIF2w ... N2vW</Body>
    //     </Message>
    //   </Body>
    // </GovTalkMessage>

    // We want to get the content of the Body and decrypt it.

    // First, let's get the content of the Body XML element, which is a base64 string starting with MIIF2w...

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Get ComLoadXmlFile Of hoXml "qa_data/xml/govTalkMessageResponse.xml" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoXml To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComGetChildContent Of hoXml "Body|Message|Body" To sBody
    Showln sBody

    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get ComLoadPfxFile Of hoCert "qa_data/pfx/govTalkMessage_aaa.pfx" "aaa" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
    If (Not(IsComObjectCreated(hoCrypt))) Begin
        Send CreateComObject of hoCrypt
    End
    Set ComCryptAlgorithm Of hoCrypt To "pki"
    Get pvComObject of hoCert to vCert
    Get ComSetDecryptCert Of hoCrypt vCert To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatBinData)) To hoBd
    If (Not(IsComObjectCreated(hoBd))) Begin
        Send CreateComObject of hoBd
    End
    // Append the bytes to bd.
    Get ComAppendEncoded Of hoBd sBody "base64" To iSuccess

    // Decrypt in-place.
    Get pvComObject of hoBd to vBd
    Get ComDecryptBd Of hoCrypt vBd To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Save the decrypted data to a file.
    Get ComWriteFile Of hoBd "qa_output/out.dat" To iSuccess

    // If the decrypted data is non-text (binary) then we can examine it in an encoding, such as hex:
    Get ComGetEncoded Of hoBd "hex" To sTemp1
    Showln "Decrypted bytes as hex: " sTemp1


End_Procedure

 

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