Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Xojo Plugin Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
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
Misc
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
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Xojo Plugin) Sign Bolivia Invoice XML

See more XML Digital Signatures Examples

Demonstrates how to create an XML digital signature (XmlDSig) for a Bolivia invoice (factura).

Chilkat Xojo Plugin Download

Xojo Plugin for Windows, Linux, Mac OS X, and ARM, ARM64

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

Dim success As Boolean
success = True

// 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

Dim xml As New Chilkat.Xml
xml.Tag = "facturaElectronicaCompraVenta"
success = xml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
success = xml.AddAttribute("xsi:noNamespaceSchemaLocation","facturaElectronicaCompraVenta.xsd")
xml.UpdateChildContent "cabecera|nitEmisor","99999999"
xml.UpdateChildContent "cabecera|razonSocialEmisor","Abc Xyz"
xml.UpdateChildContent "cabecera|municipio","Cochabamba - Cochabamba"
xml.UpdateChildContent "cabecera|telefono","4444444"
xml.UpdateChildContent "cabecera|numeroFactura","417"
xml.UpdateChildContent "cabecera|cuf","ABABABABABABABABABABABABABABABABABABABABABABABABABABABABA"
xml.UpdateChildContent "cabecera|cufd","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
xml.UpdateChildContent "cabecera|codigoSucursal","0"
xml.UpdateChildContent "cabecera|direccion","aaa aaa aaa"
xml.UpdateChildContent "cabecera|codigoPuntoVenta","1"
xml.UpdateChildContent "cabecera|fechaEmision","2023-04-13T22:43:22.417"
xml.UpdateChildContent "cabecera|nombreRazonSocial","xyz"
xml.UpdateChildContent "cabecera|codigoTipoDocumentoIdentidad","1"
xml.UpdateChildContent "cabecera|numeroDocumento","1234567"
success = xml.UpdateAttrAt("cabecera|complemento",True,"xsi:nil","true")
xml.UpdateChildContent "cabecera|codigoCliente","1234567"
xml.UpdateChildContent "cabecera|codigoMetodoPago","1"
success = xml.UpdateAttrAt("cabecera|numeroTarjeta",True,"xsi:nil","true")
xml.UpdateChildContent "cabecera|montoTotal","22.00"
xml.UpdateChildContent "cabecera|montoTotalSujetoIva","22.00"
xml.UpdateChildContent "cabecera|codigoMoneda","1"
xml.UpdateChildContent "cabecera|tipoCambio","1.00"
xml.UpdateChildContent "cabecera|montoTotalMoneda","22.00"
success = xml.UpdateAttrAt("cabecera|montoGiftCard",True,"xsi:nil","true")
xml.UpdateChildContent "cabecera|descuentoAdicional","0.00"
xml.UpdateChildContent "cabecera|codigoExcepcion","1"
success = xml.UpdateAttrAt("cabecera|cafc",True,"xsi:nil","true")
xml.UpdateChildContent "cabecera|leyenda","Ley N 453: El proveedor de servicios debe habilitar medios e instrumentos para efectuar consultas y reclamaciones."
xml.UpdateChildContent "cabecera|usuario","nromero"
xml.UpdateChildContent "cabecera|codigoDocumentoSector","1"
xml.UpdateChildContent "detalle|actividadEconomica","620100"
xml.UpdateChildContent "detalle|codigoProductoSin","123456"
xml.UpdateChildContent "detalle|codigoProducto","1"
xml.UpdateChildContent "detalle|descripcion","Economicos"
xml.UpdateChildContent "detalle|cantidad","1.00"
xml.UpdateChildContent "detalle|unidadMedida","58"
xml.UpdateChildContent "detalle|precioUnitario","22.00"
xml.UpdateChildContent "detalle|montoDescuento","0.00"
xml.UpdateChildContent "detalle|subTotal","22.00"
success = xml.UpdateAttrAt("detalle|numeroSerie",True,"xsi:nil","true")
success = xml.UpdateAttrAt("detalle|numeroImei",True,"xsi:nil","true")

Dim gen As New Chilkat.XmlDSigGen

gen.SigLocation = "facturaElectronicaCompraVenta"
gen.SigLocationMod = 0
gen.SigNamespacePrefix = ""
gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
gen.SignedInfoCanonAlg = "C14N"
gen.SignedInfoDigestMethod = "sha256"

success = gen.AddSameDocRef("","sha256","C14N_WithComments","","")

// Provide your certificate + private key. (PFX password is test123)
Dim cert As New Chilkat.Cert
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> True) Then
    System.DebugLog(cert.LastErrorText)
    Return
End If

success = gen.SetX509Cert(cert,True)

gen.KeyInfoType = "X509Data"
gen.X509Type = "Certificate"

gen.Behaviors = "EnvelopedTransformFirst"

// Load XML to be signed...
Dim sbXml As New Chilkat.StringBuilder
xml.EmitCompact = True
success = xml.GetXmlSb(sbXml)

// Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> True) Then
    System.DebugLog(gen.LastErrorText)
    Return
End If

// -----------------------------------------------

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

System.DebugLog(sbXml.GetAsString())

// ----------------------------------------
// Verify the signatures we just produced...
Dim verifier As New Chilkat.XmlDSig
success = verifier.LoadSignatureSb(sbXml)
If (success <> True) Then
    System.DebugLog(verifier.LastErrorText)
    Return
End If

Dim numSigs As Int32
numSigs = verifier.NumSignatures
Dim verifyIdx As Int32
verifyIdx = 0
While verifyIdx < numSigs
    verifier.Selector = verifyIdx
    Dim verified As Boolean
    verified = verifier.VerifySignature(True)
    If (verified <> True) Then
        System.DebugLog(verifier.LastErrorText)
        Return
    End If

    verifyIdx = verifyIdx + 1
Wend
System.DebugLog("All signatures were successfully verified.")

 

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