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

DataFlex 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

 

 

 

(DataFlex) 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

Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoXmlToSign
    Handle hoGen
    Variant vXml1
    Handle hoXml1
    Variant vCert
    Handle hoCert
    Variant vSbXml
    Handle hoSbXml
    Handle hoVerifier
    Integer iNumSigs
    Integer iVerifyIdx
    Boolean iVerified
    String sTemp1

    Move True To iSuccess

    // Create the XML to be signed...

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

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

    Get Create (RefClass(cComChilkatXmlDSigGen)) To hoGen
    If (Not(IsComObjectCreated(hoGen))) Begin
        Send CreateComObject of hoGen
    End

    Set ComSigLocation Of hoGen To "rDE"
    Set ComSigLocationMod Of hoGen To 0
    Set ComSigNamespacePrefix Of hoGen To ""
    Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#"
    Set ComSignedInfoCanonAlg Of hoGen To "C14N"
    Set ComSignedInfoDigestMethod Of hoGen To "sha256"

    // -------- Reference 1 --------
    Get Create (RefClass(cComChilkatXml)) To hoXml1
    If (Not(IsComObjectCreated(hoXml1))) Begin
        Send CreateComObject of hoXml1
    End
    Set ComTag Of hoXml1 To "Transforms"
    Get ComUpdateAttrAt Of hoXml1 "Transform" True "Algorithm" "http://www.w3.org/2000/09/xmldsig#enveloped-signature" To iSuccess
    Get ComUpdateAttrAt Of hoXml1 "Transform[1]" True "Algorithm" "http://www.w3.org/2001/10/xml-exc-c14n#" To iSuccess

    Get pvComObject of hoXml1 to vXml1
    Get ComAddSameDocRef2 Of hoGen "01800228774059001001501012022091516941989060" "sha256" vXml1 "" To iSuccess

    // Provide a certificate + private key. (PFX password is test123)
    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get ComLoadPfxFile Of hoCert "qa_data/pfx/cert_test123.pfx" "test123" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoCert To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get pvComObject of hoCert to vCert
    Get ComSetX509Cert Of hoGen vCert True To iSuccess

    Set ComKeyInfoType Of hoGen To "X509Data"
    Set ComX509Type Of hoGen To "Certificate"

    // Load XML to be signed...
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
    If (Not(IsComObjectCreated(hoSbXml))) Begin
        Send CreateComObject of hoSbXml
    End
    Get pvComObject of hoSbXml to vSbXml
    Get ComGetXmlSb Of hoXmlToSign vSbXml To iSuccess

    Set ComBehaviors Of hoGen To "IndentedSignature"

    // Sign the XML...
    Get pvComObject of hoSbXml to vSbXml
    Get ComCreateXmlDSigSb Of hoGen vSbXml To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoGen To sTemp1
        Showln sTemp1
        Procedure_Return
    End

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

    // Save the signed XML to a file.
    Get ComWriteFile Of hoSbXml "c:/temp/qa_output/signedXml.xml" "utf-8" False To iSuccess

    Get ComGetAsString Of hoSbXml To sTemp1
    Showln sTemp1

    // ----------------------------------------
    // Verify the signatures we just produced...
    Get Create (RefClass(cComChilkatXmlDSig)) To hoVerifier
    If (Not(IsComObjectCreated(hoVerifier))) Begin
        Send CreateComObject of hoVerifier
    End
    Get pvComObject of hoSbXml to vSbXml
    Get ComLoadSignatureSb Of hoVerifier vSbXml To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoVerifier To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumSignatures Of hoVerifier To iNumSigs
    Move 0 To iVerifyIdx
    While (iVerifyIdx < iNumSigs)
        Set ComSelector Of hoVerifier To iVerifyIdx
        Get ComVerifySignature Of hoVerifier True To iVerified
        If (iVerified <> True) Begin
            Get ComLastErrorText Of hoVerifier To sTemp1
            Showln sTemp1
            Procedure_Return
        End

        Move (iVerifyIdx + 1) To iVerifyIdx
    Loop

    Showln "All signatures were successfully verified."


End_Procedure

 

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