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
uncategorized

 

 

 

(DataFlex) Cape Verde Fatura Eletrónica XML Digital Signature

See more XML Digital Signatures Examples

Demonstrates how to sign XML to create a signed invoice compatible with the Cape Verde Fatura Eletrónica requirements.

Note: This example requires Chilkat v9.5.0.89 or greater for a small feature to provide the ability produce mult-line base64 signature ending with 

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoXmlToSign
    Handle hoGen
    Handle hoObject1
    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.

    // First create the following XML to be signed.  This can be created programmatically as shown in the code below, or 
    // you can simply load the XML to be signed from a file..

    // <?xml version="1.0" encoding="utf-8"?>
    // <Dfe xmlns="urn:cv:efatura:xsd:v1.0" DocumentTypeCode="1" Id="CV2210818123456789000010100000000546735014601" Version="1.0">
    //     <Invoice>
    //         <LedCode>1</LedCode>
    //         <Serie>SL</Serie>
    //         <DocumentNumber>5</DocumentNumber>
    //         <IssueDate>2021-08-30</IssueDate>
    //         <IssueTime>00:01:00</IssueTime>
    //         <TaxPointDate>2021-08-18</TaxPointDate>
    //         <EmitterParty>
    //             <TaxId CountryCode="CV">123456789</TaxId>
    //             <Name>Maria</Name>
    //             <Address CountryCode="CV">
    //                 <State>Estado do Emissor</State>
    //                 <City>Cidade do Emissor</City>
    //                 <Region>Regio do Emissor</Region>
    //                 <Street>Rua do Emissor</Street>
    //                 <StreetDetail>Detalhe da rua do Emissor</StreetDetail>
    //                 <BuildingName>Prdio do Emissor</BuildingName>
    //                 <BuildingNumber>1</BuildingNumber>
    //                 <BuildingFloor>2</BuildingFloor>
    //                 <PostalCode>7600</PostalCode>
    //                 <AddressDetail>Detalhe de endereo do Emissor</AddressDetail>
    //                 <AddressCode>CV774999999999999319</AddressCode>
    //             </Address>
    //             <Contacts>
    //                 <Telephone>1234567</Telephone>
    //                 <Mobilephone>1234568</Mobilephone>
    //                 <Telefax>1234569</Telefax>
    //                 <Email>somebody@example.com</Email>
    //                 <Website>emissor.efatura.cv</Website>
    //             </Contacts>
    //         </EmitterParty>
    //         <ReceiverParty>
    //             <TaxId CountryCode="CV">123456789</TaxId>
    //             <Name>Nome do Recetor</Name>
    //             <Address CountryCode="CV">
    //                 <State>Estado do Recetor</State>
    //                 <City>Cidade do Recetor</City>
    //                 <Region>Regio do Recetor</Region>
    //                 <Street>Rua do Recetor</Street>
    //                 <StreetDetail>Detalhe da rua do Recetor</StreetDetail>
    //                 <BuildingName>Prdio do Recetor</BuildingName>
    //                 <BuildingNumber>2</BuildingNumber>
    //                 <BuildingFloor>3</BuildingFloor>
    //                 <PostalCode>7601</PostalCode>
    //                 <AddressDetail>Detalhe de endereo do Recetor</AddressDetail>
    //                 <AddressCode>CV774999999999999319</AddressCode>
    //             </Address>
    //             <Contacts>
    //                 <Telephone>2234567</Telephone>
    //                 <Mobilephone>2234568</Mobilephone>
    //                 <Telefax>2234569</Telefax>
    //                 <Email>rector@efatura.cv</Email>
    //                 <Website>rector.efatura.cv</Website>
    //             </Contacts>
    //         </ReceiverParty>
    //         <Lines>
    //             <Line LineTypeCode="N">
    //                 <Id>01</Id>
    //                 <OrderLineReference>1</OrderLineReference>
    //                 <Quantity UnitCode="EA">3.15</Quantity>
    //                 <Price>123456</Price>
    //                 <PriceExtension>388886</PriceExtension>
    //                 <Discount>15</Discount>
    //                 <NetTotal>252776</NetTotal>
    //                 <Tax TaxTypeCode="IVA">
    //                     <TaxPercentage>15</TaxPercentage>
    //                 </Tax>
    //                 <Item>
    //                     <Description>Telemvel</Description>
    //                     <Name>Telemvel</Name>
    //                     <BrandName>Apple</BrandName>
    //                     <ModelName>iPhone X</ModelName>
    //                     <EmitterIdentification>TLMV</EmitterIdentification>
    //                     <StandardIdentification>
    //                         <GTIN>12345</GTIN>
    //                     </StandardIdentification>
    //                     <HazardousRiskIndicator>false</HazardousRiskIndicator>
    //                 </Item>
    //             </Line>
    //         </Lines>
    //         <Totals>
    //             <PriceExtensionTotalAmount>388886</PriceExtensionTotalAmount>
    //             <ChargeTotalAmount>0</ChargeTotalAmount>
    //             <DiscountTotalAmount>136110</DiscountTotalAmount>
    //             <NetTotalAmount>252776</NetTotalAmount>
    //             <Discount ValueType="P">20</Discount>
    //             <TaxTotalAmount>37916</TaxTotalAmount>
    //             <PayableAmount>290692</PayableAmount>
    //         </Totals>
    //         <References>
    //             <Reference>
    //                 <FiscalDocument IsOldDocument="false">CV1200520123456789000112345678901112345678901</FiscalDocument>
    //                 <PaymentAmount>12345</PaymentAmount>
    //                 <Tax TaxTypeCode="IR">
    //                     <TaxPercentage>10</TaxPercentage>
    //                 </Tax>
    //             </Reference>
    //             <Reference>
    //                 <FiscalDocument IsOldDocument="false">CV1200520123456789000112345678901112345678903</FiscalDocument>
    //                 <PaymentAmount>98765</PaymentAmount>
    //                 <Tax TaxTypeCode="IVA">
    //                     <TaxPercentage>15</TaxPercentage>
    //                 </Tax>
    //             </Reference>
    //         </References>
    //         <Payments>
    //             <PaymentDueDate>2021-12-31</PaymentDueDate>
    //             <PaymentTerms>
    //                 <Note>Juros de 12% a partir da data de vencimento</Note>
    //             </PaymentTerms>
    //             <PayeeFinancialAccount>
    //                 <NIB>123456789012345678901</NIB>
    //                 <Name>Nome da Conta 1</Name>
    //             </PayeeFinancialAccount>
    //             <PayeeFinancialAccount>
    //                 <NIB>123456789012345678902</NIB>
    //                 <Name>Nome da Conta 2</Name>
    //             </PayeeFinancialAccount>
    //         </Payments>
    //         <Note>Texto livre</Note>
    //     </Invoice>
    //     <Transmission>
    //         <IssueMode>2</IssueMode>
    //         <TransmitterTaxId CountryCode="CV">123456789</TransmitterTaxId>
    //         <Software>
    //             <Code>EMIPUB</Code>
    //             <Name>DNRE Emissor Pblico</Name>
    //             <Version>Build #53 12-07-2021 14:00:47 CVT - master</Version>
    //         </Software>
    //         <Contingency>
    //             <LedCode>1</LedCode>
    //             <IssueDate>2020-01-01</IssueDate>
    //             <IssueTime>01:02:03</IssueTime>
    //             <ReasonTypeCode>1</ReasonTypeCode>
    //         </Contingency>
    //     </Transmission>
    //     <RepositoryCode>2</RepositoryCode>
    // </Dfe>

    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 "Dfe"
    Get ComAddAttribute Of hoXmlToSign "xmlns" "urn:cv:efatura:xsd:v1.0" To iSuccess
    Get ComAddAttribute Of hoXmlToSign "DocumentTypeCode" "1" To iSuccess
    Get ComAddAttribute Of hoXmlToSign "Id" "CV2210818123456789000010100000000546735014601" To iSuccess
    Get ComAddAttribute Of hoXmlToSign "Version" "1.0" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|LedCode" "1"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Serie" "SL"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|DocumentNumber" "5"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|IssueDate" "2021-08-30"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|IssueTime" "00:01:00"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|TaxPointDate" "2021-08-18"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|EmitterParty|TaxId" True "CountryCode" "CV" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|TaxId" "123456789"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Name" "Maria"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|EmitterParty|Address" True "CountryCode" "CV" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|State" "Estado do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|City" "Cidade do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|Region" "Regio do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|Street" "Rua do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|StreetDetail" "Detalhe da rua do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|BuildingName" "Prdio do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|BuildingNumber" "1"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|BuildingFloor" "2"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|PostalCode" "7600"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|AddressDetail" "Detalhe de endereo do Emissor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Address|AddressCode" "CV774999999999999319"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Contacts|Telephone" "1234567"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Contacts|Mobilephone" "1234568"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Contacts|Telefax" "1234569"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Contacts|Email" "somebody@example.com"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|EmitterParty|Contacts|Website" "emissor.efatura.cv"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|ReceiverParty|TaxId" True "CountryCode" "CV" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|TaxId" "123456789"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Name" "Nome do Recetor"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|ReceiverParty|Address" True "CountryCode" "CV" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|State" "Estado do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|City" "Cidade do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|Region" "Regio do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|Street" "Rua do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|StreetDetail" "Detalhe da rua do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|BuildingName" "Prdio do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|BuildingNumber" "2"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|BuildingFloor" "3"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|PostalCode" "7601"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|AddressDetail" "Detalhe de endereo do Recetor"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Address|AddressCode" "CV774999999999999319"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Contacts|Telephone" "2234567"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Contacts|Mobilephone" "2234568"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Contacts|Telefax" "2234569"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Contacts|Email" "rector@efatura.cv"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|ReceiverParty|Contacts|Website" "rector.efatura.cv"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|Lines|Line" True "LineTypeCode" "N" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Id" "01"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|OrderLineReference" "1"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|Lines|Line|Quantity" True "UnitCode" "EA" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Quantity" "3.15"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Price" "123456"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|PriceExtension" "388886"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Discount" "15"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|NetTotal" "252776"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|Lines|Line|Tax" True "TaxTypeCode" "IVA" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Tax|TaxPercentage" "15"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|Description" "Telemvel"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|Name" "Telemvel"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|BrandName" "Apple"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|ModelName" "iPhone X"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|EmitterIdentification" "TLMV"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|StandardIdentification|GTIN" "12345"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Lines|Line|Item|HazardousRiskIndicator" "false"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|PriceExtensionTotalAmount" "388886"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|ChargeTotalAmount" "0"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|DiscountTotalAmount" "136110"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|NetTotalAmount" "252776"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|Totals|Discount" True "ValueType" "P" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|Discount" "20"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|TaxTotalAmount" "37916"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Totals|PayableAmount" "290692"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|References|Reference|FiscalDocument" True "IsOldDocument" "false" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|References|Reference|FiscalDocument" "CV1200520123456789000112345678901112345678901"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|References|Reference|PaymentAmount" "12345"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|References|Reference|Tax" True "TaxTypeCode" "IR" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|References|Reference|Tax|TaxPercentage" "10"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|References|Reference[1]|FiscalDocument" True "IsOldDocument" "false" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|References|Reference[1]|FiscalDocument" "CV1200520123456789000112345678901112345678903"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|References|Reference[1]|PaymentAmount" "98765"
    Get ComUpdateAttrAt Of hoXmlToSign "Invoice|References|Reference[1]|Tax" True "TaxTypeCode" "IVA" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Invoice|References|Reference[1]|Tax|TaxPercentage" "15"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Payments|PaymentDueDate" "2021-12-31"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Payments|PaymentTerms|Note" "Juros de 12% a partir da data de vencimento"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Payments|PayeeFinancialAccount|NIB" "123456789012345678901"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Payments|PayeeFinancialAccount|Name" "Nome da Conta 1"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Payments|PayeeFinancialAccount[1]|NIB" "123456789012345678902"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Payments|PayeeFinancialAccount[1]|Name" "Nome da Conta 2"
    Send ComUpdateChildContent To hoXmlToSign "Invoice|Note" "Texto livre"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|IssueMode" "2"
    Get ComUpdateAttrAt Of hoXmlToSign "Transmission|TransmitterTaxId" True "CountryCode" "CV" To iSuccess
    Send ComUpdateChildContent To hoXmlToSign "Transmission|TransmitterTaxId" "123456789"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Software|Code" "EMIPUB"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Software|Name" "DNRE Emissor Pblico"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Software|Version" "Build #53 12-07-2021 14:00:47 CVT - master"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Contingency|LedCode" "1"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Contingency|IssueDate" "2020-01-01"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Contingency|IssueTime" "01:02:03"
    Send ComUpdateChildContent To hoXmlToSign "Transmission|Contingency|ReasonTypeCode" "1"
    Send ComUpdateChildContent To hoXmlToSign "RepositoryCode" "2"

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

    Set ComSigLocation Of hoGen To "Dfe"
    Set ComSigLocationMod Of hoGen To 0
    Set ComSigId Of hoGen To "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac"
    Set ComSigNamespacePrefix Of hoGen To "ds"
    Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#"
    Set ComSigValueId Of hoGen To "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-sigvalue"
    Set ComSignedInfoCanonAlg Of hoGen To "C14N"
    Set ComSignedInfoDigestMethod Of hoGen To "sha256"

    // Set the KeyInfoId before adding references..
    Set ComKeyInfoId Of hoGen To "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo"

    // Create an Object to be added to the Signature.
    Get Create (RefClass(cComChilkatXml)) To hoObject1
    If (Not(IsComObjectCreated(hoObject1))) Begin
        Send CreateComObject of hoObject1
    End
    Set ComTag Of hoObject1 To "xades:QualifyingProperties"
    Get ComAddAttribute Of hoObject1 "xmlns:xades" "http://uri.etsi.org/01903/v1.3.2#" To iSuccess
    Get ComAddAttribute Of hoObject1 "xmlns:xades141" "http://uri.etsi.org/01903/v1.4.1#" To iSuccess
    Get ComAddAttribute Of hoObject1 "Target" "#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac" To iSuccess
    Get ComUpdateAttrAt Of hoObject1 "xades:SignedProperties" True "Id" "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops" To iSuccess
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime" "TO BE GENERATED BY CHILKAT"
    Get ComUpdateAttrAt Of hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod" True "Algorithm" "http://www.w3.org/2001/04/xmlenc#sha256" To iSuccess
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue" "TO BE GENERATED BY CHILKAT"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName" "TO BE GENERATED BY CHILKAT"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber" "TO BE GENERATED BY CHILKAT"
    Get ComUpdateAttrAt Of hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:CertDigest|ds:DigestMethod" True "Algorithm" "http://www.w3.org/2001/04/xmlenc#sha256" To iSuccess
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:CertDigest|ds:DigestValue" "TO BE GENERATED BY CHILKAT"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:IssuerSerial|ds:X509IssuerName" "TO BE GENERATED BY CHILKAT"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:IssuerSerial|ds:X509SerialNumber" "TO BE GENERATED BY CHILKAT"
    Get ComUpdateAttrAt Of hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:CertDigest|ds:DigestMethod" True "Algorithm" "http://www.w3.org/2001/04/xmlenc#sha256" To iSuccess
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:CertDigest|ds:DigestValue" "TO BE GENERATED BY CHILKAT"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:IssuerSerial|ds:X509IssuerName" "TO BE GENERATED BY CHILKAT"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:IssuerSerial|ds:X509SerialNumber" "TO BE GENERATED BY CHILKAT"
    Get ComUpdateAttrAt Of hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat" True "ObjectReference" "#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0" To iSuccess
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description" "DFE Signature"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier" "efatura-uri"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:DocumentationReferences|xades:DocumentationReference" "https://efatura.cv"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType" "text/xml"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding" "UTF-8"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Identifier" "http://uri.etsi.org/01903/v1.2.2#ProofOfApproval"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Description" "Indicates that the signer has approved the content of the signed data object"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:AllSignedDataObjects" ""
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Identifier" "http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Description" "Indicates that the signer recognizes to have created, approved and sent the signed data object"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:ObjectReference" "#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0"
    Send ComUpdateChildContent To hoObject1 "xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeQualifiers|xades:CommitmentTypeQualifier" "CV-FE-123456789"

    Get ComGetXml Of hoObject1 To sTemp1
    Get ComAddObject Of hoGen "" sTemp1 "" "" To iSuccess

    // -------- Reference 1 --------
    Get ComAddSameDocRef Of hoGen "CV2210818123456789000010100000000546735014601" "sha256" "" "" "" To iSuccess
    Get ComSetRefIdAttr Of hoGen "CV2210818123456789000010100000000546735014601" "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0" To iSuccess

    // -------- Reference 2 --------
    Get ComAddSameDocRef Of hoGen "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo" "sha256" "C14N" "" "" To iSuccess

    // -------- Reference 3 --------
    Get ComAddObjectRef Of hoGen "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops" "sha256" "C14N" "" "http://uri.etsi.org/01903#SignedProperties" 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 "IssuerSerial,SubjectName,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

    // Note: The last keyword (Base64Cr13Entity) requires Chilkat v9.5.0.89 or later.
    Set ComBehaviors Of hoGen To "IndentedSignature,Base64Cr13Entity,ForceAddEnvelopedSignatureTransform,Base64Cr13Entity"

    // 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_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.