Unicode C++
Unicode C++
Create XAdES Facturae 3.2 Signed Invoice
See more XAdES Examples
Demonstrates how to create a factura electrónica XAdES digital signature for Gobierno de EspañaChilkat Unicode C++ Downloads
#include <CkXmlW.h>
#include <CkXmlDSigGenW.h>
#include <CkCertW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// ---
// The following source code can be generated from sample XML using the XML Signature Code Generator at chilkat.io
// ---
// Create the XML to be signed...
CkXmlW xmlToSign;
xmlToSign.put_Tag(L"fe:Facturae");
xmlToSign.AddAttribute(L"xmlns:ds",L"http://www.w3.org/2000/09/xmldsig#");
xmlToSign.AddAttribute(L"xmlns:fe",L"http://www.facturae.es/Facturae/2009/v3.2/Facturae");
xmlToSign.UpdateChildContent(L"FileHeader|SchemaVersion",L"3.2");
xmlToSign.UpdateChildContent(L"FileHeader|Modality",L"I");
xmlToSign.UpdateChildContent(L"FileHeader|InvoiceIssuerType",L"EM");
xmlToSign.UpdateChildContent(L"FileHeader|Batch|BatchIdentifier",L"0000000000B2Emit-");
xmlToSign.UpdateChildContent(L"FileHeader|Batch|InvoicesCount",L"1");
xmlToSign.UpdateChildContent(L"FileHeader|Batch|TotalInvoicesAmount|TotalAmount",L"63.13");
xmlToSign.UpdateChildContent(L"FileHeader|Batch|TotalOutstandingAmount|TotalAmount",L"63.13");
xmlToSign.UpdateChildContent(L"FileHeader|Batch|TotalExecutableAmount|TotalAmount",L"63.13");
xmlToSign.UpdateChildContent(L"FileHeader|Batch|InvoiceCurrencyCode",L"EUR");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|TaxIdentification|PersonTypeCode",L"J");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|TaxIdentification|ResidenceTypeCode",L"R");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|TaxIdentification|TaxIdentificationNumber",L"A82735122");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|CorporateName",L"Company Comp SA");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|TradeName",L"Comp");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|Book",L"1");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|RegisterOfCompaniesLocation",L"12AP22");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|Sheet",L"3");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|Folio",L"15");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|Section",L"2");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|Volume",L"12");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|RegistrationData|AdditionalRegistrationData",L"Sin datos");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|AddressInSpain|Address",L"C/ Mayour 33 15 E");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|AddressInSpain|PostCode",L"28001");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|AddressInSpain|Town",L"Argamasilla de Alba");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|AddressInSpain|Province",L"Ciudad Real");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|AddressInSpain|CountryCode",L"ESP");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|Telephone",L"917776665");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|TeleFax",L"917776666");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|WebAddress",L"www.facturae.es");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|ElectronicMail",L"facturae@mityc.es");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|ContactPersons",L"Fernando");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|CnoCnae",L"28000");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|INETownCode",L"2134AAB");
xmlToSign.UpdateChildContent(L"Parties|SellerParty|LegalEntity|ContactDetails|AdditionalContactDetails",L"Otros datos");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|TaxIdentification|PersonTypeCode",L"F");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|TaxIdentification|ResidenceTypeCode",L"E");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|TaxIdentification|TaxIdentificationNumber",L"0000000000B");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreCode",L"1");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|RoleTypeCode",L"02");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|Name",L"Ruth");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|FirstSurname",L"Mauripo");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Address",L"Armenia 1922");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|PostCodeAndTown",L"00000 Buenos Aires");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Province",L"Capital Federal");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|CountryCode",L"ARG");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreDescription",L"Centro principal de recepcion");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|Name",L"Juana");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|FirstSurname",L"Mauripo");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|OverseasAddress|Address",L"Juncal 1315");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|OverseasAddress|PostCodeAndTown",L"00000 Buenos Aires");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|OverseasAddress|Province",L"Capital Federal");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|OverseasAddress|CountryCode",L"ARG");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|ContactDetails|Telephone",L"00547775554");
xmlToSign.UpdateChildContent(L"Parties|BuyerParty|Individual|ContactDetails|TeleFax",L"00547775555");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceHeader|InvoiceNumber",L"2");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceHeader|InvoiceSeriesCode",L"Emit-");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceHeader|InvoiceDocumentType",L"FC");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceHeader|InvoiceClass",L"OO");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|IssueDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|OperationDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PostCode",L"00000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PlaceOfIssueDescription",L"Regalos");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|StartDate",L"2010-03-09");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|EndDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|InvoiceCurrencyCode",L"EUR");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|TaxCurrencyCode",L"EUR");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceIssueData|LanguageName",L"es");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax|TaxTypeCode",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax|TaxRate",L"16.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax|TaxableBase|TotalAmount",L"26.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax|TaxAmount|TotalAmount",L"4.16");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurcharge",L"1.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount",L"0.26");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax[1]|TaxTypeCode",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax[1]|TaxRate",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesOutputs|Tax[1]|TaxableBase|TotalAmount",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesWithheld|Tax|TaxTypeCode",L"05");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesWithheld|Tax|TaxRate",L"4.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesWithheld|Tax|TaxableBase|TotalAmount",L"26.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|TaxesWithheld|Tax|TaxAmount|TotalAmount",L"1.04");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalGrossAmount",L"59.75");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalGeneralDiscounts",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalGeneralSurcharges",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalGrossAmountBeforeTaxes",L"59.75");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalTaxOutputs",L"4.42");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalTaxesWithheld",L"1.04");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|InvoiceTotal",L"63.13");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalOutstandingAmount",L"63.13");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|InvoiceTotals|TotalExecutableAmount",L"63.13");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|IssuerContractReference",L"A9938281");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|IssuerContractDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|IssuerTransactionReference",L"A9938282");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|IssuerTransactionDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|ReceiverContractReference",L"BBBH-38271");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|ReceiverContractDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionReference",L"BBBH-38272");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|FileReference",L"000298172");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|FileDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|SequenceNumber",L"1.0");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteNumber",L"132413842");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteNumber",L"987673211");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteDate",L"2010-03-09");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|ItemDescription",L"Flores");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|Quantity",L"1.0");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|UnitOfMeasure",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|UnitPriceWithoutTax",L"25.000000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|TotalCost",L"25.000000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountReason",L"Descuento");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountRate",L"5.0000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountAmount",L"1.250000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeReason",L"Cargo");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeAmount",L"10.000000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|GrossAmount",L"33.750000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxTypeCode",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxRate",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxableBase|TotalAmount",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxAmount|TotalAmount",L"0.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|AdditionalLineItemInformation",L"Contacto en Neuquen: Paulita");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventCode",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventReason",L"Concepto exento por el motivo aqu definido");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine|ArticleCode",L"142");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|IssuerContractDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|IssuerTransactionDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|ReceiverContractDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|ReceiverTransactionDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|FileDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|SequenceNumber",L"2.0");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|ItemDescription",L"Mate");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|Quantity",L"2.0");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|UnitOfMeasure",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|UnitPriceWithoutTax",L"13.000000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TotalCost",L"26.000000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|GrossAmount",L"26.000000");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxTypeCode",L"05");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxRate",L"4.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxableBase|TotalAmount",L"26.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxAmount|TotalAmount",L"1.04");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxTypeCode",L"01");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxRate",L"16.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxableBase|TotalAmount",L"26.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxAmount|TotalAmount",L"4.16");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurcharge",L"1.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount",L"0.26");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|Items|InvoiceLine[1]|ArticleCode",L"122");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|InstallmentDueDate",L"2010-03-10");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|InstallmentAmount",L"25.00");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|PaymentMeans",L"19");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|IBAN",L"4322 3432 22 1341234212");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BankCode",L"4322");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BranchCode",L"3432");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Address",L"Juncal 1423 8 Z");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|PostCodeAndTown",L"01115 Capital Federal");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Province",L"Buenos Aires");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|CountryCode",L"ARG");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|PaymentReconciliationReference",L"12223");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|IBAN",L"1234 4312 22 33212341212314");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BankCode",L"1234");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BranchCode",L"4312");
xmlToSign.UpdateChildContent(L"Invoices|Invoice|PaymentDetails|Installment|DebitReconciliationReference",L"12223");
CkXmlDSigGenW gen;
success = true;
gen.put_SigLocation(L"fe:Facturae");
gen.put_SigLocationMod(0);
gen.put_SigId(L"Signature869123");
gen.AddSignatureNamespace(L"etsi",L"http://uri.etsi.org/01903/v1.3.2#");
gen.put_SigNamespacePrefix(L"ds");
gen.put_SigNamespaceUri(L"http://www.w3.org/2000/09/xmldsig#");
gen.put_SignedInfoId(L"Signature-SignedInfo241096");
gen.put_SignedInfoCanonAlg(L"EXCL_C14N");
gen.put_SignedInfoDigestMethod(L"sha256");
// 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#");
// The Id can be any unique string..
object1.AddAttribute(L"Id",L"QualifyingProperties-e01a8fee-1bee-4ff5-9570-3d57aa02f278");
object1.AddAttribute(L"Target",L"#Signature869123");
object1.UpdateAttrAt(L"xades:SignedProperties",true,L"Id",L"Signature869123-SignedProperties787205");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime",L"TO BE GENERATED BY CHILKAT");
// Note: It may be that http://www.w3.org/2001/04/xmlenc#sha256 is needed in the following line instead of http://www.w3.org/2000/09/xmldsig#sha1
object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestMethod",true,L"Algorithm",L"http://www.w3.org/2000/09/xmldsig#sha1");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestValue",L"TO BE GENERATED BY CHILKAT");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:IssuerSerialV2",L"TO BE GENERATED BY CHILKAT");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Identifier",L"http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Description",L"Polótica de Firma FacturaE v3.1");
object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestMethod",true,L"Algorithm",L"http://www.w3.org/2000/09/xmldsig#sha1");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestValue",L"Ohixl6upD6av8N7pEvDABhEL6hM=");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignerRole|xades:ClaimedRoles|xades:ClaimedRole",L"emisor");
object1.UpdateAttrAt(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat",true,L"ObjectReference",L"#Reference-ID-670821");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description",L"Factura electrónica");
object1.UpdateChildContent(L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType",L"text/xml");
gen.AddObject(L"Signature869123-Object629337",object1.getXml(),L"",L"");
gen.AddObjectRef(L"Signature869123-SignedProperties787205",L"sha1",L"",L"",L"http://uri.etsi.org/01903#SignedProperties");
gen.SetRefIdAttr(L"Signature869123-SignedProperties787205",L"SignedPropertiesID459347");
gen.put_KeyInfoId(L"Certificate1570061");
gen.AddSameDocRef(L"Certificate1570061",L"sha1",L"",L"",L"");
gen.AddSameDocRef(L"",L"sha1",L"",L"",L"");
gen.SetRefIdAttr(L"",L"Reference-ID-670821");
// 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 == false) {
wprintf(L"%s\n",cert.lastErrorText());
return;
}
gen.SetX509Cert(cert,true);
gen.put_KeyInfoType(L"X509Data+KeyValue");
gen.put_X509Type(L"Certificate");
// Load XML to be signed...
CkStringBuilderW sbXml;
xmlToSign.GetXmlSb(sbXml);
gen.put_Behaviors(L"CompactSignedXml");
// Sign the XML...
success = gen.CreateXmlDSigSb(sbXml);
if (success == false) {
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());
}