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) Paraguay E-Invoicing Signed XML (SIFEN)See more XML Digital Signatures ExamplesDemonstrates how to sign XML for e-invoicing -- SISTEMA INTEGRADO DE FACTURACIÓN ELECTRÓNICA NACIONAL (SIFEN). This is for signing XML files that need to be submitted to a government agency (Country Paraguay, SIFEN / EKUATIA, Sistema Nacional de Facturacion Electrónica).
Local $bSuccess = True ; Create the XML to be signed... ; Use this online tool to generate code from sample XML: ; Generate Code to Create XML $oXmlToSign = ObjCreate("Chilkat.Xml") $oXmlToSign.Tag = "rDE" $oXmlToSign.AddAttribute("xmlns","http://ekuatia.set.gov.py/sifen/xsd") $oXmlToSign.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") $oXmlToSign.AddAttribute("xsi:schemaLocation","http://ekuatia.set.gov.py/sifen/xsd siRecepDE_v150.xsd") $oXmlToSign.UpdateChildContent "dVerFor","150" $oXmlToSign.UpdateAttrAt("DE",True,"Id","01800228774059001001501012022091519999999990") $oXmlToSign.UpdateChildContent "DE|dDVId","0" $oXmlToSign.UpdateChildContent "DE|dFecFirma","2022-09-15T10:23:05" $oXmlToSign.UpdateChildContent "DE|dSisFact","1" $oXmlToSign.UpdateChildContent "DE|gOpeDE|iTipEmi","1" $oXmlToSign.UpdateChildContent "DE|gOpeDE|dDesTipEmi","Normal" $oXmlToSign.UpdateChildContent "DE|gOpeDE|dCodSeg","999999999" $oXmlToSign.UpdateChildContent "DE|gOpeDE|dInfoEmi","GENERADA DE PEDIDO 131043202" $oXmlToSign.UpdateChildContent "DE|gTimb|iTiDE","1" $oXmlToSign.UpdateChildContent "DE|gTimb|dDesTiDE","Factura electr�nica" $oXmlToSign.UpdateChildContent "DE|gTimb|dNumTim","18889014" $oXmlToSign.UpdateChildContent "DE|gTimb|dEst","059" $oXmlToSign.UpdateChildContent "DE|gTimb|dPunExp","001" $oXmlToSign.UpdateChildContent "DE|gTimb|dNumDoc","0015010" $oXmlToSign.UpdateChildContent "DE|gTimb|dFeIniT","2022-05-25" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|dFeEmiDE","2022-09-15T10:22:57" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gOpeCom|iTipTra","1" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gOpeCom|dDesTipTra","Venta de mercader�a" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gOpeCom|iTImp","1" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gOpeCom|dDesTImp","IVA" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gOpeCom|cMoneOpe","PYG" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gOpeCom|dDesMoneOpe","Guarani" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dRucEm","80022877" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dDVEmi","4" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|iTipCont","1" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|cTipReg","1" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dNomEmi","ABCDEF SA" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dNomFanEmi","ABCDEF SA" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dDirEmi","Jos� Abcde Xyz N� 666 e/Abxyz123" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dNumCas","0" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dCompDir1","N/A" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dCompDir2","N/A" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|cDepEmi","12" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dDesDepEmi","CENTRAL" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|cDisEmi","153" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dDesDisEmi","CAPIATA" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|cCiuEmi","1234" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dDesCiuEmi","CAPIATA" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dTelEmi","(022) 1111 000" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dEmailE","somebody@example.com.py" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|dDenSuc","PUNTO 99" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|gActEco|cActEco","47721" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gEmis|gActEco|dDesActEco","COMERCIO AL POR MENOR DE PRODUCTOS" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|iNatRec","1" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|iTiOpe","2" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|cPaisRec","PRY" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dDesPaisRe","Paraguay" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|iTiContRec","2" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dRucRec","80082971" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dDVRec","9" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dNomRec","XXXXXXX" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dNomFanRec","XXXXXXX" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dNumCasRec","0" $oXmlToSign.UpdateChildContent "DE|gDatGralOpe|gDatRec|dCodCliente","9999999" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamFE|iIndPres","1" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamFE|dDesIndPres","Operaci�n presencial" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|iCondOpe","1" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|dDCondOpe","Contado" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni|iTiPago","1" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni|dDesTiPag","Efectivo" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni|dMonTiPag","100000.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni|cMoneTiPag","PYG" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni|dDMoneTiPag","Guarani" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni[1]|iTiPago","1" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni[1]|dDesTiPag","Efectivo" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni[1]|dMonTiPag","73600.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni[1]|cMoneTiPag","PYG" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamCond|gPaConEIni[1]|dDMoneTiPag","Guarani" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|dCodInt","818181" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|dDesProSer","Widget Abc Xyz" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|cUniMed","77" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|dDesUniMed","UNI" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|dCantProSer","2.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gValorItem|dPUniProSer","16500.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gValorItem|dTotBruOpeItem","33000.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dDescItem","3300.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dPorcDesIt","20.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dTotOpeItem","26400.0000" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gCamIVA|iAfecIVA","1" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gCamIVA|dDesAfecIVA","Gravado IVA" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gCamIVA|dPropIVA","100" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gCamIVA|dTasaIVA","5" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gCamIVA|dBasGravIVA","25142.8571" $oXmlToSign.UpdateChildContent "DE|gDtipDE|gCamItem|gCamIVA|dLiqIVAItem","1257.1429" $oXmlToSign.UpdateChildContent "DE|gTotSub|dSubExe","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dSub5","26400.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dSub10","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotOpe","26400.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotDesc","6600.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotDescGlotem","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotAntItem","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotAnt","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dPorcDescTotal","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dDescTotal","6600.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dAnticipo","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dRedon","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotGralOpe","26400.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dIVA5","1257.1429" $oXmlToSign.UpdateChildContent "DE|gTotSub|dIVA10","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTotIVA","1257.1429" $oXmlToSign.UpdateChildContent "DE|gTotSub|dBaseGrav5","25142.8571" $oXmlToSign.UpdateChildContent "DE|gTotSub|dBaseGrav10","0.0000" $oXmlToSign.UpdateChildContent "DE|gTotSub|dTBasGraIVA","25142.8571" $oGen = ObjCreate("Chilkat.XmlDSigGen") $oGen.SigLocation = "rDE" $oGen.SigLocationMod = 0 $oGen.SigNamespacePrefix = "" $oGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" $oGen.SignedInfoCanonAlg = "C14N" $oGen.SignedInfoDigestMethod = "sha256" ; -------- Reference 1 -------- $oXml1 = ObjCreate("Chilkat.Xml") $oXml1.Tag = "Transforms" $oXml1.UpdateAttrAt("Transform",True,"Algorithm","http://www.w3.org/2000/09/xmldsig#enveloped-signature") $oXml1.UpdateAttrAt("Transform[1]",True,"Algorithm","http://www.w3.org/2001/10/xml-exc-c14n#") $oGen.AddSameDocRef2("01800228774059001001501012022091516941989060","sha256",$oXml1,"") ; 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 = "X509Data" $oGen.X509Type = "Certificate" ; Load XML to be signed... $oSbXml = ObjCreate("Chilkat.StringBuilder") $oXmlToSign.GetXmlSb($oSbXml) $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("c:/temp/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.