Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift 3,4,5...) Create XAdES Facturae 3.2 Signed InvoiceSee more XAdES ExamplesDemonstrates how to create a factura electrónica XAdES digital signature for Gobierno de España Note: This example requires Chilkat v9.5.0.92 or greater. Problems specific to XML signatures for FacturaE in Spain were fixed in v9.5.0.92.
func chilkatTest() { // ---------------------------------------------------------------------- // IMPORTANT: This generated example requires Chilkat v9.5.0.75 or later. // Contact support@chilkatsoft.com for a pre-release. // ---------------------------------------------------------------------- // --- // The following source code can be generated from sample XML using the XML Signature Code Generator at chilkat.io // --- // IMPORTANT: This example requires Chilkat v9.5.0.92 or greater. Problems specific to XML signatures for FacturaE in Spain were fixed in v9.5.0.92. // Create the XML to be signed... let xmlToSign = CkoXml()! xmlToSign.tag = "fe:Facturae" xmlToSign.addAttribute("xmlns:ds", value: "http://www.w3.org/2000/09/xmldsig#") xmlToSign.addAttribute("xmlns:fe", value: "http://www.facturae.es/Facturae/2009/v3.2/Facturae") xmlToSign.updateChildContent("FileHeader|SchemaVersion", value: "3.2") xmlToSign.updateChildContent("FileHeader|Modality", value: "I") xmlToSign.updateChildContent("FileHeader|InvoiceIssuerType", value: "EM") xmlToSign.updateChildContent("FileHeader|Batch|BatchIdentifier", value: "0000000000B2Emit-") xmlToSign.updateChildContent("FileHeader|Batch|InvoicesCount", value: "1") xmlToSign.updateChildContent("FileHeader|Batch|TotalInvoicesAmount|TotalAmount", value: "63.13") xmlToSign.updateChildContent("FileHeader|Batch|TotalOutstandingAmount|TotalAmount", value: "63.13") xmlToSign.updateChildContent("FileHeader|Batch|TotalExecutableAmount|TotalAmount", value: "63.13") xmlToSign.updateChildContent("FileHeader|Batch|InvoiceCurrencyCode", value: "EUR") xmlToSign.updateChildContent("Parties|SellerParty|TaxIdentification|PersonTypeCode", value: "J") xmlToSign.updateChildContent("Parties|SellerParty|TaxIdentification|ResidenceTypeCode", value: "R") xmlToSign.updateChildContent("Parties|SellerParty|TaxIdentification|TaxIdentificationNumber", value: "A82735122") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|CorporateName", value: "Company Comp SA") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|TradeName", value: "Comp") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Book", value: "1") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|RegisterOfCompaniesLocation", value: "12AP22") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Sheet", value: "3") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Folio", value: "15") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Section", value: "2") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|Volume", value: "12") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|RegistrationData|AdditionalRegistrationData", value: "Sin datos") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|Address", value: "C/ Mayour 33 15 E") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|PostCode", value: "28001") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|Town", value: "Argamasilla de Alba") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|Province", value: "Ciudad Real") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|AddressInSpain|CountryCode", value: "ESP") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|Telephone", value: "917776665") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|TeleFax", value: "917776666") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|WebAddress", value: "www.facturae.es") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|ElectronicMail", value: "facturae@mityc.es") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|ContactPersons", value: "Fernando") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|CnoCnae", value: "28000") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|INETownCode", value: "2134AAB") xmlToSign.updateChildContent("Parties|SellerParty|LegalEntity|ContactDetails|AdditionalContactDetails", value: "Otros datos") xmlToSign.updateChildContent("Parties|BuyerParty|TaxIdentification|PersonTypeCode", value: "F") xmlToSign.updateChildContent("Parties|BuyerParty|TaxIdentification|ResidenceTypeCode", value: "E") xmlToSign.updateChildContent("Parties|BuyerParty|TaxIdentification|TaxIdentificationNumber", value: "0000000000B") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreCode", value: "1") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|RoleTypeCode", value: "02") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|Name", value: "Ruth") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|FirstSurname", value: "Mauripo") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Address", value: "Armenia 1922") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|PostCodeAndTown", value: "00000 Buenos Aires") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|Province", value: "Capital Federal") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|OverseasAddress|CountryCode", value: "ARG") xmlToSign.updateChildContent("Parties|BuyerParty|AdministrativeCentres|AdministrativeCentre|CentreDescription", value: "Centro principal de recepcion") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|Name", value: "Juana") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|FirstSurname", value: "Mauripo") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|Address", value: "Juncal 1315") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|PostCodeAndTown", value: "00000 Buenos Aires") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|Province", value: "Capital Federal") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|OverseasAddress|CountryCode", value: "ARG") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|ContactDetails|Telephone", value: "00547775554") xmlToSign.updateChildContent("Parties|BuyerParty|Individual|ContactDetails|TeleFax", value: "00547775555") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceNumber", value: "2") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceSeriesCode", value: "Emit-") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceDocumentType", value: "FC") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceHeader|InvoiceClass", value: "OO") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|IssueDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|OperationDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PostCode", value: "00000") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|PlaceOfIssue|PlaceOfIssueDescription", value: "Regalos") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|StartDate", value: "2010-03-09") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|InvoicingPeriod|EndDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|InvoiceCurrencyCode", value: "EUR") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|TaxCurrencyCode", value: "EUR") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceIssueData|LanguageName", value: "es") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxTypeCode", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxRate", value: "16.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxableBase|TotalAmount", value: "26.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|TaxAmount|TotalAmount", value: "4.16") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurcharge", value: "1.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount", value: "0.26") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax[1]|TaxTypeCode", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax[1]|TaxRate", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesOutputs|Tax[1]|TaxableBase|TotalAmount", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxTypeCode", value: "05") xmlToSign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxRate", value: "4.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxableBase|TotalAmount", value: "26.00") xmlToSign.updateChildContent("Invoices|Invoice|TaxesWithheld|Tax|TaxAmount|TotalAmount", value: "1.04") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGrossAmount", value: "59.75") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGeneralDiscounts", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGeneralSurcharges", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalGrossAmountBeforeTaxes", value: "59.75") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalTaxOutputs", value: "4.42") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalTaxesWithheld", value: "1.04") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|InvoiceTotal", value: "63.13") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalOutstandingAmount", value: "63.13") xmlToSign.updateChildContent("Invoices|Invoice|InvoiceTotals|TotalExecutableAmount", value: "63.13") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerContractReference", value: "A9938281") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerContractDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerTransactionReference", value: "A9938282") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|IssuerTransactionDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverContractReference", value: "BBBH-38271") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverContractDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionReference", value: "BBBH-38272") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ReceiverTransactionDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|FileReference", value: "000298172") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|FileDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|SequenceNumber", value: "1.0") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteNumber", value: "132413842") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote|DeliveryNoteDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteNumber", value: "987673211") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DeliveryNotesReferences|DeliveryNote[1]|DeliveryNoteDate", value: "2010-03-09") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ItemDescription", value: "Flores") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|Quantity", value: "1.0") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|UnitOfMeasure", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|UnitPriceWithoutTax", value: "25.000000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TotalCost", value: "25.000000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountReason", value: "Descuento") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountRate", value: "5.0000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|DiscountsAndRebates|Discount|DiscountAmount", value: "1.250000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeReason", value: "Cargo") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|Charges|Charge|ChargeAmount", value: "10.000000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|GrossAmount", value: "33.750000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxTypeCode", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxRate", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxableBase|TotalAmount", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|TaxesOutputs|Tax|TaxAmount|TotalAmount", value: "0.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|AdditionalLineItemInformation", value: "Contacto en Neuquen: Paulita") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventCode", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|SpecialTaxableEvent|SpecialTaxableEventReason", value: "Concepto exento por el motivo aqu definido") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine|ArticleCode", value: "142") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|IssuerContractDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|IssuerTransactionDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ReceiverContractDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ReceiverTransactionDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|FileDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|SequenceNumber", value: "2.0") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ItemDescription", value: "Mate") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|Quantity", value: "2.0") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|UnitOfMeasure", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|UnitPriceWithoutTax", value: "13.000000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TotalCost", value: "26.000000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|GrossAmount", value: "26.000000") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxTypeCode", value: "05") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxRate", value: "4.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxableBase|TotalAmount", value: "26.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesWithheld|Tax|TaxAmount|TotalAmount", value: "1.04") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxTypeCode", value: "01") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxRate", value: "16.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxableBase|TotalAmount", value: "26.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|TaxAmount|TotalAmount", value: "4.16") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurcharge", value: "1.00") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|TaxesOutputs|Tax|EquivalenceSurchargeAmount|TotalAmount", value: "0.26") xmlToSign.updateChildContent("Invoices|Invoice|Items|InvoiceLine[1]|ArticleCode", value: "122") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|InstallmentDueDate", value: "2010-03-10") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|InstallmentAmount", value: "25.00") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|PaymentMeans", value: "19") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|IBAN", value: "4322 3432 22 1341234212") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BankCode", value: "4322") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|BranchCode", value: "3432") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Address", value: "Juncal 1423 8 Z") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|PostCodeAndTown", value: "01115 Capital Federal") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|Province", value: "Buenos Aires") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeCredited|OverseasBranchAddress|CountryCode", value: "ARG") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|PaymentReconciliationReference", value: "12223") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|IBAN", value: "1234 4312 22 33212341212314") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BankCode", value: "1234") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|AccountToBeDebited|BranchCode", value: "4312") xmlToSign.updateChildContent("Invoices|Invoice|PaymentDetails|Installment|DebitReconciliationReference", value: "12223") let gen = CkoXmlDSigGen()! var success: Bool = true gen.sigLocation = "fe:Facturae" gen.sigLocationMod = 0 gen.sigId = "Signature869123" gen.addSignatureNamespace("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("xmlns:xades", value: "http://uri.etsi.org/01903/v1.3.2#") // The Id can be any unique string.. object1.addAttribute("Id", value: "QualifyingProperties-e01a8fee-1bee-4ff5-9570-3d57aa02f278") object1.addAttribute("Target", value: "#Signature869123") object1.updateAttr(at: "xades:SignedProperties", autoCreate: true, attrName: "Id", attrValue: "Signature869123-SignedProperties787205") object1.updateChildContent("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.updateAttr(at: "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod", autoCreate: true, attrName: "Algorithm", attrValue: "http://www.w3.org/2000/09/xmldsig#sha1") object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue", value: "TO BE GENERATED BY CHILKAT") object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName", value: "TO BE GENERATED BY CHILKAT") object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber", value: "TO BE GENERATED BY CHILKAT") object1.updateChildContent("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("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyId|xades:Description", value: "Poltica de Firma FacturaE v3.1") object1.updateAttr(at: "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("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignaturePolicyIdentifier|xades:SignaturePolicyId|xades:SigPolicyHash|ds:DigestValue", value: "Ohixl6upD6av8N7pEvDABhEL6hM=") object1.updateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SignerRole|xades:ClaimedRoles|xades:ClaimedRole", value: "emisor") object1.updateAttr(at: "xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat", autoCreate: true, attrName: "ObjectReference", attrValue: "#Reference-ID-670821") object1.updateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description", value: "Factura electrnica") object1.updateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType", value: "text/xml") gen.addObject("Signature869123-Object629337", content: object1.getXml(), mimeType: "", encoding: "") gen.addObjectRef("Signature869123-SignedProperties787205", digestMethod: "sha1", canonMethod: "", prefixList: "", refType: "http://uri.etsi.org/01903#SignedProperties") gen.setRefIdAttr("Signature869123-SignedProperties787205", value: "SignedPropertiesID459347") gen.keyInfoId = "Certificate1570061" gen.addSameDocRef("Certificate1570061", digestMethod: "sha1", canonMethod: "", prefixList: "", refType: "") gen.addSameDocRef("", digestMethod: "sha1", canonMethod: "", prefixList: "", refType: "") gen.setRefIdAttr("", value: "Reference-ID-670821") // Provide a certificate + private key. (PFX password is test123) let cert = CkoCert()! success = cert.loadPfxFile("qa_data/pfx/cert_test123.pfx", password: "test123") if success != true { print("\(cert.lastErrorText!)") return } gen.setX509Cert(cert, usePrivateKey: true) gen.keyInfoType = "X509Data+KeyValue" gen.x509Type = "Certificate" // Load XML to be signed... let sbXml = CkoStringBuilder()! xmlToSign.getSb(sbXml) gen.behaviors = "CompactSignedXml" // Sign the XML... success = gen.createXmlDSigSb(sbXml) if success != true { print("\(gen.lastErrorText!)") return } // Save the signed XMl to a file. success = sbXml.writeFile("qa_output/signedXml.xml", charset: "utf-8", emitBom: false) print("\(sbXml.getAsString()!)") } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.