Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Excel Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Excel) Sign XML for eFactura DGI Uruguay (cfe.dgi.gub.uy)

Demonstrates how to sign XML for eFactura DGI (Uruguay, cfe.dgi.gub.uy).

Download Excel Class Modules

Chilkat Excel Class Modules

' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.


success = True

' <?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>

Dim gen As Chilkat.XmlDSigGen
Set gen = Chilkat.NewXmlDSigGen

gen.SigLocation = "DGICFE:EnvioCFE|CFE"
gen.SigLocationMod = 0
gen.SigNamespacePrefix = ""
gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
gen.SignedInfoCanonAlg = "C14N"
gen.SignedInfoDigestMethod = "sha1"

' -------- Reference 1 --------
Dim success As Boolean
success = gen.AddSameDocRef("","sha1","C14N","","")

' Provide a certificate + private key. (PFX password is test123)
Dim cert As Chilkat.Cert
Set cert = Chilkat.NewCert
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> True) Then
    Debug.Print cert.LastErrorText
    Exit Sub
End If

success = gen.SetX509Cert(cert,True)

gen.KeyInfoType = "X509Data"
gen.X509Type = "IssuerSerial"

' Load XML to be signed...
Dim sbXml As Chilkat.StringBuilder
Set sbXml = Chilkat.NewStringBuilder
success = sbXml.LoadFile("qa_data/cfe.dgi.gub.uy/sample.xml","utf-8")
If (success = False) Then
    Debug.Print "Failed to load input XML document."
    Exit Sub
End If

gen.Behaviors = "IndentedSignature,CompactSignedXml"

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> True) Then
    Debug.Print gen.LastErrorText
    Exit Sub
End If

' -----------------------------------------------

' Save the signed XML to a file.
success = sbXml.WriteFile("qa_output/signed.xml","utf-8",False)

Debug.Print sbXml.GetAsString()

 

© 2000-2022 Chilkat Software, Inc. All Rights Reserved.