Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Swift Alliance LAU XML SignatureCalculating 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.)
IncludeFile "CkStringBuilder.pb" IncludeFile "CkXmlDSigGen.pb" Procedure ChilkatExample() ; 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. sbXml.i = CkStringBuilder::ckCreate() If sbXml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkStringBuilder::ckLoadFile(sbXml,"c:/someDir/fileToSign.xml","utf-8") If success = 0 Debug "Failed to load XML file." CkStringBuilder::ckDispose(sbXml) ProcedureReturn EndIf ; We need to add a "LAU" XML element just before the "</Saa:DataPDU>" numReplaced.i = CkStringBuilder::ckReplace(sbXml,"</Saa:DataPDU>","<LAU xmlns=" + Chr(34) + "urn:swift:saa:xsd:saa.2.0" + Chr(34) + "></LAU></Saa:DataPDU>") gen.i = CkXmlDSigGen::ckCreate() If gen.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXmlDSigGen::setCkSigLocation(gen, "Saa:DataPDU|LAU") CkXmlDSigGen::setCkSigLocationMod(gen, 0) CkXmlDSigGen::setCkSigNamespacePrefix(gen, "ds") CkXmlDSigGen::setCkSigNamespaceUri(gen, "http://www.w3.org/2000/09/xmldsig#") CkXmlDSigGen::setCkSignedInfoCanonAlg(gen, "EXCL_C14N") CkXmlDSigGen::setCkSignedInfoDigestMethod(gen, "sha256") CkXmlDSigGen::setCkBehaviors(gen, "CompactSignedXml") ; Sign the entire document. CkXmlDSigGen::ckAddSameDocRef(gen,"","sha256","EXCL_C14N","","") ; Set our HMAC key CkXmlDSigGen::ckSetHmacKey(gen,"Abcdef0123456789Abcdef0123456789","ascii") ; Sign the XML: success = CkXmlDSigGen::ckCreateXmlDSigSb(gen,sbXml) If success = 0 Debug CkXmlDSigGen::ckLastErrorText(gen) CkStringBuilder::ckDispose(sbXml) CkXmlDSigGen::ckDispose(gen) ProcedureReturn EndIf ; Examine the signed XML Debug CkStringBuilder::ckGetAsString(sbXml) ; Save the signed XML to a file. success = CkStringBuilder::ckWriteFile(sbXml,"c:/someDir/signedFile.xml","utf-8",0) CkStringBuilder::ckDispose(sbXml) CkXmlDSigGen::ckDispose(gen) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.