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

PowerBuilder 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
Secrets
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

 

 

 

(PowerBuilder) 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 ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Xml
oleobject loo_Gen
oleobject loo_Cert
oleobject loo_SbXml
oleobject loo_Verifier
integer li_NumSigs
integer li_VerifyIdx
integer li_Verified

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

li_Success = 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

loo_Xml = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
    destroy loo_Xml
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Xml.Tag = "facturaElectronicaCompraVenta"
loo_Xml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
loo_Xml.AddAttribute("xsi:noNamespaceSchemaLocation","facturaElectronicaCompraVenta.xsd")
loo_Xml.UpdateChildContent("cabecera|nitEmisor","99999999")
loo_Xml.UpdateChildContent("cabecera|razonSocialEmisor","Abc Xyz")
loo_Xml.UpdateChildContent("cabecera|municipio","Cochabamba - Cochabamba")
loo_Xml.UpdateChildContent("cabecera|telefono","4444444")
loo_Xml.UpdateChildContent("cabecera|numeroFactura","417")
loo_Xml.UpdateChildContent("cabecera|cuf","ABABABABABABABABABABABABABABABABABABABABABABABABABABABABA")
loo_Xml.UpdateChildContent("cabecera|cufd","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
loo_Xml.UpdateChildContent("cabecera|codigoSucursal","0")
loo_Xml.UpdateChildContent("cabecera|direccion","aaa aaa aaa")
loo_Xml.UpdateChildContent("cabecera|codigoPuntoVenta","1")
loo_Xml.UpdateChildContent("cabecera|fechaEmision","2023-04-13T22:43:22.417")
loo_Xml.UpdateChildContent("cabecera|nombreRazonSocial","xyz")
loo_Xml.UpdateChildContent("cabecera|codigoTipoDocumentoIdentidad","1")
loo_Xml.UpdateChildContent("cabecera|numeroDocumento","1234567")
loo_Xml.UpdateAttrAt("cabecera|complemento",1,"xsi:nil","true")
loo_Xml.UpdateChildContent("cabecera|codigoCliente","1234567")
loo_Xml.UpdateChildContent("cabecera|codigoMetodoPago","1")
loo_Xml.UpdateAttrAt("cabecera|numeroTarjeta",1,"xsi:nil","true")
loo_Xml.UpdateChildContent("cabecera|montoTotal","22.00")
loo_Xml.UpdateChildContent("cabecera|montoTotalSujetoIva","22.00")
loo_Xml.UpdateChildContent("cabecera|codigoMoneda","1")
loo_Xml.UpdateChildContent("cabecera|tipoCambio","1.00")
loo_Xml.UpdateChildContent("cabecera|montoTotalMoneda","22.00")
loo_Xml.UpdateAttrAt("cabecera|montoGiftCard",1,"xsi:nil","true")
loo_Xml.UpdateChildContent("cabecera|descuentoAdicional","0.00")
loo_Xml.UpdateChildContent("cabecera|codigoExcepcion","1")
loo_Xml.UpdateAttrAt("cabecera|cafc",1,"xsi:nil","true")
loo_Xml.UpdateChildContent("cabecera|leyenda","Ley N� 453: El proveedor de servicios debe habilitar medios e instrumentos para efectuar consultas y reclamaciones.")
loo_Xml.UpdateChildContent("cabecera|usuario","nromero")
loo_Xml.UpdateChildContent("cabecera|codigoDocumentoSector","1")
loo_Xml.UpdateChildContent("detalle|actividadEconomica","620100")
loo_Xml.UpdateChildContent("detalle|codigoProductoSin","123456")
loo_Xml.UpdateChildContent("detalle|codigoProducto","1")
loo_Xml.UpdateChildContent("detalle|descripcion","Economicos")
loo_Xml.UpdateChildContent("detalle|cantidad","1.00")
loo_Xml.UpdateChildContent("detalle|unidadMedida","58")
loo_Xml.UpdateChildContent("detalle|precioUnitario","22.00")
loo_Xml.UpdateChildContent("detalle|montoDescuento","0.00")
loo_Xml.UpdateChildContent("detalle|subTotal","22.00")
loo_Xml.UpdateAttrAt("detalle|numeroSerie",1,"xsi:nil","true")
loo_Xml.UpdateAttrAt("detalle|numeroImei",1,"xsi:nil","true")

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 = "facturaElectronicaCompraVenta"
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"

loo_Gen.AddSameDocRef("","sha256","C14N_WithComments","","")

// Provide your 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_Xml
    destroy loo_Gen
    destroy loo_Cert
    return
end if

loo_Gen.SetX509Cert(loo_Cert,1)

loo_Gen.KeyInfoType = "X509Data"
loo_Gen.X509Type = "Certificate"

loo_Gen.Behaviors = "EnvelopedTransformFirst"

// 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_Xml.EmitCompact = 1
loo_Xml.GetXmlSb(loo_SbXml)

// Sign the XML...
li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml)
if li_Success <> 1 then
    Write-Debug loo_Gen.LastErrorText
    destroy loo_Xml
    destroy loo_Gen
    destroy loo_Cert
    destroy loo_SbXml
    return
end if

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

// Save the signed XML to a file.
li_Success = loo_SbXml.WriteFile("qa_output/signedXml.xml","utf-8",1)

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_Xml
    destroy loo_Gen
    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_Xml
        destroy loo_Gen
        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_Xml
destroy loo_Gen
destroy loo_Cert
destroy loo_SbXml
destroy loo_Verifier

 

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