C
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 C Downloads
#include <C_CkXml.h>
#include <C_CkXmlDSigGen.h>
#include <C_CkCert.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
BOOL success;
HCkXml xmlToSign;
HCkXmlDSigGen gen;
HCkXml object1;
HCkCert cert;
HCkStringBuilder sbXml;
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...
xmlToSign = CkXml_Create();
CkXml_putTag(xmlToSign,"fe:Facturae");
CkXml_AddAttribute(xmlToSign,"xmlns:ds","http://www.w3.org/2000/09/xmldsig#");
CkXml_AddAttribute(xmlToSign,"xmlns:fe","http://www.facturae.es/Facturae/2009/v3.2/Facturae");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|SchemaVersion","3.2");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Modality","I");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|InvoiceIssuerType","EM");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Batch|BatchIdentifier","0000000000B2Emit-");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Batch|InvoicesCount","1");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Batch|TotalInvoicesAmount|TotalAmount","63.13");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Batch|TotalOutstandingAmount|TotalAmount","63.13");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Batch|TotalExecutableAmount|TotalAmount","63.13");
CkXml_UpdateChildContent(xmlToSign,"FileHeader|Batch|InvoiceCurrencyCode","EUR");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|TaxIdentification|PersonTypeCode","J");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|TaxIdentification|ResidenceTypeCode","R");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|TaxIdentification|TaxIdentificationNumber","A82735122");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|CorporateName","Company Comp SA");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|TradeName","Comp");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|Book","1");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|RegisterOfCompaniesLocation","12AP22");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|Sheet","3");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|Folio","15");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|Section","2");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|Volume","12");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|RegistrationData|AdditionalRegistrationData","Sin datos");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|AddressInSpain|Address","C/ Mayour 33 15 E");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|AddressInSpain|PostCode","28001");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|AddressInSpain|Town","Argamasilla de Alba");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|AddressInSpain|Province","Ciudad Real");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|AddressInSpain|CountryCode","ESP");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|Telephone","917776665");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|TeleFax","917776666");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|WebAddress","www.facturae.es");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|ElectronicMail","facturae@mityc.es");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|ContactPersons","Fernando");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|CnoCnae","28000");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|INETownCode","2134AAB");
CkXml_UpdateChildContent(xmlToSign,"Parties|SellerParty|LegalEntity|ContactDetails|AdditionalContactDetails","Otros datos");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|TaxIdentification|PersonTypeCode","F");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|TaxIdentification|ResidenceTypeCode","E");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|TaxIdentification|TaxIdentificationNumber","0000000000B");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreCode","1");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|RoleTypeCode","02");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|Name","Ruth");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|FirstSurname","Mauripo");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Address","Armenia 1922");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|PostCodeAndTown","00000 Buenos Aires");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Province","Capital Federal");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|CountryCode","ARG");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreDescription","Centro principal de recepcion");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|Name","Juana");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|FirstSurname","Mauripo");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|OverseasAddress|Address","Juncal 1315");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|OverseasAddress|PostCodeAndTown","00000 Buenos Aires");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|OverseasAddress|Province","Capital Federal");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|OverseasAddress|CountryCode","ARG");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|ContactDetails|Telephone","00547775554");
CkXml_UpdateChildContent(xmlToSign,"Parties|BuyerParty|Individual|ContactDetails|TeleFax","00547775555");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceHeader|InvoiceNumber","2");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceHeader|InvoiceSeriesCode","Emit-");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceHeader|InvoiceDocumentType","FC");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceHeader|InvoiceClass","OO");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|IssueDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|OperationDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PostCode","00000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PlaceOfIssueDescription","Regalos");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|StartDate","2010-03-09");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|EndDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|InvoiceCurrencyCode","EUR");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|TaxCurrencyCode","EUR");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceIssueData|LanguageName","es");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax|TaxTypeCode","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax|TaxRate","16.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax|TaxableBase|TotalAmount","26.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax|TaxAmount|TotalAmount","4.16");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurcharge","1.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount","0.26");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax[1]|TaxTypeCode","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax[1]|TaxRate","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesOutputs|Tax[1]|TaxableBase|TotalAmount","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesWithheld|Tax|TaxTypeCode","05");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesWithheld|Tax|TaxRate","4.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesWithheld|Tax|TaxableBase|TotalAmount","26.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|TaxesWithheld|Tax|TaxAmount|TotalAmount","1.04");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalGrossAmount","59.75");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalGeneralDiscounts","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalGeneralSurcharges","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalGrossAmountBeforeTaxes","59.75");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalTaxOutputs","4.42");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalTaxesWithheld","1.04");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|InvoiceTotal","63.13");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalOutstandingAmount","63.13");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|InvoiceTotals|TotalExecutableAmount","63.13");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|IssuerContractReference","A9938281");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|IssuerContractDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|IssuerTransactionReference","A9938282");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|IssuerTransactionDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|ReceiverContractReference","BBBH-38271");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|ReceiverContractDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionReference","BBBH-38272");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|FileReference","000298172");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|FileDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|SequenceNumber","1.0");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteNumber","132413842");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteNumber","987673211");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteDate","2010-03-09");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|ItemDescription","Flores");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|Quantity","1.0");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|UnitOfMeasure","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|UnitPriceWithoutTax","25.000000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|TotalCost","25.000000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountReason","Descuento");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountRate","5.0000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountAmount","1.250000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeReason","Cargo");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeAmount","10.000000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|GrossAmount","33.750000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxTypeCode","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxRate","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxableBase|TotalAmount","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxAmount|TotalAmount","0.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|AdditionalLineItemInformation","Contacto en Neuquen: Paulita");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventCode","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventReason","Concepto exento por el motivo aqu definido");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine|ArticleCode","142");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|IssuerContractDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|IssuerTransactionDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|ReceiverContractDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|ReceiverTransactionDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|FileDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|SequenceNumber","2.0");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|ItemDescription","Mate");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|Quantity","2.0");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|UnitOfMeasure","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|UnitPriceWithoutTax","13.000000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TotalCost","26.000000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|GrossAmount","26.000000");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxTypeCode","05");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxRate","4.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxableBase|TotalAmount","26.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxAmount|TotalAmount","1.04");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxTypeCode","01");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxRate","16.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxableBase|TotalAmount","26.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxAmount|TotalAmount","4.16");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurcharge","1.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount","0.26");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|Items|InvoiceLine[1]|ArticleCode","122");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|InstallmentDueDate","2010-03-10");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|InstallmentAmount","25.00");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|PaymentMeans","19");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|IBAN","4322 3432 22 1341234212");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BankCode","4322");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BranchCode","3432");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Address","Juncal 1423 8 Z");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|PostCodeAndTown","01115 Capital Federal");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Province","Buenos Aires");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|CountryCode","ARG");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|PaymentReconciliationReference","12223");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|IBAN","1234 4312 22 33212341212314");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BankCode","1234");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BranchCode","4312");
CkXml_UpdateChildContent(xmlToSign,"Invoices|Invoice|PaymentDetails|Installment|DebitReconciliationReference","12223");
gen = CkXmlDSigGen_Create();
success = TRUE;
CkXmlDSigGen_putSigLocation(gen,"fe:Facturae");
CkXmlDSigGen_putSigLocationMod(gen,0);
CkXmlDSigGen_putSigId(gen,"Signature869123");
CkXmlDSigGen_AddSignatureNamespace(gen,"etsi","http://uri.etsi.org/01903/v1.3.2#");
CkXmlDSigGen_putSigNamespacePrefix(gen,"ds");
CkXmlDSigGen_putSigNamespaceUri(gen,"http://www.w3.org/2000/09/xmldsig#");
CkXmlDSigGen_putSignedInfoId(gen,"Signature-SignedInfo241096");
CkXmlDSigGen_putSignedInfoCanonAlg(gen,"EXCL_C14N");
CkXmlDSigGen_putSignedInfoDigestMethod(gen,"sha256");
// Create an Object to be added to the Signature.
object1 = CkXml_Create();
CkXml_putTag(object1,"xades:QualifyingProperties");
CkXml_AddAttribute(object1,"xmlns:xades","http://uri.etsi.org/01903/v1.3.2#");
// The Id can be any unique string..
CkXml_AddAttribute(object1,"Id","QualifyingProperties-e01a8fee-1bee-4ff5-9570-3d57aa02f278");
CkXml_AddAttribute(object1,"Target","#Signature869123");
CkXml_UpdateAttrAt(object1,"xades:SignedProperties",TRUE,"Id","Signature869123-SignedProperties787205");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime","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
CkXml_UpdateAttrAt(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestMethod",TRUE,"Algorithm","http://www.w3.org/2000/09/xmldsig#sha1");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:IssuerSerialV2","TO BE GENERATED BY CHILKAT");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Identifier","http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Description","Polótica de Firma FacturaE v3.1");
CkXml_UpdateAttrAt(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestMethod",TRUE,"Algorithm","http://www.w3.org/2000/09/xmldsig#sha1");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestValue","Ohixl6upD6av8N7pEvDABhEL6hM=");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedSignatureProperties|xades:SignerRole|xades:ClaimedRoles|xades:ClaimedRole","emisor");
CkXml_UpdateAttrAt(object1,"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat",TRUE,"ObjectReference","#Reference-ID-670821");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description","Factura electrónica");
CkXml_UpdateChildContent(object1,"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType","text/xml");
CkXmlDSigGen_AddObject(gen,"Signature869123-Object629337",CkXml_getXml(object1),"","");
CkXmlDSigGen_AddObjectRef(gen,"Signature869123-SignedProperties787205","sha1","","","http://uri.etsi.org/01903#SignedProperties");
CkXmlDSigGen_SetRefIdAttr(gen,"Signature869123-SignedProperties787205","SignedPropertiesID459347");
CkXmlDSigGen_putKeyInfoId(gen,"Certificate1570061");
CkXmlDSigGen_AddSameDocRef(gen,"Certificate1570061","sha1","","","");
CkXmlDSigGen_AddSameDocRef(gen,"","sha1","","","");
CkXmlDSigGen_SetRefIdAttr(gen,"","Reference-ID-670821");
// Provide a certificate + private key. (PFX password is test123)
cert = CkCert_Create();
success = CkCert_LoadPfxFile(cert,"qa_data/pfx/cert_test123.pfx","test123");
if (success == FALSE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkXml_Dispose(xmlToSign);
CkXmlDSigGen_Dispose(gen);
CkXml_Dispose(object1);
CkCert_Dispose(cert);
return;
}
CkXmlDSigGen_SetX509Cert(gen,cert,TRUE);
CkXmlDSigGen_putKeyInfoType(gen,"X509Data+KeyValue");
CkXmlDSigGen_putX509Type(gen,"Certificate");
// Load XML to be signed...
sbXml = CkStringBuilder_Create();
CkXml_GetXmlSb(xmlToSign,sbXml);
CkXmlDSigGen_putBehaviors(gen,"CompactSignedXml");
// Sign the XML...
success = CkXmlDSigGen_CreateXmlDSigSb(gen,sbXml);
if (success == FALSE) {
printf("%s\n",CkXmlDSigGen_lastErrorText(gen));
CkXml_Dispose(xmlToSign);
CkXmlDSigGen_Dispose(gen);
CkXml_Dispose(object1);
CkCert_Dispose(cert);
CkStringBuilder_Dispose(sbXml);
return;
}
// Save the signed XMl to a file.
success = CkStringBuilder_WriteFile(sbXml,"qa_output/signedXml.xml","utf-8",FALSE);
printf("%s\n",CkStringBuilder_getAsString(sbXml));
CkXml_Dispose(xmlToSign);
CkXmlDSigGen_Dispose(gen);
CkXml_Dispose(object1);
CkCert_Dispose(cert);
CkStringBuilder_Dispose(sbXml);
}