Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Node.js Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Node.js) Decrypt a govtalk.gov.uk SOAP GovTalkMessage

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

Install Chilkat for Node.js and Electron using npm at

Chilkat npm packages for Node.js

Chilkat npm packages for Electron

on Windows, Linux, MacOSX, and ARM

var os = require('os');
if (os.platform() == 'win32') {  
    if (os.arch() == 'ia32') {
        var chilkat = require('@chilkat/ck-node11-win-ia32');
    } else {
        var chilkat = require('@chilkat/ck-node11-win64'); 
    }
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('@chilkat/ck-node11-arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('@chilkat/ck-node11-linux32');
    } else {
        var chilkat = require('@chilkat/ck-node11-linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('@chilkat/ck-node11-macosx');
}

function chilkatExample() {

    // 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...

    var xml = new chilkat.Xml();
    var success = xml.LoadXmlFile("qa_data/xml/govTalkMessageResponse.xml");
    if (success == false) {
        console.log(xml.LastErrorText);
        return;
    }

    var Body = xml.GetChildContent("Body|Message|Body");
    console.log(Body);

    var cert = new chilkat.Cert();
    success = cert.LoadPfxFile("qa_data/pfx/govTalkMessage_aaa.pfx","aaa");
    if (success == false) {
        console.log(cert.LastErrorText);
        return;
    }

    var crypt = new chilkat.Crypt2();
    crypt.CryptAlgorithm = "pki";
    success = crypt.SetDecryptCert(cert);
    if (success == false) {
        console.log(crypt.LastErrorText);
        return;
    }

    var bd = new chilkat.BinData();
    // Append the bytes to bd.
    success = bd.AppendEncoded(Body,"base64");

    // Decrypt in-place.
    success = crypt.DecryptBd(bd);
    if (success == false) {
        console.log(crypt.LastErrorText);
        return;
    }

    // Save the decrypted data to a file.
    success = bd.WriteFile("qa_output/out.dat");

    // If the decrypted data is non-text (binary) then we can examine it in an encoding, such as hex:
    console.log("Decrypted bytes as hex: " + bd.GetEncoded("hex"));

}

chilkatExample();

 

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