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
(PowerBuilder) 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).
integer li_rc integer li_Success oleobject loo_XmlToSign oleobject loo_Gen oleobject loo_Xml1 oleobject loo_Cert oleobject loo_SbXml oleobject loo_Verifier integer li_NumSigs integer li_VerifyIdx integer li_Verified li_Success = 1 // Create the XML to be signed... // Use this online tool to generate code from sample XML: // Generate Code to Create XML 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 = "rDE" loo_XmlToSign.AddAttribute("xmlns","http://ekuatia.set.gov.py/sifen/xsd") loo_XmlToSign.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") loo_XmlToSign.AddAttribute("xsi:schemaLocation","http://ekuatia.set.gov.py/sifen/xsd siRecepDE_v150.xsd") loo_XmlToSign.UpdateChildContent("dVerFor","150") loo_XmlToSign.UpdateAttrAt("DE",1,"Id","01800228774059001001501012022091519999999990") loo_XmlToSign.UpdateChildContent("DE|dDVId","0") loo_XmlToSign.UpdateChildContent("DE|dFecFirma","2022-09-15T10:23:05") loo_XmlToSign.UpdateChildContent("DE|dSisFact","1") loo_XmlToSign.UpdateChildContent("DE|gOpeDE|iTipEmi","1") loo_XmlToSign.UpdateChildContent("DE|gOpeDE|dDesTipEmi","Normal") loo_XmlToSign.UpdateChildContent("DE|gOpeDE|dCodSeg","999999999") loo_XmlToSign.UpdateChildContent("DE|gOpeDE|dInfoEmi","GENERADA DE PEDIDO 131043202") loo_XmlToSign.UpdateChildContent("DE|gTimb|iTiDE","1") loo_XmlToSign.UpdateChildContent("DE|gTimb|dDesTiDE","Factura electr�nica") loo_XmlToSign.UpdateChildContent("DE|gTimb|dNumTim","18889014") loo_XmlToSign.UpdateChildContent("DE|gTimb|dEst","059") loo_XmlToSign.UpdateChildContent("DE|gTimb|dPunExp","001") loo_XmlToSign.UpdateChildContent("DE|gTimb|dNumDoc","0015010") loo_XmlToSign.UpdateChildContent("DE|gTimb|dFeIniT","2022-05-25") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|dFeEmiDE","2022-09-15T10:22:57") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|iTipTra","1") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|dDesTipTra","Venta de mercader�a") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|iTImp","1") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|dDesTImp","IVA") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|cMoneOpe","PYG") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|dDesMoneOpe","Guarani") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dRucEm","80022877") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDVEmi","4") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|iTipCont","1") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cTipReg","1") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dNomEmi","ABCDEF SA") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dNomFanEmi","ABCDEF SA") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDirEmi","Jos� Abcde Xyz N� 666 e/Abxyz123") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dNumCas","0") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dCompDir1","N/A") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dCompDir2","N/A") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cDepEmi","12") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDesDepEmi","CENTRAL") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cDisEmi","153") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDesDisEmi","CAPIATA") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cCiuEmi","1234") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDesCiuEmi","CAPIATA") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dTelEmi","(022) 1111 000") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dEmailE","somebody@example.com.py") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDenSuc","PUNTO 99") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|gActEco|cActEco","47721") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|gActEco|dDesActEco","COMERCIO AL POR MENOR DE PRODUCTOS") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|iNatRec","1") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|iTiOpe","2") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|cPaisRec","PRY") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dDesPaisRe","Paraguay") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|iTiContRec","2") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dRucRec","80082971") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dDVRec","9") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dNomRec","XXXXXXX") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dNomFanRec","XXXXXXX") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dNumCasRec","0") loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dCodCliente","9999999") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamFE|iIndPres","1") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamFE|dDesIndPres","Operaci�n presencial") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|iCondOpe","1") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|dDCondOpe","Contado") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|iTiPago","1") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|dDesTiPag","Efectivo") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|dMonTiPag","100000.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|cMoneTiPag","PYG") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|dDMoneTiPag","Guarani") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|iTiPago","1") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|dDesTiPag","Efectivo") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|dMonTiPag","73600.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|cMoneTiPag","PYG") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|dDMoneTiPag","Guarani") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dCodInt","818181") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dDesProSer","Widget Abc Xyz") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|cUniMed","77") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dDesUniMed","UNI") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dCantProSer","2.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|dPUniProSer","16500.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|dTotBruOpeItem","33000.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dDescItem","3300.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dPorcDesIt","20.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dTotOpeItem","26400.0000") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|iAfecIVA","1") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dDesAfecIVA","Gravado IVA") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dPropIVA","100") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dTasaIVA","5") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dBasGravIVA","25142.8571") loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dLiqIVAItem","1257.1429") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dSubExe","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dSub5","26400.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dSub10","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotOpe","26400.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotDesc","6600.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotDescGlotem","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotAntItem","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotAnt","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dPorcDescTotal","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dDescTotal","6600.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dAnticipo","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dRedon","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotGralOpe","26400.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dIVA5","1257.1429") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dIVA10","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotIVA","1257.1429") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dBaseGrav5","25142.8571") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dBaseGrav10","0.0000") loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTBasGraIVA","25142.8571") 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 = "rDE" loo_Gen.SigLocationMod = 0 loo_Gen.SigNamespacePrefix = "" loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loo_Gen.SignedInfoCanonAlg = "C14N" loo_Gen.SignedInfoDigestMethod = "sha256" // -------- Reference 1 -------- loo_Xml1 = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml1.ConnectToNewObject("Chilkat.Xml") loo_Xml1.Tag = "Transforms" loo_Xml1.UpdateAttrAt("Transform",1,"Algorithm","http://www.w3.org/2000/09/xmldsig#enveloped-signature") loo_Xml1.UpdateAttrAt("Transform[1]",1,"Algorithm","http://www.w3.org/2001/10/xml-exc-c14n#") loo_Gen.AddSameDocRef2("01800228774059001001501012022091516941989060","sha256",loo_Xml1,"") // 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_Gen destroy loo_Xml1 destroy loo_Cert return end if loo_Gen.SetX509Cert(loo_Cert,1) loo_Gen.KeyInfoType = "X509Data" loo_Gen.X509Type = "Certificate" // 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) 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_Gen destroy loo_Xml1 destroy loo_Cert destroy loo_SbXml return end if // ----------------------------------------------- // Save the signed XML to a file. li_Success = loo_SbXml.WriteFile("c:/temp/qa_output/signedXml.xml","utf-8",0) Write-Debug loo_SbXml.GetAsString() // ---------------------------------------- // 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_Gen destroy loo_Xml1 destroy loo_Cert destroy loo_SbXml 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_Gen destroy loo_Xml1 destroy loo_Cert destroy loo_SbXml destroy loo_Verifier return end if li_VerifyIdx = li_VerifyIdx + 1 loop Write-Debug "All signatures were successfully verified." destroy loo_XmlToSign destroy loo_Gen destroy loo_Xml1 destroy loo_Cert destroy loo_SbXml destroy loo_Verifier |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.