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

PowerBuilder 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

 

 

 

(PowerBuilder) Signed SOAP for www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/ using BinarySecurityToken

Creates a signed SOAP request for www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/ using a BinarySecurityToken.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_XmlToSign
oleobject loo_DtNow
oleobject loo_Gen
oleobject loo_Cert
oleobject loo_XmlCustomKeyInfo
oleobject loo_SbXml
oleobject loo_BdCert
oleobject loo_SbCert64
integer li_NReplaced
oleobject loo_Verifier
integer li_NumSigs
integer li_VerifyIdx
integer li_Verified

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

// Create the following pre-signed SOAP XML:
// Note: We'll be constructing a placeholder for the wseBinarySecurityToken in the soapenv:Header.
// Chilkat will automatically replace the "BinarySecurityToken_Base64Binary_Content" with actual data when signing the XML.

// However: Your application should insert the actual desired timestamp values for wsu:Created and wsuExpires
// Typically this is the current system date/time and a few minutes from the current system date/time.
// The example below shows a 5 minute window.  We'll write code below to insert the current date/time and the current date/time + 5 minutes..

// <?xml version="1.0" encoding="utf-8"?>
// <soapenv:Envelope 
//   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
//   xmlns:scat="www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/"
//   xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
//   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
//   xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
//   xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#">
//     <soapenv:Header xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
//         <wsse:Security soapenv:mustUnderstand="1">
//             <wsse:BinarySecurityToken 
//                   ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
//                   EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
//                   wsu:Id="X509Token">BinarySecurityToken_Base64Binary_Content</wsse:BinarySecurityToken>
//             <wsu:Timestamp wsu:Id="_1">
//                 <wsu:Created>2020-03-20T18:08:19Z</wsu:Created>
//                 <wsu:Expires>2020-03-20T18:13:19Z</wsu:Expires>
//             </wsu:Timestamp>
//         </wsse:Security>
//         <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
//     </soapenv:Header>
//     <soapenv:Body>
//         <scat:getRuoliStruttureOperatore>
//             <scat:codFiscaleOperatore>CLDxxxxxxxxxxxxL</scat:codFiscaleOperatore>
//         </scat:getRuoliStruttureOperatore>
//     </soapenv:Body>
// </soapenv:Envelope>

li_Success = 1
// Create the XML to be signed...
loo_XmlToSign = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
    destroy loo_XmlToSign
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_XmlToSign.Tag = "soapenv:Envelope"
loo_XmlToSign.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
loo_XmlToSign.AddAttribute("xmlns:scat","www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/")
loo_XmlToSign.AddAttribute("xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
loo_XmlToSign.AddAttribute("xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
loo_XmlToSign.AddAttribute("xmlns:ds","http://www.w3.org/2000/09/xmldsig#")
loo_XmlToSign.AddAttribute("xmlns:exc14n","http://www.w3.org/2001/10/xml-exc-c14n#")
loo_XmlToSign.UpdateAttrAt("soapenv:Header",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",1,"soapenv:mustUnderstand","1")
loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3")
loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary")
loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","X509Token")
loo_XmlToSign.UpdateChildContent("soapenv:Header|wsse:Security|wsse:BinarySecurityToken","BinarySecurityToken_Base64Binary_Content")
loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsu:Timestamp",1,"wsu:Id","_1")

// Insert a 5-minute timestampe window.
loo_DtNow = create oleobject
// Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
li_rc = loo_DtNow.ConnectToNewObject("Chilkat.CkDateTime")

loo_DtNow.SetFromCurrentSystemTime()
loo_XmlToSign.UpdateChildContent("soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Created",loo_DtNow.GetAsTimestamp(0))
// Add 5 minutes to the time.
loo_DtNow.AddSeconds(300)
loo_XmlToSign.UpdateChildContent("soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Expires",loo_DtNow.GetAsTimestamp(0))
loo_XmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security[1]",1,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
loo_XmlToSign.UpdateChildContent("soapenv:Body|scat:getRuoliStruttureOperatore|scat:codFiscaleOperatore","CLDxxxxxxxxxxxxL")

Write-Debug "XML to sign:"
Write-Debug loo_XmlToSign.GetXml()

loo_Gen = create oleobject
// Use "Chilkat_9_5_0.XmlDSigGen" for versions of Chilkat < 10.0.0
li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen")

loo_Gen.SigLocation = "soapenv:Envelope|soapenv:Header|wsse:Security"
loo_Gen.SigLocationMod = 0
loo_Gen.SigNamespacePrefix = "ds"
loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
loo_Gen.SignedInfoCanonAlg = "EXCL_C14N"
loo_Gen.SignedInfoDigestMethod = "sha1"

// Set the KeyInfoId before adding references..
loo_Gen.KeyInfoId = "X509KeyId"

// -------- Reference 1 --------
loo_Gen.AddSameDocRef("_1","sha1","EXCL_C14N","","")

// Provide a certificate + private key. (PFX password is test123)
loo_Cert = create oleobject
// Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
if li_Success <> 1 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_XmlToSign
    destroy loo_DtNow
    destroy loo_Gen
    destroy loo_Cert
    return
end if

loo_Gen.SetX509Cert(loo_Cert,1)

loo_Gen.KeyInfoType = "Custom"

// Create the custom KeyInfo XML..
loo_XmlCustomKeyInfo = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_XmlCustomKeyInfo.ConnectToNewObject("Chilkat.Xml")

loo_XmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference"
loo_XmlCustomKeyInfo.AddAttribute("wsu:Id","X509TokenReference")
loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#X509Token")
loo_XmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3")

loo_XmlCustomKeyInfo.EmitXmlDecl = 0
loo_Gen.CustomKeyInfoXml = loo_XmlCustomKeyInfo.GetXml()

// Load XML to be signed...
loo_SbXml = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")

loo_XmlToSign.GetXmlSb(loo_SbXml)

// Update BinarySecurityToken_Base64Binary_Content with the actual X509 of the signing cert.
loo_BdCert = create oleobject
// Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
li_rc = loo_BdCert.ConnectToNewObject("Chilkat.BinData")

loo_Cert.ExportCertDerBd(loo_BdCert)
loo_SbCert64 = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbCert64.ConnectToNewObject("Chilkat.StringBuilder")

loo_BdCert.GetEncodedSb("base64",loo_SbCert64)

li_NReplaced = loo_SbXml.Replace("BinarySecurityToken_Base64Binary_Content",loo_SbCert64.GetAsString())

loo_Gen.Behaviors = "IndentedSignature"

// Sign the XML...
li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml)
if li_Success <> 1 then
    Write-Debug loo_Gen.LastErrorText
    destroy loo_XmlToSign
    destroy loo_DtNow
    destroy loo_Gen
    destroy loo_Cert
    destroy loo_XmlCustomKeyInfo
    destroy loo_SbXml
    destroy loo_BdCert
    destroy loo_SbCert64
    return
end if

// -----------------------------------------------

// Save the signed XML to a file.
li_Success = loo_SbXml.WriteFile("qa_output/signedXml.xml","utf-8",0)

Write-Debug loo_SbXml.GetAsString()

// Produces the following signed XML:
// Note: The following has been edited for readability.  Therefore, what you see here will not actually validate because it's been modified.

// <?xml version="1.0" encoding="utf-8"?>
// <soapenv:Envelope 
//   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
//   xmlns:scat="www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/" 
//   xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
//   xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
//   xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#">
//     <soapenv:Header xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
//         <wsse:Security soapenv:mustUnderstand="1">
//             <wsse:BinarySecurityToken ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" wsu:Id="X509Token">MIIFNTCCBB2gAwIBAgIQHozVnBl1lTsusAh26u6WZTANBgkqhkiG9w0BAQsFADCB
// lzELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
// A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxPTA7BgNV
// BAMTNENPTU9ETyBSU0EgQ2xpZW50IEF1dGhlbnRpY2F0aW9uIGFuZCBTZWN1cmUg
// RW1haWwgQ0EwHhcNMTcxMjE0MDAwMDAwWhcNMTgxMjE0MjM1OTU5WjAmMSQwIgYJ
// KoZIhvcNAQkBFhVhc2Rhc2Rhc2Rhc2RkQGJ5b20uZGUwggEiMA0GCSqGSIb3DQEB
// AQUAA4IBDwAwggEKAoIBAQC96oQe50EDoiuJVITeKJzy6GzVq74cEa14eFypjMNb
// YVyedfCI6cn9pVClLqL7dlwxFGCRA62bbNE9woKLBT3SO1IvgoFDVIrbJm+84GEo
// qQReZe8HpZnF06d3DWwhUjjcuO1z2yliGdSymSee8/1OaztxEAEOWaZR+4MkfSNc
// AzzjGtKcKjVMSdiiO0JGAG/IXEwzlulfkF8zVdqDGkQTQesvT4WBys4BYwTDI64d
// sM7rcC9vwuK6gvpkUi9i1Wzu0W4v9T3iHAbl3rLihPcjQ95c4q7+NjwpRqQW1VXR
// enR/0iyLEFOek0D4JvOoscUwJ0LYd8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FRlACVeb1Qlytr4vgc5FlCqn0rMtjlF4=
// </wsse:BinarySecurityToken>
//             <wsu:Timestamp wsu:Id="_1">
//                 <wsu:Created>2020-03-26T17:19:50Z</wsu:Created>
//                 <wsu:Expires>2020-03-26T17:24:50Z</wsu:Expires>
//             </wsu:Timestamp>
//         </wsse:Security>
//         <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><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#"/>
//     <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
//     <ds:Reference URI="#_1">
//       <ds:Transforms>
//         <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
//       </ds:Transforms>
//       <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
//       <ds:DigestValue>cwrTw7wFZqNc50NxE//UT11qZCY=</ds:DigestValue>
//     </ds:Reference>
//   </ds:SignedInfo>
//   <ds:SignatureValue>s2UmYNVDz9dm3eU ... 619qSZqw==</ds:SignatureValue>
//   <ds:KeyInfo Id="X509KeyId"><wsse:SecurityTokenReference wsu:Id="X509TokenReference">
//     <wsse:Reference URI="#X509Token" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
// </wsse:SecurityTokenReference>
//   </ds:KeyInfo>
// </ds:Signature></wsse:Security>
//     </soapenv:Header>
//     <soapenv:Body>
//         <scat:getRuoliStruttureOperatore>
//             <scat:codFiscaleOperatore>CLDxxxxxxxxxxxxL</scat:codFiscaleOperatore>
//         </scat:getRuoliStruttureOperatore>
//     </soapenv:Body>
// </soapenv:Envelope>

// ----------------------------------------
// Verify the signatures we just produced...
loo_Verifier = create oleobject
// Use "Chilkat_9_5_0.XmlDSig" for versions of Chilkat < 10.0.0
li_rc = loo_Verifier.ConnectToNewObject("Chilkat.XmlDSig")

li_Success = loo_Verifier.LoadSignatureSb(loo_SbXml)
if li_Success <> 1 then
    Write-Debug loo_Verifier.LastErrorText
    destroy loo_XmlToSign
    destroy loo_DtNow
    destroy loo_Gen
    destroy loo_Cert
    destroy loo_XmlCustomKeyInfo
    destroy loo_SbXml
    destroy loo_BdCert
    destroy loo_SbCert64
    destroy loo_Verifier
    return
end if

li_NumSigs = loo_Verifier.NumSignatures
li_VerifyIdx = 0
do while li_VerifyIdx < li_NumSigs
    loo_Verifier.Selector = li_VerifyIdx
    li_Verified = loo_Verifier.VerifySignature(1)
    if li_Verified <> 1 then
        Write-Debug loo_Verifier.LastErrorText
        destroy loo_XmlToSign
        destroy loo_DtNow
        destroy loo_Gen
        destroy loo_Cert
        destroy loo_XmlCustomKeyInfo
        destroy loo_SbXml
        destroy loo_BdCert
        destroy loo_SbCert64
        destroy loo_Verifier
        return
    end if

    li_VerifyIdx = li_VerifyIdx + 1
loop
Write-Debug "All signatures were successfully verified."


destroy loo_XmlToSign
destroy loo_DtNow
destroy loo_Gen
destroy loo_Cert
destroy loo_XmlCustomKeyInfo
destroy loo_SbXml
destroy loo_BdCert
destroy loo_SbCert64
destroy loo_Verifier

 

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