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