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

Unicode C++ 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

 

 

 

(Unicode C++) 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 C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <CkXmlW.h>
#include <CkXmlDSigGenW.h>
#include <CkCertW.h>
#include <CkStringBuilderW.h>
#include <CkXmlDSigW.h>

void ChilkatSample(void)
    {
    // 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>

    bool success = true;

    // Create the XML to be signed...

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

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

    CkXmlDSigGenW gen;

    gen.put_SigLocation(L"Dfe");
    gen.put_SigLocationMod(0);
    gen.put_SigId(L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac");
    gen.put_SigNamespacePrefix(L"ds");
    gen.put_SigNamespaceUri(L"http://www.w3.org/2000/09/xmldsig#");
    gen.put_SigValueId(L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-sigvalue");
    gen.put_SignedInfoCanonAlg(L"C14N");
    gen.put_SignedInfoDigestMethod(L"sha256");

    // Set the KeyInfoId before adding references..
    gen.put_KeyInfoId(L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo");

    // Create an Object to be added to the Signature.
    CkXmlW object1;
    object1.put_Tag(L"xades:QualifyingProperties");
    object1.AddAttribute(L"xmlns:xades",L"http://uri.etsi.org/01903/v1.3.2#");
    object1.AddAttribute(L"xmlns:xades141",L"http://uri.etsi.org/01903/v1.4.1#");
    object1.AddAttribute(L"Target",L"#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac");
    object1.UpdateAttrAt(L"xades:SignedProperties",true,L"Id",L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod",true,L"Algorithm",L"http://www.w3.org/2001/04/xmlenc#sha256");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:CertDigest|ds:DigestMethod",true,L"Algorithm",L"http://www.w3.org/2001/04/xmlenc#sha256");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:CertDigest|ds:DigestValue",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:IssuerSerial|ds:X509IssuerName",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:IssuerSerial|ds:X509SerialNumber",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:CertDigest|ds:DigestMethod",true,L"Algorithm",L"http://www.w3.org/2001/04/xmlenc#sha256");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:CertDigest|ds:DigestValue",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:IssuerSerial|ds:X509IssuerName",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:IssuerSerial|ds:X509SerialNumber",L"TO BE GENERATED BY CHILKAT");
    object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat",true,L"ObjectReference",L"#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description",L"DFE Signature");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier",L"efatura-uri");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:DocumentationReferences|xades:DocumentationReference",L"https://efatura.cv");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType",L"text/xml");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding",L"UTF-8");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Identifier",L"http://uri.etsi.org/01903/v1.2.2#ProofOfApproval");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Description",L"Indicates that the signer has approved the content of the signed data object");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:AllSignedDataObjects",L"");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Identifier",L"http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Description",L"Indicates that the signer recognizes to have created, approved and sent the signed data object");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:ObjectReference",L"#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0");
    object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeQualifiers|xades:CommitmentTypeQualifier",L"CV-FE-123456789");

    gen.AddObject(L"",object1.getXml(),L"",L"");

    // -------- Reference 1 --------
    gen.AddSameDocRef(L"CV2210818123456789000010100000000546735014601",L"sha256",L"",L"",L"");
    gen.SetRefIdAttr(L"CV2210818123456789000010100000000546735014601",L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0");

    // -------- Reference 2 --------
    gen.AddSameDocRef(L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo",L"sha256",L"C14N",L"",L"");

    // -------- Reference 3 --------
    gen.AddObjectRef(L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops",L"sha256",L"C14N",L"",L"http://uri.etsi.org/01903#SignedProperties");

    // Provide a certificate + private key. (PFX password is test123)
    CkCertW cert;
    success = cert.LoadPfxFile(L"qa_data/pfx/cert_test123.pfx",L"test123");
    if (success != true) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    gen.SetX509Cert(cert,true);

    gen.put_KeyInfoType(L"X509Data");
    gen.put_X509Type(L"IssuerSerial,SubjectName,Certificate");

    // Load XML to be signed...
    CkStringBuilderW sbXml;
    xmlToSign.GetXmlSb(sbXml);

    // Note: The last keyword (Base64Cr13Entity) requires Chilkat v9.5.0.89 or later.
    gen.put_Behaviors(L"IndentedSignature,Base64Cr13Entity,ForceAddEnvelopedSignatureTransform,Base64Cr13Entity");

    // Sign the XML...
    success = gen.CreateXmlDSigSb(sbXml);
    if (success != true) {
        wprintf(L"%s\n",gen.lastErrorText());
        return;
    }

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

    // Save the signed XML to a file.
    success = sbXml.WriteFile(L"qa_output/signedXml.xml",L"utf-8",false);

    wprintf(L"%s\n",sbXml.getAsString());

    // ----------------------------------------
    // Verify the signatures we just produced...
    CkXmlDSigW verifier;
    success = verifier.LoadSignatureSb(sbXml);
    if (success != true) {
        wprintf(L"%s\n",verifier.lastErrorText());
        return;
    }

    int numSigs = verifier.get_NumSignatures();
    int verifyIdx = 0;
    while (verifyIdx < numSigs) {
        verifier.put_Selector(verifyIdx);
        bool verified = verifier.VerifySignature(true);
        if (verified != true) {
            wprintf(L"%s\n",verifier.lastErrorText());
            return;
        }

        verifyIdx = verifyIdx + 1;
    }

    wprintf(L"All signatures were successfully verified.\n");
    }

 

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