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

SQL Server 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
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

 

 

 

(SQL Server) Swift Alliance LAU XML Signature

Calculating the LAU for Swift Alliance File Act XML using HMAC SHA256. (The XML signature, also referred to as Local Authentication (LAU), is computed using the algorithm HMAC based on SHA-256.)

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    -- We begin with the following XML:

    -- <?xml version="1.0" encoding="UTF-8"?>
    -- <Saa:DataPDU xmlns:Saa="urn:swift:saa:xsd:saa.2.0" xmlns:Sw="urn:swift:snl:ns.Sw" xmlns:SwInt="urn:swift:snl:ns.SwInt" xmlns:SwGbl="urn:swift:snl:ns.SwGbl" xmlns:SwSec="urn:swift:snl:ns.SwSec">
    --     <Saa:Revision>2.0.6</Saa:Revision>
    --     <Saa:Header>
    --         <Saa:Message>
    --             <Saa:SenderReference>Ref760FA1234</Saa:SenderReference>
    --             <Saa:MessageIdentifier>tsrv.fin.mt7xx.gteesstandbys</Saa:MessageIdentifier>
    --             <Saa:Format>File</Saa:Format>
    --             <Saa:SubFormat>Input</Saa:SubFormat>
    --             <Saa:Sender>
    --                 <Saa:DN>cn=su8,o=ptsqgbbb,o=swift</Saa:DN>
    --                 <Saa:FullName>
    --                     <Saa:X1>PTSQGBBBXXX</Saa:X1>
    --                 </Saa:FullName>
    --             </Saa:Sender>
    --             <Saa:Receiver>
    --                 <Saa:DN>cn=abc,ou=saa,o=xxx,o=swift</Saa:DN>
    --                 <Saa:FullName>
    --                     <Saa:X1>PTSXXXXXXXX</Saa:X1>
    --                     <Saa:X2>saa</Saa:X2>
    --                 </Saa:FullName>
    --             </Saa:Receiver>
    --             <Saa:InterfaceInfo>
    --                 <Saa:UserReference>CRE...</Saa:UserReference>
    --                 <Saa:MessageCreator>ApplicationInterface</Saa:MessageCreator>
    --                 <Saa:MessageContext>Original</Saa:MessageContext>
    --                 <Saa:MessageNature>Financial</Saa:MessageNature>
    --             </Saa:InterfaceInfo>
    --             <Saa:NetworkInfo>
    --                 <Saa:Priority>Normal</Saa:Priority>
    --                 <Saa:IsPossibleDuplicate>true</Saa:IsPossibleDuplicate>
    --                 <Saa:Service>swift.corp.fast!x</Saa:Service>
    --                 <Saa:Network>Application</Saa:Network>
    --                 <Saa:SessionNr>0080</Saa:SessionNr>
    --                 <Saa:SeqNr>000001</Saa:SeqNr>
    --                 <Saa:SWIFTNetNetworkInfo>
    --                     <Saa:RequestType>tsrv.fin.mt7xx.gteesstandbys</Saa:RequestType>
    --                     <Saa:Reference>2f949999-d32e-49eb-9999-9a819b9b9c0d</Saa:Reference>
    --                     <Saa:FileInfo>SwCompression=Zip</Saa:FileInfo>
    --                 </Saa:SWIFTNetNetworkInfo>
    --             </Saa:NetworkInfo>
    --             <Saa:SecurityInfo>
    --                 <Saa:SWIFTNetSecurityInfo>
    --                     <Saa:FileDigestAlgorithm>SHA-256</Saa:FileDigestAlgorithm>
    --                     <Saa:FileDigestValue>9tnnjIgsowPSU+ehm8Rb0J5TvZIvhCYnySzFkpur1aw=</Saa:FileDigestValue>
    --                 </Saa:SWIFTNetSecurityInfo>
    --             </Saa:SecurityInfo>
    --             <Saa:FileLogicalName>Payload.ZIP</Saa:FileLogicalName>
    --             <Saa:ExpiryDateTime>20210712074808</Saa:ExpiryDateTime>
    --         </Saa:Message>
    --     </Saa:Header>
    --     <Saa:Body>Payload.ZIP</Saa:Body>
    -- </Saa:DataPDU>

    -- Load the XML file to be signed.
    DECLARE @sbXml int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbXml OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int
    EXEC sp_OAMethod @sbXml, 'LoadFile', @success OUT, 'c:/someDir/fileToSign.xml', 'utf-8'
    IF @success = 0
      BEGIN

        PRINT 'Failed to load XML file.'
        EXEC @hr = sp_OADestroy @sbXml
        RETURN
      END

    -- We need to add a "LAU" XML element just before the "</Saa:DataPDU>"
    DECLARE @numReplaced int
    EXEC sp_OAMethod @sbXml, 'Replace', @numReplaced OUT, '</Saa:DataPDU>', '<LAU xmlns="urn:swift:saa:xsd:saa.2.0"></LAU></Saa:DataPDU>'

    DECLARE @gen int
    -- Use "Chilkat_9_5_0.XmlDSigGen" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.XmlDSigGen', @gen OUT

    EXEC sp_OASetProperty @gen, 'SigLocation', 'Saa:DataPDU|LAU'
    EXEC sp_OASetProperty @gen, 'SigLocationMod', 0
    EXEC sp_OASetProperty @gen, 'SigNamespacePrefix', 'ds'
    EXEC sp_OASetProperty @gen, 'SigNamespaceUri', 'http://www.w3.org/2000/09/xmldsig#'
    EXEC sp_OASetProperty @gen, 'SignedInfoCanonAlg', 'EXCL_C14N'
    EXEC sp_OASetProperty @gen, 'SignedInfoDigestMethod', 'sha256'
    EXEC sp_OASetProperty @gen, 'Behaviors', 'CompactSignedXml'

    -- Sign the entire document.
    EXEC sp_OAMethod @gen, 'AddSameDocRef', @success OUT, '', 'sha256', 'EXCL_C14N', '', ''

    -- Set our HMAC key
    EXEC sp_OAMethod @gen, 'SetHmacKey', @success OUT, 'Abcdef0123456789Abcdef0123456789', 'ascii'

    -- Sign the XML:
    EXEC sp_OAMethod @gen, 'CreateXmlDSigSb', @success OUT, @sbXml
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @gen, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @sbXml
        EXEC @hr = sp_OADestroy @gen
        RETURN
      END

    -- Examine the signed XML
    EXEC sp_OAMethod @sbXml, 'GetAsString', @sTmp0 OUT
    PRINT @sTmp0

    -- Save the signed XML to a file.
    EXEC sp_OAMethod @sbXml, 'WriteFile', @success OUT, 'c:/someDir/signedFile.xml', 'utf-8', 0

    EXEC @hr = sp_OADestroy @sbXml
    EXEC @hr = sp_OADestroy @gen


END
GO

 

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