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

 

 

 

(DataFlex) Create sii.cl Factura Electrónica (Chile Servicio de Impuestos Internos)

Demonstrates how to sign an XML invoice according to Chilean Internal Revenue Service regulations.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

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

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

    // See: Apply 2nd Signature to sii.cl Factura Electr�nica (Chile Servicio de Impuestos Internos)
    // for an example showing how to apply a 2nd signature.

    // We want to sign XML that looks like the following:

    // <?xml version="1.0" encoding="iso-8859-1"?>
    // <DTE version="1.0" xmlns="http://www.sii.cl/SiiDte">
    //     <Documento ID="F13T34">
    //         <Encabezado>
    //             <IdDoc>
    //                 <TipoDTE>34</TipoDTE>
    //                 <Folio>13</Folio>
    //                 <FchEmis>2020-07-17</FchEmis>
    //                 <FmaPago>1</FmaPago>
    //                 <FchVenc>2020-07-17</FchVenc>
    //             </IdDoc>
    //             <Emisor>
    //                 <RUTEmisor>...</RUTEmisor>
    //                 <RznSoc>...</RznSoc>
    //                 <GiroEmis>...</GiroEmis>
    //                 <Acteco>...</Acteco>
    //                 <DirOrigen>...</DirOrigen>
    //                 <CmnaOrigen>...</CmnaOrigen>
    //                 <CiudadOrigen>...</CiudadOrigen>
    //             </Emisor>
    //             <Receptor>
    //                 <RUTRecep>...</RUTRecep>
    //                 <RznSocRecep>...</RznSocRecep>
    //                 <GiroRecep>...</GiroRecep>
    //                 <Contacto/>
    //                 <DirRecep>...</DirRecep>
    //                 <CmnaRecep>...</CmnaRecep>
    //                 <CiudadRecep>...</CiudadRecep>
    //             </Receptor>
    //             <Totales>
    //                 <MntExe>14999</MntExe>
    //                 <MntTotal>14999</MntTotal>
    //             </Totales>
    //         </Encabezado>
    //         <Detalle>
    //             <NroLinDet>1</NroLinDet>
    //             <CdgItem>
    //                 <TpoCodigo>INT</TpoCodigo>
    //                 <VlrCodigo>1</VlrCodigo>
    //             </CdgItem>
    //             <NmbItem>Atencin profesional mes de Junio 2020</NmbItem>
    //             <QtyItem>1</QtyItem>
    //             <UnmdItem>UNI</UnmdItem>
    //             <PrcItem>14999</PrcItem>
    //             <MontoItem>14999</MontoItem>
    //         </Detalle>
    //         <TED version="1.0">
    //             <DD>
    //                 <RE>99972220-K</RE>
    //                 <TD>34</TD>
    //                 <F>13</F>
    //                 <FE>2020-07-17</FE>
    //                 <RR>99942999-2</RR>
    //                 <RSR>...</RSR>
    //                 <MNT>14999</MNT>
    //                 <IT1>Atencion profesional mes de Junio 2020</IT1>
    //                 <CAF version="1.0">
    //                     <DA>
    //                         <RE>99972220-K</RE>
    //                         <RS>...</RS>
    //                         <TD>34</TD>
    //                         <RNG>
    //                             <D>3</D>
    //                             <H>12</H>
    //                         </RNG>
    //                         <FA>2019-10-10</FA>
    //                         <RSAPK>
    //                             <M>2zHVYpcVNQRvS2yFuqdrh...TEQZx/m0t9HVTgWKZvlc6LSQ==</M>
    //                             <E>Aw==</E>
    //                         </RSAPK>
    //                         <IDK>300</IDK>
    //                     </DA>
    //                     <FRMA algoritmo="SHA1withRSA">LaVkjISGu...sBtsQL1jR9lw==</FRMA>
    //                 </CAF>
    //                 <TSTED>2020-07-17T13:19:10</TSTED>
    //             </DD>
    //             <FRMT algoritmo="SHA1withRSA">LxZr6zmXRZIfTz7...IXS6sp4vfz2fIsA==</FRMT>
    //         </TED>
    //         <TmstFirma>2020-07-17T13:19:10</TmstFirma>
    //     </Documento>
    // </DTE>

    Move True To iSuccess

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

    Set ComSigLocation Of hoGen To "DTE"
    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 "sha1"

    // -------- Reference 1 --------
    Get ComAddSameDocRef Of hoGen "F13T34" "sha1" "" "" "" 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+KeyValue"
    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 ComLoadFile Of hoSbXml "qa_data/xml_dsig/sii_cl/xmlToSign.xml" "iso-8859-1" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load XML file."
        Procedure_Return
    End

    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 "qa_data/xml_dsig/sii_cl/signed1.xml" "iso-8859-1" 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.