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
(Visual FoxPro) Sign Bolivia Invoice XMLSee more XML Digital Signatures ExamplesDemonstrates how to create an XML digital signature (XmlDSig) for a Bolivia invoice (factura).
LOCAL lnSuccess LOCAL loXml LOCAL loGen LOCAL loCert LOCAL loSbXml LOCAL loVerifier LOCAL lnNumSigs LOCAL lnVerifyIdx LOCAL lnVerified * This example assumes the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. lnSuccess = 1 * Create the following XML to be signed: * <?xml version="1.0" encoding="UTF-8"?> * <facturaElectronicaCompraVenta xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="facturaElectronicaCompraVenta.xsd"> * <cabecera> * <nitEmisor>99999999</nitEmisor> * <razonSocialEmisor>Abc Xyz</razonSocialEmisor> * <municipio>Cochabamba - Cochabamba</municipio> * <telefono>4444444</telefono> * <numeroFactura>417</numeroFactura> * <cuf>ABABABABABABABABABABABABABABABABABABABABABABABABABABABABA</cuf> * <cufd>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</cufd> * <codigoSucursal>0</codigoSucursal> * <direccion>aaa aaa aaa</direccion> * <codigoPuntoVenta>1</codigoPuntoVenta> * <fechaEmision>2023-04-13T22:43:22.417</fechaEmision> * <nombreRazonSocial>xyz</nombreRazonSocial> * <codigoTipoDocumentoIdentidad>1</codigoTipoDocumentoIdentidad> * <numeroDocumento>1234567</numeroDocumento> * <complemento xsi:nil="true"/> * <codigoCliente>1234567</codigoCliente> * <codigoMetodoPago>1</codigoMetodoPago> * <numeroTarjeta xsi:nil="true"/> * <montoTotal>22.00</montoTotal> * <montoTotalSujetoIva>22.00</montoTotalSujetoIva> * <codigoMoneda>1</codigoMoneda> * <tipoCambio>1.00</tipoCambio> * <montoTotalMoneda>22.00</montoTotalMoneda> * <montoGiftCard xsi:nil="true"/> * <descuentoAdicional>0.00</descuentoAdicional> * <codigoExcepcion>1</codigoExcepcion> * <cafc xsi:nil="true"/> * <leyenda>Ley N� 453: El proveedor de servicios debe habilitar medios e instrumentos para efectuar consultas y reclamaciones.</leyenda> * <usuario>nromero</usuario> * <codigoDocumentoSector>1</codigoDocumentoSector> * </cabecera> * <detalle> * <actividadEconomica>620100</actividadEconomica> * <codigoProductoSin>123456</codigoProductoSin> * <codigoProducto>1</codigoProducto> * <descripcion>Economicos</descripcion> * <cantidad>1.00</cantidad> * <unidadMedida>58</unidadMedida> * <precioUnitario>22.00</precioUnitario> * <montoDescuento>0.00</montoDescuento> * <subTotal>22.00</subTotal> * <numeroSerie xsi:nil="true"/> * <numeroImei xsi:nil="true"/> * </detalle> * </facturaElectronicaCompraVenta> * Use this online tool to generate code from sample XML: * Generate Code to Create XML * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml') loXml = CreateObject('Chilkat.Xml') loXml.Tag = "facturaElectronicaCompraVenta" loXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") loXml.AddAttribute("xsi:noNamespaceSchemaLocation","facturaElectronicaCompraVenta.xsd") loXml.UpdateChildContent("cabecera|nitEmisor","99999999") loXml.UpdateChildContent("cabecera|razonSocialEmisor","Abc Xyz") loXml.UpdateChildContent("cabecera|municipio","Cochabamba - Cochabamba") loXml.UpdateChildContent("cabecera|telefono","4444444") loXml.UpdateChildContent("cabecera|numeroFactura","417") loXml.UpdateChildContent("cabecera|cuf","ABABABABABABABABABABABABABABABABABABABABABABABABABABABABA") loXml.UpdateChildContent("cabecera|cufd","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") loXml.UpdateChildContent("cabecera|codigoSucursal","0") loXml.UpdateChildContent("cabecera|direccion","aaa aaa aaa") loXml.UpdateChildContent("cabecera|codigoPuntoVenta","1") loXml.UpdateChildContent("cabecera|fechaEmision","2023-04-13T22:43:22.417") loXml.UpdateChildContent("cabecera|nombreRazonSocial","xyz") loXml.UpdateChildContent("cabecera|codigoTipoDocumentoIdentidad","1") loXml.UpdateChildContent("cabecera|numeroDocumento","1234567") loXml.UpdateAttrAt("cabecera|complemento",1,"xsi:nil","true") loXml.UpdateChildContent("cabecera|codigoCliente","1234567") loXml.UpdateChildContent("cabecera|codigoMetodoPago","1") loXml.UpdateAttrAt("cabecera|numeroTarjeta",1,"xsi:nil","true") loXml.UpdateChildContent("cabecera|montoTotal","22.00") loXml.UpdateChildContent("cabecera|montoTotalSujetoIva","22.00") loXml.UpdateChildContent("cabecera|codigoMoneda","1") loXml.UpdateChildContent("cabecera|tipoCambio","1.00") loXml.UpdateChildContent("cabecera|montoTotalMoneda","22.00") loXml.UpdateAttrAt("cabecera|montoGiftCard",1,"xsi:nil","true") loXml.UpdateChildContent("cabecera|descuentoAdicional","0.00") loXml.UpdateChildContent("cabecera|codigoExcepcion","1") loXml.UpdateAttrAt("cabecera|cafc",1,"xsi:nil","true") loXml.UpdateChildContent("cabecera|leyenda","Ley N� 453: El proveedor de servicios debe habilitar medios e instrumentos para efectuar consultas y reclamaciones.") loXml.UpdateChildContent("cabecera|usuario","nromero") loXml.UpdateChildContent("cabecera|codigoDocumentoSector","1") loXml.UpdateChildContent("detalle|actividadEconomica","620100") loXml.UpdateChildContent("detalle|codigoProductoSin","123456") loXml.UpdateChildContent("detalle|codigoProducto","1") loXml.UpdateChildContent("detalle|descripcion","Economicos") loXml.UpdateChildContent("detalle|cantidad","1.00") loXml.UpdateChildContent("detalle|unidadMedida","58") loXml.UpdateChildContent("detalle|precioUnitario","22.00") loXml.UpdateChildContent("detalle|montoDescuento","0.00") loXml.UpdateChildContent("detalle|subTotal","22.00") loXml.UpdateAttrAt("detalle|numeroSerie",1,"xsi:nil","true") loXml.UpdateAttrAt("detalle|numeroImei",1,"xsi:nil","true") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSigGen') loGen = CreateObject('Chilkat.XmlDSigGen') loGen.SigLocation = "facturaElectronicaCompraVenta" loGen.SigLocationMod = 0 loGen.SigNamespacePrefix = "" loGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loGen.SignedInfoCanonAlg = "C14N" loGen.SignedInfoDigestMethod = "sha256" loGen.AddSameDocRef("","sha256","C14N_WithComments","","") * Provide your certificate + private key. (PFX password is test123) * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Cert') loCert = CreateObject('Chilkat.Cert') lnSuccess = loCert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") IF (lnSuccess <> 1) THEN ? loCert.LastErrorText RELEASE loXml RELEASE loGen RELEASE loCert CANCEL ENDIF loGen.SetX509Cert(loCert,1) loGen.KeyInfoType = "X509Data" loGen.X509Type = "Certificate" loGen.Behaviors = "EnvelopedTransformFirst" * Load XML to be signed... * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbXml = CreateObject('Chilkat.StringBuilder') loXml.EmitCompact = 1 loXml.GetXmlSb(loSbXml) * Sign the XML... lnSuccess = loGen.CreateXmlDSigSb(loSbXml) IF (lnSuccess <> 1) THEN ? loGen.LastErrorText RELEASE loXml RELEASE loGen RELEASE loCert RELEASE loSbXml CANCEL ENDIF * ----------------------------------------------- * Save the signed XML to a file. lnSuccess = loSbXml.WriteFile("qa_output/signedXml.xml","utf-8",1) ? loSbXml.GetAsString() * ---------------------------------------- * Verify the signatures we just produced... * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSig') loVerifier = CreateObject('Chilkat.XmlDSig') lnSuccess = loVerifier.LoadSignatureSb(loSbXml) IF (lnSuccess <> 1) THEN ? loVerifier.LastErrorText RELEASE loXml RELEASE loGen RELEASE loCert RELEASE loSbXml RELEASE loVerifier CANCEL ENDIF lnNumSigs = loVerifier.NumSignatures lnVerifyIdx = 0 DO WHILE lnVerifyIdx < lnNumSigs loVerifier.Selector = lnVerifyIdx lnVerified = loVerifier.VerifySignature(1) IF (lnVerified <> 1) THEN ? loVerifier.LastErrorText RELEASE loXml RELEASE loGen RELEASE loCert RELEASE loSbXml RELEASE loVerifier CANCEL ENDIF lnVerifyIdx = lnVerifyIdx + 1 ENDDO ? "All signatures were successfully verified." RELEASE loXml RELEASE loGen RELEASE loCert RELEASE loSbXml RELEASE loVerifier |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.