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
(DataFlex) Sign XML for eFactura DGI Uruguay (cfe.dgi.gub.uy)Demonstrates how to sign XML for eFactura DGI (Uruguay, cfe.dgi.gub.uy).
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoGen Variant vCert Handle hoCert Variant vSbXml Handle hoSbXml String sTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Move True To iSuccess // <?xml version="1.0" encoding="utf-8"?> // <DGICFE:EnvioCFE version="1.0" xsi:schemaLocation="http://cfe.dgi.gub.uy EnvioCFE_v1.30.xsd" xmlns:DGICFE="http://cfe.dgi.gub.uy" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> // <DGICFE:Caratula version="1.0"> // <DGICFE:RutReceptor>...</DGICFE:RutReceptor> // <DGICFE:RUCEmisor>...</DGICFE:RUCEmisor> // <DGICFE:Idemisor>...</DGICFE:Idemisor> // <DGICFE:CantCFE>1</DGICFE:CantCFE> // <DGICFE:Fecha>2020-07-29T08:24:34-03:00</DGICFE:Fecha> // <DGICFE:X509Certificate>MIIGc...UJwsTEnI // </DGICFE:X509Certificate> // </DGICFE:Caratula> // <CFE xmlns="http://cfe.dgi.gub.uy" version="1.0"> // <eFact> // <TmstFirma>2020-07-21T12:34:01-03:00</TmstFirma> // <Encabezado> // <IdDoc> // <TipoCFE>111</TipoCFE> // <Serie>A</Serie> // <Nro>...</Nro> // <FchEmis>2020-07-21</FchEmis> // <FmaPago>2</FmaPago> // <FchVenc>2020-09-19</FchVenc> // </IdDoc> // <Emisor> // <RUCEmisor>...</RUCEmisor> // <RznSoc>...</RznSoc> // <NomComercial>...</NomComercial> // <GiroEmis>...</GiroEmis> // <Telefono>(598)...</Telefono> // <Telefono>(598)...</Telefono> // <CorreoEmisor>...</CorreoEmisor> // <EmiSucursal>...</EmiSucursal> // <CdgDGISucur>7</CdgDGISucur> // <DomFiscal>...</DomFiscal> // <Ciudad>Montevideo</Ciudad> // <Departamento>Montevideo</Departamento> // </Emisor> // <Receptor> // <TipoDocRecep>2</TipoDocRecep> // <CodPaisRecep>UY</CodPaisRecep> // <DocRecep>...</DocRecep> // <RznSocRecep>...</RznSocRecep> // <DirRecep>...</DirRecep> // <CiudadRecep>...</CiudadRecep> // <DeptoRecep>...</DeptoRecep> // <PaisRecep/> // <CP>...</CP> // <InfoAdicional/> // <LugarDestEnt>...</LugarDestEnt> // <CompraID>...</CompraID> // </Receptor> // <Totales> // <TpoMoneda>UYU</TpoMoneda> // <MntNoGrv>0.00</MntNoGrv> // <MntExpoyAsim>0.00</MntExpoyAsim> // <MntImpuestoPerc>0.00</MntImpuestoPerc> // <MntIVaenSusp>0.00</MntIVaenSusp> // <MntNetoIvaTasaMin>2701.71</MntNetoIvaTasaMin> // <MntNetoIVATasaBasica>0.00</MntNetoIVATasaBasica> // <MntNetoIVAOtra>0.00</MntNetoIVAOtra> // <IVATasaMin>10.00</IVATasaMin> // <IVATasaBasica>22.00</IVATasaBasica> // <MntIVATasaMin>270.17</MntIVATasaMin> // <MntIVATasaBasica>0.00</MntIVATasaBasica> // <MntIVAOtra>0.00</MntIVAOtra> // <MntTotal>2971.88</MntTotal> // <MntTotRetenido>0.00</MntTotRetenido> // <CantLinDet>1</CantLinDet> // <MontoNF>0.11</MontoNF> // <MntPagar>2971.99</MntPagar> // </Totales> // </Encabezado> // <Detalle> // <Item> // <NroLinDet>1</NroLinDet> // <IndFact>2</IndFact> // <NomItem>...</NomItem> // <DscItem>...</DscItem> // <Cantidad>4.000</Cantidad> // <UniMed/> // <PrecioUnitario>662.185000</PrecioUnitario> // <DescuentoPct>0.000</DescuentoPct> // <DescuentoMonto>0.00</DescuentoMonto> // <RecargoPct>2.000</RecargoPct> // <RecargoMnt>52.97</RecargoMnt> // <MontoItem>2701.71</MontoItem> // </Item> // </Detalle> // <CAEData> // <CAE_ID>90200658285</CAE_ID> // <DNro>1015000</DNro> // <HNro>1016999</HNro> // <FecVenc>2022-05-07</FecVenc> // </CAEData> // </eFact> // </CFE> // </DGICFE:EnvioCFE> Get Create (RefClass(cComChilkatXmlDSigGen)) To hoGen If (Not(IsComObjectCreated(hoGen))) Begin Send CreateComObject of hoGen End Set ComSigLocation Of hoGen To "DGICFE:EnvioCFE|CFE" Set ComSigLocationMod Of hoGen To 0 Set ComSigNamespacePrefix Of hoGen To "" Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#" Set ComSignedInfoCanonAlg Of hoGen To "C14N" Set ComSignedInfoDigestMethod Of hoGen To "sha1" // -------- Reference 1 -------- Get ComAddSameDocRef Of hoGen "" "sha1" "C14N" "" "" To iSuccess // Provide a certificate + private key. (PFX password is test123) Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComLoadPfxFile Of hoCert "qa_data/pfx/cert_test123.pfx" "test123" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End Get pvComObject of hoCert to vCert Get ComSetX509Cert Of hoGen vCert True To iSuccess Set ComKeyInfoType Of hoGen To "X509Data" Set ComX509Type Of hoGen To "IssuerSerial" // Load XML to be signed... Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml If (Not(IsComObjectCreated(hoSbXml))) Begin Send CreateComObject of hoSbXml End Get ComLoadFile Of hoSbXml "qa_data/cfe.dgi.gub.uy/sample.xml" "utf-8" To iSuccess If (iSuccess = False) Begin Showln "Failed to load input XML document." Procedure_Return End Set ComBehaviors Of hoGen To "IndentedSignature,CompactSignedXml" // Sign the XML... Get pvComObject of hoSbXml to vSbXml Get ComCreateXmlDSigSb Of hoGen vSbXml To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoGen To sTemp1 Showln sTemp1 Procedure_Return End // ----------------------------------------------- // Save the signed XML to a file. Get ComWriteFile Of hoSbXml "qa_output/signed.xml" "utf-8" False To iSuccess Get ComGetAsString Of hoSbXml To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.