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
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) Paraguay E-Invoicing Signed XML (SIFEN)

See more XML Digital Signatures Examples

Demonstrates how to sign XML for e-invoicing -- SISTEMA INTEGRADO DE FACTURACIÓN ELECTRÓNICA NACIONAL (SIFEN). This is for signing XML files that need to be submitted to a government agency (Country Paraguay, SIFEN / EKUATIA, Sistema Nacional de Facturacion Electrónica).

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_XmlToSign
oleobject loo_Gen
oleobject loo_Xml1
oleobject loo_Cert
oleobject loo_SbXml
oleobject loo_Verifier
integer li_NumSigs
integer li_VerifyIdx
integer li_Verified

li_Success = 1

// Create the XML to be signed...

// Use this online tool to generate code from sample XML: 
// Generate Code to Create XML

loo_XmlToSign = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
    destroy loo_XmlToSign
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_XmlToSign.Tag = "rDE"
loo_XmlToSign.AddAttribute("xmlns","http://ekuatia.set.gov.py/sifen/xsd")
loo_XmlToSign.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
loo_XmlToSign.AddAttribute("xsi:schemaLocation","http://ekuatia.set.gov.py/sifen/xsd siRecepDE_v150.xsd")
loo_XmlToSign.UpdateChildContent("dVerFor","150")
loo_XmlToSign.UpdateAttrAt("DE",1,"Id","01800228774059001001501012022091519999999990")
loo_XmlToSign.UpdateChildContent("DE|dDVId","0")
loo_XmlToSign.UpdateChildContent("DE|dFecFirma","2022-09-15T10:23:05")
loo_XmlToSign.UpdateChildContent("DE|dSisFact","1")
loo_XmlToSign.UpdateChildContent("DE|gOpeDE|iTipEmi","1")
loo_XmlToSign.UpdateChildContent("DE|gOpeDE|dDesTipEmi","Normal")
loo_XmlToSign.UpdateChildContent("DE|gOpeDE|dCodSeg","999999999")
loo_XmlToSign.UpdateChildContent("DE|gOpeDE|dInfoEmi","GENERADA DE PEDIDO 131043202")
loo_XmlToSign.UpdateChildContent("DE|gTimb|iTiDE","1")
loo_XmlToSign.UpdateChildContent("DE|gTimb|dDesTiDE","Factura electr�nica")
loo_XmlToSign.UpdateChildContent("DE|gTimb|dNumTim","18889014")
loo_XmlToSign.UpdateChildContent("DE|gTimb|dEst","059")
loo_XmlToSign.UpdateChildContent("DE|gTimb|dPunExp","001")
loo_XmlToSign.UpdateChildContent("DE|gTimb|dNumDoc","0015010")
loo_XmlToSign.UpdateChildContent("DE|gTimb|dFeIniT","2022-05-25")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|dFeEmiDE","2022-09-15T10:22:57")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|iTipTra","1")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|dDesTipTra","Venta de mercader�a")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|iTImp","1")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|dDesTImp","IVA")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|cMoneOpe","PYG")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gOpeCom|dDesMoneOpe","Guarani")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dRucEm","80022877")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDVEmi","4")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|iTipCont","1")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cTipReg","1")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dNomEmi","ABCDEF SA")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dNomFanEmi","ABCDEF SA")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDirEmi","Jos� Abcde Xyz N� 666 e/Abxyz123")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dNumCas","0")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dCompDir1","N/A")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dCompDir2","N/A")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cDepEmi","12")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDesDepEmi","CENTRAL")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cDisEmi","153")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDesDisEmi","CAPIATA")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|cCiuEmi","1234")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDesCiuEmi","CAPIATA")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dTelEmi","(022) 1111 000")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dEmailE","somebody@example.com.py")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|dDenSuc","PUNTO 99")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|gActEco|cActEco","47721")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gEmis|gActEco|dDesActEco","COMERCIO AL POR MENOR DE PRODUCTOS")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|iNatRec","1")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|iTiOpe","2")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|cPaisRec","PRY")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dDesPaisRe","Paraguay")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|iTiContRec","2")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dRucRec","80082971")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dDVRec","9")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dNomRec","XXXXXXX")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dNomFanRec","XXXXXXX")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dNumCasRec","0")
loo_XmlToSign.UpdateChildContent("DE|gDatGralOpe|gDatRec|dCodCliente","9999999")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamFE|iIndPres","1")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamFE|dDesIndPres","Operaci�n presencial")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|iCondOpe","1")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|dDCondOpe","Contado")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|iTiPago","1")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|dDesTiPag","Efectivo")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|dMonTiPag","100000.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|cMoneTiPag","PYG")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni|dDMoneTiPag","Guarani")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|iTiPago","1")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|dDesTiPag","Efectivo")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|dMonTiPag","73600.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|cMoneTiPag","PYG")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamCond|gPaConEIni[1]|dDMoneTiPag","Guarani")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dCodInt","818181")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dDesProSer","Widget Abc Xyz")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|cUniMed","77")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dDesUniMed","UNI")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|dCantProSer","2.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|dPUniProSer","16500.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|dTotBruOpeItem","33000.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dDescItem","3300.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dPorcDesIt","20.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gValorItem|gValorRestaItem|dTotOpeItem","26400.0000")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|iAfecIVA","1")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dDesAfecIVA","Gravado IVA")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dPropIVA","100")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dTasaIVA","5")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dBasGravIVA","25142.8571")
loo_XmlToSign.UpdateChildContent("DE|gDtipDE|gCamItem|gCamIVA|dLiqIVAItem","1257.1429")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dSubExe","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dSub5","26400.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dSub10","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotOpe","26400.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotDesc","6600.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotDescGlotem","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotAntItem","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotAnt","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dPorcDescTotal","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dDescTotal","6600.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dAnticipo","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dRedon","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotGralOpe","26400.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dIVA5","1257.1429")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dIVA10","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTotIVA","1257.1429")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dBaseGrav5","25142.8571")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dBaseGrav10","0.0000")
loo_XmlToSign.UpdateChildContent("DE|gTotSub|dTBasGraIVA","25142.8571")

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

// -------- Reference 1 --------
loo_Xml1 = create oleobject
// Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
li_rc = loo_Xml1.ConnectToNewObject("Chilkat.Xml")

loo_Xml1.Tag = "Transforms"
loo_Xml1.UpdateAttrAt("Transform",1,"Algorithm","http://www.w3.org/2000/09/xmldsig#enveloped-signature")
loo_Xml1.UpdateAttrAt("Transform[1]",1,"Algorithm","http://www.w3.org/2001/10/xml-exc-c14n#")

loo_Gen.AddSameDocRef2("01800228774059001001501012022091516941989060","sha256",loo_Xml1,"")

// Provide a 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_XmlToSign
    destroy loo_Gen
    destroy loo_Xml1
    destroy loo_Cert
    return
end if

loo_Gen.SetX509Cert(loo_Cert,1)

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

// 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_XmlToSign.GetXmlSb(loo_SbXml)

loo_Gen.Behaviors = "IndentedSignature"

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

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

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

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

 

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