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

Visual FoxPro 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

 

 

 

(Visual FoxPro) 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

LOCAL lnSuccess
LOCAL loXmlToSign
LOCAL loGen
LOCAL loXml1
LOCAL loCert
LOCAL loSbXml
LOCAL loVerifier
LOCAL lnNumSigs
LOCAL lnVerifyIdx
LOCAL lnVerified

lnSuccess = 1

* Create the XML to be signed...

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

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSigGen')
loGen = CreateObject('Chilkat.XmlDSigGen')

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

* -------- Reference 1 --------
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml')
loXml1 = CreateObject('Chilkat.Xml')
loXml1.Tag = "Transforms"
loXml1.UpdateAttrAt("Transform",1,"Algorithm","http://www.w3.org/2000/09/xmldsig#enveloped-signature")
loXml1.UpdateAttrAt("Transform[1]",1,"Algorithm","http://www.w3.org/2001/10/xml-exc-c14n#")

loGen.AddSameDocRef2("01800228774059001001501012022091516941989060","sha256",loXml1,"")

* Provide a 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 loXmlToSign
    RELEASE loGen
    RELEASE loXml1
    RELEASE loCert
    CANCEL
ENDIF

loGen.SetX509Cert(loCert,1)

loGen.KeyInfoType = "X509Data"
loGen.X509Type = "Certificate"

* Load XML to be signed...
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbXml = CreateObject('Chilkat.StringBuilder')
loXmlToSign.GetXmlSb(loSbXml)

loGen.Behaviors = "IndentedSignature"

* Sign the XML...
lnSuccess = loGen.CreateXmlDSigSb(loSbXml)
IF (lnSuccess <> 1) THEN
    ? loGen.LastErrorText
    RELEASE loXmlToSign
    RELEASE loGen
    RELEASE loXml1
    RELEASE loCert
    RELEASE loSbXml
    CANCEL
ENDIF

* -----------------------------------------------

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

? 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 loXmlToSign
    RELEASE loGen
    RELEASE loXml1
    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 loXmlToSign
        RELEASE loGen
        RELEASE loXml1
        RELEASE loCert
        RELEASE loSbXml
        RELEASE loVerifier
        CANCEL
    ENDIF

    lnVerifyIdx = lnVerifyIdx + 1
ENDDO
? "All signatures were successfully verified."

RELEASE loXmlToSign
RELEASE loGen
RELEASE loXml1
RELEASE loCert
RELEASE loSbXml
RELEASE loVerifier


 

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