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
(AutoIt) Create XAdES with ec:InclusiveNamespaces within the TransformsDemonstrates how to generate XAdES that has a Reference that has Transforms that include an ec:InclusiveNamespaces.
; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. ; This is the XML we'll be signing: ; <soapenv:Envelope xmlns:obs="http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> ; <soapenv:Header> ; <wsse:Security ; 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" soapenv:mustUnderstand="1"> ; <wsse:BinarySecurityToken ; EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ; ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1" ; wsu:Id="X509-02BF0107214FC61449FD0013DF68F0359">MII...</wsse:BinarySecurityToken> ; </wsse:Security> ; </soapenv:Header> ; <soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" ; wsu:Id="id-396BB6026342EB5C0E1EA73593B3CC098"> ; <obs:zapiszKomunikatOS> ; <komunikatOS> ; <idPodmiotuRaportujacego> ; <idBiznesowy>000000011986</idBiznesowy> ; <rodzajPodmiotuRaportujacego>PA</rodzajPodmiotuRaportujacego> ; </idPodmiotuRaportujacego> ; </komunikatOS> ; </obs:zapiszKomunikatOS> ; </soapenv:Body> ; </soapenv:Envelope> ; ; ---------------------------------------------------------------------- ; IMPORTANT: This generated example requires Chilkat v9.5.0.77 or later. ; ---------------------------------------------------------------------- Local $bSuccess = True ; Create the above XML to be signed... $oXmlToSign = ObjCreate("Chilkat.Xml") $oXmlToSign.Tag = "soapenv:Envelope" $oXmlToSign.AddAttribute("xmlns:obs","http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/") $oXmlToSign.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/") $oXmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",True,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") $oXmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",True,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") $oXmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",True,"soapenv:mustUnderstand","1") $oXmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",True,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary") $oXmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",True,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1") $oXmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",True,"wsu:Id","X509-02BF0107214FC61449FD0013DF68F0359") ; Note: The content of this XML node is a placeholder that will be updated below with the X509PKIPathv1 for the signing certificate. $oXmlToSign.UpdateChildContent "soapenv:Header|wsse:Security|wsse:BinarySecurityToken","BinarySecurityToken_Base64Binary_Content" $oXmlToSign.UpdateAttrAt("soapenv:Body",True,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd") $oXmlToSign.UpdateAttrAt("soapenv:Body",True,"wsu:Id","id-396BB6026342EB5C0E1EA73593B3CC098") $oXmlToSign.UpdateChildContent "soapenv:Body|obs:zapiszKomunikatOS|komunikatOS|idPodmiotuRaportujacego|idBiznesowy","000000011986" $oXmlToSign.UpdateChildContent "soapenv:Body|obs:zapiszKomunikatOS|komunikatOS|idPodmiotuRaportujacego|rodzajPodmiotuRaportujacego","PA" $oGen = ObjCreate("Chilkat.XmlDSigGen") $oGen.SigLocation = "soapenv:Envelope|soapenv:Header|wsse:Security" $oGen.SigLocationMod = 0 $oGen.SigId = "SIG-BB965DFC3C8AAF87903C0ED898B8D2A8D" $oGen.SigNamespacePrefix = "ds" $oGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" $oGen.SignedInfoCanonAlg = "EXCL_C14N" $oGen.SignedInfoDigestMethod = "sha1" ; Set the KeyInfoId before adding references.. $oGen.KeyInfoId = "KI-9D95C38916099AD2EE87DDAC1A76E97E4" ; -------- Reference 1 -------- $oGen.AddSameDocRef("id-396BB6026342EB5C0E1EA73593B3CC098","sha1","EXCL_C14N","obs","") ; The reference to be produced in the Signature should look like this: ; <ds:Reference URI="#id-396BB6026342EB5C0E1EA73593B3CC098"> ; <ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> ; <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="obs"></ec:InclusiveNamespaces> ; </ds:Transform></ds:Transforms> ; <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod> ; <ds:DigestValue>2e9hZYj/CN2nPsgQqUraU43k3ds=</ds:DigestValue> ; </ds:Reference> ; ; Provide a certificate + private key. (PFX password is test123) $oCert = ObjCreate("Chilkat.Cert") $bSuccess = $oCert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") If ($bSuccess <> True) Then ConsoleWrite($oCert.LastErrorText & @CRLF) Exit EndIf $oGen.SetX509Cert($oCert,True) $oGen.KeyInfoType = "Custom" ; Create the custom KeyInfo XML.. $oXmlCustomKeyInfo = ObjCreate("Chilkat.Xml") $oXmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference" $oXmlCustomKeyInfo.AddAttribute("wsse11:TokenType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1") $oXmlCustomKeyInfo.AddAttribute("xmlns:wsse11","http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd") $oXmlCustomKeyInfo.AddAttribute("wsu:Id","STR-FF238E7C061332C5B19752C2FBC8CDEF2") $oXmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",True,"URI","#X509-02BF0107214FC61449FD0013DF68F0359") $oXmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",True,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1") $oXmlCustomKeyInfo.EmitXmlDecl = False $oGen.CustomKeyInfoXml = $oXmlCustomKeyInfo.GetXml() ; Load XML to be signed... $oSbXml = ObjCreate("Chilkat.StringBuilder") $oXmlToSign.GetXmlSb($oSbXml) ; Update BinarySecurityToken_Base64Binary_Content with the actual X509PKIPathv1 of the signing cert. Local $iNReplaced = $oSbXml.Replace("BinarySecurityToken_Base64Binary_Content",$oCert.X509PKIPathv1()) $oGen.Behaviors = "IndentedSignature" ; Sign the XML... $bSuccess = $oGen.CreateXmlDSigSb($oSbXml) If ($bSuccess <> True) Then ConsoleWrite($oGen.LastErrorText & @CRLF) Exit EndIf ; ----------------------------------------------- ; Save the signed XML to a file. $bSuccess = $oSbXml.WriteFile("qa_output/signedXml.xml","utf-8",False) ConsoleWrite($oSbXml.GetAsString() & @CRLF) ; ---------------------------------------- ; Verify the signatures we just produced... $oVerifier = ObjCreate("Chilkat.XmlDSig") $bSuccess = $oVerifier.LoadSignatureSb($oSbXml) If ($bSuccess <> True) Then ConsoleWrite($oVerifier.LastErrorText & @CRLF) Exit EndIf Local $iNumSigs = $oVerifier.NumSignatures Local $iVerifyIdx = 0 While $iVerifyIdx < $iNumSigs $oVerifier.Selector = $iVerifyIdx Local $bVerified = $oVerifier.VerifySignature(True) If ($bVerified <> True) Then ConsoleWrite($oVerifier.LastErrorText & @CRLF) Exit EndIf $iVerifyIdx = $iVerifyIdx + 1 Wend ConsoleWrite("All signatures were successfully verified." & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.