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
(Delphi DLL) Cape Verde Fatura Eletrónica XML Digital SignatureSee more XML Digital Signatures ExamplesDemonstrates how to sign XML to create a signed invoice compatible with the Cape Verde Fatura Eletrónica requirements. Note: This example requires Chilkat v9.5.0.89 or greater for a small feature to provide the ability produce mult-line base64 signature ending with
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, StringBuilder, XmlDSigGen, Xml, XmlDSig, Cert; ... procedure TForm1.Button1Click(Sender: TObject); var success: Boolean; xmlToSign: HCkXml; gen: HCkXmlDSigGen; object1: HCkXml; cert: HCkCert; sbXml: HCkStringBuilder; verifier: HCkXmlDSig; numSigs: Integer; verifyIdx: Integer; verified: Boolean; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First create the following XML to be signed. This can be created programmatically as shown in the code below, or // you can simply load the XML to be signed from a file.. // <?xml version="1.0" encoding="utf-8"?> // <Dfe xmlns="urn:cv:efatura:xsd:v1.0" DocumentTypeCode="1" Id="CV2210818123456789000010100000000546735014601" Version="1.0"> // <Invoice> // <LedCode>1</LedCode> // <Serie>SL</Serie> // <DocumentNumber>5</DocumentNumber> // <IssueDate>2021-08-30</IssueDate> // <IssueTime>00:01:00</IssueTime> // <TaxPointDate>2021-08-18</TaxPointDate> // <EmitterParty> // <TaxId CountryCode="CV">123456789</TaxId> // <Name>Maria</Name> // <Address CountryCode="CV"> // <State>Estado do Emissor</State> // <City>Cidade do Emissor</City> // <Region>Regio do Emissor</Region> // <Street>Rua do Emissor</Street> // <StreetDetail>Detalhe da rua do Emissor</StreetDetail> // <BuildingName>Prdio do Emissor</BuildingName> // <BuildingNumber>1</BuildingNumber> // <BuildingFloor>2</BuildingFloor> // <PostalCode>7600</PostalCode> // <AddressDetail>Detalhe de endereo do Emissor</AddressDetail> // <AddressCode>CV774999999999999319</AddressCode> // </Address> // <Contacts> // <Telephone>1234567</Telephone> // <Mobilephone>1234568</Mobilephone> // <Telefax>1234569</Telefax> // <Email>somebody@example.com</Email> // <Website>emissor.efatura.cv</Website> // </Contacts> // </EmitterParty> // <ReceiverParty> // <TaxId CountryCode="CV">123456789</TaxId> // <Name>Nome do Recetor</Name> // <Address CountryCode="CV"> // <State>Estado do Recetor</State> // <City>Cidade do Recetor</City> // <Region>Regio do Recetor</Region> // <Street>Rua do Recetor</Street> // <StreetDetail>Detalhe da rua do Recetor</StreetDetail> // <BuildingName>Prdio do Recetor</BuildingName> // <BuildingNumber>2</BuildingNumber> // <BuildingFloor>3</BuildingFloor> // <PostalCode>7601</PostalCode> // <AddressDetail>Detalhe de endereo do Recetor</AddressDetail> // <AddressCode>CV774999999999999319</AddressCode> // </Address> // <Contacts> // <Telephone>2234567</Telephone> // <Mobilephone>2234568</Mobilephone> // <Telefax>2234569</Telefax> // <Email>rector@efatura.cv</Email> // <Website>rector.efatura.cv</Website> // </Contacts> // </ReceiverParty> // <Lines> // <Line LineTypeCode="N"> // <Id>01</Id> // <OrderLineReference>1</OrderLineReference> // <Quantity UnitCode="EA">3.15</Quantity> // <Price>123456</Price> // <PriceExtension>388886</PriceExtension> // <Discount>15</Discount> // <NetTotal>252776</NetTotal> // <Tax TaxTypeCode="IVA"> // <TaxPercentage>15</TaxPercentage> // </Tax> // <Item> // <Description>Telemvel</Description> // <Name>Telemvel</Name> // <BrandName>Apple</BrandName> // <ModelName>iPhone X</ModelName> // <EmitterIdentification>TLMV</EmitterIdentification> // <StandardIdentification> // <GTIN>12345</GTIN> // </StandardIdentification> // <HazardousRiskIndicator>false</HazardousRiskIndicator> // </Item> // </Line> // </Lines> // <Totals> // <PriceExtensionTotalAmount>388886</PriceExtensionTotalAmount> // <ChargeTotalAmount>0</ChargeTotalAmount> // <DiscountTotalAmount>136110</DiscountTotalAmount> // <NetTotalAmount>252776</NetTotalAmount> // <Discount ValueType="P">20</Discount> // <TaxTotalAmount>37916</TaxTotalAmount> // <PayableAmount>290692</PayableAmount> // </Totals> // <References> // <Reference> // <FiscalDocument IsOldDocument="false">CV1200520123456789000112345678901112345678901</FiscalDocument> // <PaymentAmount>12345</PaymentAmount> // <Tax TaxTypeCode="IR"> // <TaxPercentage>10</TaxPercentage> // </Tax> // </Reference> // <Reference> // <FiscalDocument IsOldDocument="false">CV1200520123456789000112345678901112345678903</FiscalDocument> // <PaymentAmount>98765</PaymentAmount> // <Tax TaxTypeCode="IVA"> // <TaxPercentage>15</TaxPercentage> // </Tax> // </Reference> // </References> // <Payments> // <PaymentDueDate>2021-12-31</PaymentDueDate> // <PaymentTerms> // <Note>Juros de 12% a partir da data de vencimento</Note> // </PaymentTerms> // <PayeeFinancialAccount> // <NIB>123456789012345678901</NIB> // <Name>Nome da Conta 1</Name> // </PayeeFinancialAccount> // <PayeeFinancialAccount> // <NIB>123456789012345678902</NIB> // <Name>Nome da Conta 2</Name> // </PayeeFinancialAccount> // </Payments> // <Note>Texto livre</Note> // </Invoice> // <Transmission> // <IssueMode>2</IssueMode> // <TransmitterTaxId CountryCode="CV">123456789</TransmitterTaxId> // <Software> // <Code>EMIPUB</Code> // <Name>DNRE Emissor Pblico</Name> // <Version>Build #53 12-07-2021 14:00:47 CVT - master</Version> // </Software> // <Contingency> // <LedCode>1</LedCode> // <IssueDate>2020-01-01</IssueDate> // <IssueTime>01:02:03</IssueTime> // <ReasonTypeCode>1</ReasonTypeCode> // </Contingency> // </Transmission> // <RepositoryCode>2</RepositoryCode> // </Dfe> success := True; // Create the XML to be signed... // Use this online tool to generate code from sample XML: // Generate Code to Create XML xmlToSign := CkXml_Create(); CkXml_putTag(xmlToSign,'Dfe'); CkXml_AddAttribute(xmlToSign,'xmlns','urn:cv:efatura:xsd:v1.0'); CkXml_AddAttribute(xmlToSign,'DocumentTypeCode','1'); CkXml_AddAttribute(xmlToSign,'Id','CV2210818123456789000010100000000546735014601'); CkXml_AddAttribute(xmlToSign,'Version','1.0'); CkXml_UpdateChildContent(xmlToSign,'Invoice|LedCode','1'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Serie','SL'); CkXml_UpdateChildContent(xmlToSign,'Invoice|DocumentNumber','5'); CkXml_UpdateChildContent(xmlToSign,'Invoice|IssueDate','2021-08-30'); CkXml_UpdateChildContent(xmlToSign,'Invoice|IssueTime','00:01:00'); CkXml_UpdateChildContent(xmlToSign,'Invoice|TaxPointDate','2021-08-18'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|EmitterParty|TaxId',True,'CountryCode','CV'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|TaxId','123456789'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Name','Maria'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|EmitterParty|Address',True,'CountryCode','CV'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|State','Estado do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|City','Cidade do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|Region','Regio do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|Street','Rua do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|StreetDetail','Detalhe da rua do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|BuildingName','Prdio do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|BuildingNumber','1'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|BuildingFloor','2'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|PostalCode','7600'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|AddressDetail','Detalhe de endereo do Emissor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Address|AddressCode','CV774999999999999319'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Contacts|Telephone','1234567'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Contacts|Mobilephone','1234568'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Contacts|Telefax','1234569'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Contacts|Email','somebody@example.com'); CkXml_UpdateChildContent(xmlToSign,'Invoice|EmitterParty|Contacts|Website','emissor.efatura.cv'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|ReceiverParty|TaxId',True,'CountryCode','CV'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|TaxId','123456789'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Name','Nome do Recetor'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|ReceiverParty|Address',True,'CountryCode','CV'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|State','Estado do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|City','Cidade do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|Region','Regio do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|Street','Rua do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|StreetDetail','Detalhe da rua do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|BuildingName','Prdio do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|BuildingNumber','2'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|BuildingFloor','3'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|PostalCode','7601'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|AddressDetail','Detalhe de endereo do Recetor'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Address|AddressCode','CV774999999999999319'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Contacts|Telephone','2234567'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Contacts|Mobilephone','2234568'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Contacts|Telefax','2234569'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Contacts|Email','rector@efatura.cv'); CkXml_UpdateChildContent(xmlToSign,'Invoice|ReceiverParty|Contacts|Website','rector.efatura.cv'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|Lines|Line',True,'LineTypeCode','N'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Id','01'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|OrderLineReference','1'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|Lines|Line|Quantity',True,'UnitCode','EA'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Quantity','3.15'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Price','123456'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|PriceExtension','388886'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Discount','15'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|NetTotal','252776'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|Lines|Line|Tax',True,'TaxTypeCode','IVA'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Tax|TaxPercentage','15'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|Description','Telemvel'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|Name','Telemvel'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|BrandName','Apple'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|ModelName','iPhone X'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|EmitterIdentification','TLMV'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|StandardIdentification|GTIN','12345'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Lines|Line|Item|HazardousRiskIndicator','false'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|PriceExtensionTotalAmount','388886'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|ChargeTotalAmount','0'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|DiscountTotalAmount','136110'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|NetTotalAmount','252776'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|Totals|Discount',True,'ValueType','P'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|Discount','20'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|TaxTotalAmount','37916'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Totals|PayableAmount','290692'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|References|Reference|FiscalDocument',True,'IsOldDocument','false'); CkXml_UpdateChildContent(xmlToSign,'Invoice|References|Reference|FiscalDocument','CV1200520123456789000112345678901112345678901'); CkXml_UpdateChildContent(xmlToSign,'Invoice|References|Reference|PaymentAmount','12345'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|References|Reference|Tax',True,'TaxTypeCode','IR'); CkXml_UpdateChildContent(xmlToSign,'Invoice|References|Reference|Tax|TaxPercentage','10'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|References|Reference[1]|FiscalDocument',True,'IsOldDocument','false'); CkXml_UpdateChildContent(xmlToSign,'Invoice|References|Reference[1]|FiscalDocument','CV1200520123456789000112345678901112345678903'); CkXml_UpdateChildContent(xmlToSign,'Invoice|References|Reference[1]|PaymentAmount','98765'); CkXml_UpdateAttrAt(xmlToSign,'Invoice|References|Reference[1]|Tax',True,'TaxTypeCode','IVA'); CkXml_UpdateChildContent(xmlToSign,'Invoice|References|Reference[1]|Tax|TaxPercentage','15'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Payments|PaymentDueDate','2021-12-31'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Payments|PaymentTerms|Note','Juros de 12% a partir da data de vencimento'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Payments|PayeeFinancialAccount|NIB','123456789012345678901'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Payments|PayeeFinancialAccount|Name','Nome da Conta 1'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Payments|PayeeFinancialAccount[1]|NIB','123456789012345678902'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Payments|PayeeFinancialAccount[1]|Name','Nome da Conta 2'); CkXml_UpdateChildContent(xmlToSign,'Invoice|Note','Texto livre'); CkXml_UpdateChildContent(xmlToSign,'Transmission|IssueMode','2'); CkXml_UpdateAttrAt(xmlToSign,'Transmission|TransmitterTaxId',True,'CountryCode','CV'); CkXml_UpdateChildContent(xmlToSign,'Transmission|TransmitterTaxId','123456789'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Software|Code','EMIPUB'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Software|Name','DNRE Emissor Pblico'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Software|Version','Build #53 12-07-2021 14:00:47 CVT - master'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Contingency|LedCode','1'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Contingency|IssueDate','2020-01-01'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Contingency|IssueTime','01:02:03'); CkXml_UpdateChildContent(xmlToSign,'Transmission|Contingency|ReasonTypeCode','1'); CkXml_UpdateChildContent(xmlToSign,'RepositoryCode','2'); gen := CkXmlDSigGen_Create(); CkXmlDSigGen_putSigLocation(gen,'Dfe'); CkXmlDSigGen_putSigLocationMod(gen,0); CkXmlDSigGen_putSigId(gen,'xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac'); CkXmlDSigGen_putSigNamespacePrefix(gen,'ds'); CkXmlDSigGen_putSigNamespaceUri(gen,'http://www.w3.org/2000/09/xmldsig#'); CkXmlDSigGen_putSigValueId(gen,'xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-sigvalue'); CkXmlDSigGen_putSignedInfoCanonAlg(gen,'C14N'); CkXmlDSigGen_putSignedInfoDigestMethod(gen,'sha256'); // Set the KeyInfoId before adding references.. CkXmlDSigGen_putKeyInfoId(gen,'xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo'); // 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#'); CkXml_AddAttribute(object1,'xmlns:xades141','http://uri.etsi.org/01903/v1.4.1#'); CkXml_AddAttribute(object1,'Target','#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac'); CkXml_UpdateAttrAt(object1,'xades:SignedProperties',True,'Id','xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime','TO BE GENERATED BY CHILKAT'); CkXml_UpdateAttrAt(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod',True,'Algorithm','http://www.w3.org/2001/04/xmlenc#sha256'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue','TO BE GENERATED BY CHILKAT'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName','TO BE GENERATED BY CHILKAT'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber','TO BE GENERATED BY CHILKAT'); CkXml_UpdateAttrAt(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:CertDigest|ds:DigestMethod',True,'Algorithm','http://www.w3.org/2001/04/xmlenc#sha256'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:CertDigest|ds:DigestValue','TO BE GENERATED BY CHILKAT'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:IssuerSerial|ds:X509IssuerName','TO BE GENERATED BY CHILKAT'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[1]|xades:IssuerSerial|ds:X509SerialNumber','TO BE GENERATED BY CHILKAT'); CkXml_UpdateAttrAt(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:CertDigest|ds:DigestMethod',True,'Algorithm','http://www.w3.org/2001/04/xmlenc#sha256'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:CertDigest|ds:DigestValue','TO BE GENERATED BY CHILKAT'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:IssuerSerial|ds:X509IssuerName','TO BE GENERATED BY CHILKAT'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert[2]|xades:IssuerSerial|ds:X509SerialNumber','TO BE GENERATED BY CHILKAT'); CkXml_UpdateAttrAt(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat',True,'ObjectReference','#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description','DFE Signature'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier','efatura-uri'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:DocumentationReferences|xades:DocumentationReference','https://efatura.cv'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType','text/xml'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding','UTF-8'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Identifier','http://uri.etsi.org/01903/v1.2.2#ProofOfApproval'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Description','Indicates that the signer has approved the content of the signed data object'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:AllSignedDataObjects',''); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Identifier','http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Description','Indicates that the signer recognizes to have created, approved and sent the signed data object'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:ObjectReference','#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0'); CkXml_UpdateChildContent(object1,'xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeQualifiers|xades:CommitmentTypeQualifier','CV-FE-123456789'); CkXmlDSigGen_AddObject(gen,'',CkXml__getXml(object1),'',''); // -------- Reference 1 -------- CkXmlDSigGen_AddSameDocRef(gen,'CV2210818123456789000010100000000546735014601','sha256','','',''); CkXmlDSigGen_SetRefIdAttr(gen,'CV2210818123456789000010100000000546735014601','xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0'); // -------- Reference 2 -------- CkXmlDSigGen_AddSameDocRef(gen,'xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo','sha256','C14N','',''); // -------- Reference 3 -------- CkXmlDSigGen_AddObjectRef(gen,'xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops','sha256','C14N','','http://uri.etsi.org/01903#SignedProperties'); // 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 <> True) then begin Memo1.Lines.Add(CkCert__lastErrorText(cert)); Exit; end; CkXmlDSigGen_SetX509Cert(gen,cert,True); CkXmlDSigGen_putKeyInfoType(gen,'X509Data'); CkXmlDSigGen_putX509Type(gen,'IssuerSerial,SubjectName,Certificate'); // Load XML to be signed... sbXml := CkStringBuilder_Create(); CkXml_GetXmlSb(xmlToSign,sbXml); // Note: The last keyword (Base64Cr13Entity) requires Chilkat v9.5.0.89 or later. CkXmlDSigGen_putBehaviors(gen,'IndentedSignature,Base64Cr13Entity,ForceAddEnvelopedSignatureTransform,Base64Cr13Entity'); // Sign the XML... success := CkXmlDSigGen_CreateXmlDSigSb(gen,sbXml); if (success <> True) then begin Memo1.Lines.Add(CkXmlDSigGen__lastErrorText(gen)); Exit; end; // ----------------------------------------------- // Save the signed XML to a file. success := CkStringBuilder_WriteFile(sbXml,'qa_output/signedXml.xml','utf-8',False); Memo1.Lines.Add(CkStringBuilder__getAsString(sbXml)); // ---------------------------------------- // Verify the signatures we just produced... verifier := CkXmlDSig_Create(); success := CkXmlDSig_LoadSignatureSb(verifier,sbXml); if (success <> True) then begin Memo1.Lines.Add(CkXmlDSig__lastErrorText(verifier)); Exit; end; numSigs := CkXmlDSig_getNumSignatures(verifier); verifyIdx := 0; while verifyIdx < numSigs do begin CkXmlDSig_putSelector(verifier,verifyIdx); verified := CkXmlDSig_VerifySignature(verifier,True); if (verified <> True) then begin Memo1.Lines.Add(CkXmlDSig__lastErrorText(verifier)); Exit; end; verifyIdx := verifyIdx + 1; end; Memo1.Lines.Add('All signatures were successfully verified.'); CkXml_Dispose(xmlToSign); CkXmlDSigGen_Dispose(gen); CkXml_Dispose(object1); CkCert_Dispose(cert); CkStringBuilder_Dispose(sbXml); CkXmlDSig_Dispose(verifier); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.