Zig Requires Chilkat v9.5.0.92+
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// ---
// 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...
const xml_to_sign = try chilkat.Xml.init();
defer xml_to_sign.deinit();
xml_to_sign.setTag("fe:Facturae");
xml_to_sign.addAttribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#") catch {};
xml_to_sign.addAttribute("xmlns:fe", "http://www.facturae.es/Facturae/2009/v3.2/Facturae") catch {};
xml_to_sign.updateChildContent("FileHeader|SchemaVersion", "3.2");
xml_to_sign.updateChildContent("FileHeader|Modality", "I");
xml_to_sign.updateChildContent("FileHeader|InvoiceIssuerType", "EM");
xml_to_sign.updateChildContent("FileHeader|Batch|BatchIdentifier", "0000000000B2Emit-");
xml_to_sign.updateChildContent("FileHeader|Batch|InvoicesCount", "1");
xml_to_sign.updateChildContent("FileHeader|Batch|TotalInvoicesAmount|TotalAmount", "63.13");
xml_to_sign.updateChildContent("FileHeader|Batch|TotalOutstandingAmount|TotalAmount", "63.13");
xml_to_sign.updateChildContent("FileHeader|Batch|TotalExecutableAmount|TotalAmount", "63.13");
xml_to_sign.updateChildContent("FileHeader|Batch|InvoiceCurrencyCode", "EUR");
xml_to_sign.updateChildContent("Parties|SellerParty|TaxIdentification|PersonTypeCode", "J");
xml_to_sign.updateChildContent("Parties|SellerParty|TaxIdentification|ResidenceTypeCode", "R");
xml_to_sign.updateChildContent("Parties|SellerParty|TaxIdentification|TaxIdentificationNumber", "A82735122");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|CorporateName", "Company Comp SA");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|TradeName", "Comp");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Book", "1");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|RegisterOfCompaniesLocation", "12AP22");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Sheet", "3");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Folio", "15");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Section", "2");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Volume", "12");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|AdditionalRegistrationData", "Sin datos");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|Address", "C/ Mayour 33 15 E");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|PostCode", "28001");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|Town", "Argamasilla de Alba");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|Province", "Ciudad Real");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|CountryCode", "ESP");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|Telephone", "917776665");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|TeleFax", "917776666");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|WebAddress", "www.facturae.es");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|ElectronicMail", "facturae@mityc.es");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|ContactPersons", "Fernando");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|CnoCnae", "28000");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|INETownCode", "2134AAB");
xml_to_sign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|AdditionalContactDetails", "Otros datos");
xml_to_sign.updateChildContent("Parties|BuyerParty|TaxIdentification|PersonTypeCode", "F");
xml_to_sign.updateChildContent("Parties|BuyerParty|TaxIdentification|ResidenceTypeCode", "E");
xml_to_sign.updateChildContent("Parties|BuyerParty|TaxIdentification|TaxIdentificationNumber", "0000000000B");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreCode", "1");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|RoleTypeCode", "02");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|Name", "Ruth");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|FirstSurname", "Mauripo");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Address", "Armenia 1922");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|PostCodeAndTown", "00000 Buenos Aires");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Province", "Capital Federal");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|CountryCode", "ARG");
xml_to_sign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreDescription", "Centro principal de recepcion");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|Name", "Juana");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|FirstSurname", "Mauripo");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|Address", "Juncal 1315");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|PostCodeAndTown", "00000 Buenos Aires");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|Province", "Capital Federal");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|CountryCode", "ARG");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|ContactDetails|Telephone", "00547775554");
xml_to_sign.updateChildContent("Parties|BuyerParty|Individual|ContactDetails|TeleFax", "00547775555");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceNumber", "2");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceSeriesCode", "Emit-");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceDocumentType", "FC");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceClass", "OO");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|IssueDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|OperationDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PostCode", "00000");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PlaceOfIssueDescription", "Regalos");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|StartDate", "2010-03-09");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|EndDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|InvoiceCurrencyCode", "EUR");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|TaxCurrencyCode", "EUR");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceIssueData|LanguageName", "es");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxTypeCode", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxRate", "16.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxableBase|TotalAmount", "26.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxAmount|TotalAmount", "4.16");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurcharge", "1.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount", "0.26");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax[1]|TaxTypeCode", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax[1]|TaxRate", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax[1]|TaxableBase|TotalAmount", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxTypeCode", "05");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxRate", "4.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxableBase|TotalAmount", "26.00");
xml_to_sign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxAmount|TotalAmount", "1.04");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGrossAmount", "59.75");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGeneralDiscounts", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGeneralSurcharges", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGrossAmountBeforeTaxes", "59.75");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalTaxOutputs", "4.42");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalTaxesWithheld", "1.04");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|InvoiceTotal", "63.13");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalOutstandingAmount", "63.13");
xml_to_sign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalExecutableAmount", "63.13");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerContractReference", "A9938281");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerContractDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerTransactionReference", "A9938282");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerTransactionDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverContractReference", "BBBH-38271");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverContractDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionReference", "BBBH-38272");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|FileReference", "000298172");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|FileDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|SequenceNumber", "1.0");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteNumber", "132413842");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteNumber", "987673211");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteDate", "2010-03-09");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ItemDescription", "Flores");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|Quantity", "1.0");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|UnitOfMeasure", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|UnitPriceWithoutTax", "25.000000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TotalCost", "25.000000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountReason", "Descuento");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountRate", "5.0000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountAmount", "1.250000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeReason", "Cargo");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeAmount", "10.000000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|GrossAmount", "33.750000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxTypeCode", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxRate", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxableBase|TotalAmount", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxAmount|TotalAmount", "0.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|AdditionalLineItemInformation", "Contacto en Neuquen: Paulita");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventCode", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventReason", "Concepto exento por el motivo aqu definido");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ArticleCode", "142");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|IssuerContractDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|IssuerTransactionDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ReceiverContractDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ReceiverTransactionDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|FileDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|SequenceNumber", "2.0");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ItemDescription", "Mate");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|Quantity", "2.0");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|UnitOfMeasure", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|UnitPriceWithoutTax", "13.000000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TotalCost", "26.000000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|GrossAmount", "26.000000");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxTypeCode", "05");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxRate", "4.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxableBase|TotalAmount", "26.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxAmount|TotalAmount", "1.04");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxTypeCode", "01");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxRate", "16.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxableBase|TotalAmount", "26.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxAmount|TotalAmount", "4.16");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurcharge", "1.00");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount", "0.26");
xml_to_sign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ArticleCode", "122");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|InstallmentDueDate", "2010-03-10");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|InstallmentAmount", "25.00");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|PaymentMeans", "19");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|IBAN", "4322 3432 22 1341234212");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BankCode", "4322");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BranchCode", "3432");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Address", "Juncal 1423 8 Z");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|PostCodeAndTown", "01115 Capital Federal");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Province", "Buenos Aires");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|CountryCode", "ARG");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|PaymentReconciliationReference", "12223");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|IBAN", "1234 4312 22 33212341212314");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BankCode", "1234");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BranchCode", "4312");
xml_to_sign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|DebitReconciliationReference", "12223");
const gen = try chilkat.XmlDSigGen.init();
defer gen.deinit();
gen.setSigLocation("fe:Facturae");
gen.setSigLocationMod(0);
gen.setSigId("Signature869123");
gen.addSignatureNamespace("etsi", "http://uri.etsi.org/01903/v1.3.2#") catch {};
gen.setSigNamespacePrefix("ds");
gen.setSigNamespaceUri("http://www.w3.org/2000/09/xmldsig#");
gen.setSignedInfoId("Signature-SignedInfo241096");
gen.setSignedInfoCanonAlg("EXCL_C14N");
gen.setSignedInfoDigestMethod("sha256");
// Create an Object to be added to the Signature.
const object1 = try chilkat.Xml.init();
defer object1.deinit();
object1.setTag("xades:QualifyingProperties");
object1.addAttribute("xmlns:xades", "http://uri.etsi.org/01903/v1.3.2#") catch {};
// The Id can be any unique string..
object1.addAttribute("Id", "QualifyingProperties-e01a8fee-1bee-4ff5-9570-3d57aa02f278") catch {};
object1.addAttribute("Target", "#Signature869123") catch {};
object1.updateAttrAt("xades:SignedProperties", true, "Id", "Signature869123-SignedProperties787205") catch {};
object1.updateChildContent("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
object1.updateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestMethod", true, "Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1") catch {};
object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestValue", "TO BE GENERATED BY CHILKAT");
object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:IssuerSerialV2", "TO BE GENERATED BY CHILKAT");
object1.updateChildContent("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");
object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Description", "Polótica de Firma FacturaE v3.1");
object1.updateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestMethod", true, "Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1") catch {};
object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestValue", "Ohixl6upD6av8N7pEvDABhEL6hM=");
object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignerRole|xades:ClaimedRoles|xades:ClaimedRole", "emisor");
object1.updateAttrAt("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat", true, "ObjectReference", "#Reference-ID-670821") catch {};
object1.updateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description", "Factura electrónica");
object1.updateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType", "text/xml");
gen.addObject("Signature869123-Object629337", try object1.getXml(alloc), "", "") catch {};
gen.addObjectRef("Signature869123-SignedProperties787205", "sha1", "", "", "http://uri.etsi.org/01903#SignedProperties") catch {};
gen.setRefIdAttr("Signature869123-SignedProperties787205", "SignedPropertiesID459347") catch {};
gen.setKeyInfoId("Certificate1570061");
gen.addSameDocRef("Certificate1570061", "sha1", "", "", "") catch {};
gen.addSameDocRef("", "sha1", "", "", "") catch {};
gen.setRefIdAttr("", "Reference-ID-670821") catch {};
// Provide a certificate + private key. (PFX password is test123)
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.loadPfxFile("qa_data/pfx/cert_test123.pfx", "test123") catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
gen.setX509Cert(cert, true) catch {};
gen.setKeyInfoType("X509Data+KeyValue");
gen.setX509Type("Certificate");
// Load XML to be signed...
const sb_xml = try chilkat.StringBuilder.init();
defer sb_xml.deinit();
xml_to_sign.getXmlSb(sb_xml) catch {};
gen.setBehaviors("CompactSignedXml");
// Sign the XML...
gen.createXmlDSigSb(sb_xml) catch {
std.debug.print("{s}\n", .{try gen.getLastErrorText(alloc)});
return;
};
// Save the signed XMl to a file.
try sb_xml.writeFile("qa_output/signedXml.xml", "utf-8", false);
std.debug.print("{s}\n", .{try sb_xml.getAsString(alloc)});
}