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
(Unicode C) 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
#include <C_CkXmlW.h> #include <C_CkXmlDSigGenW.h> #include <C_CkCertW.h> #include <C_CkStringBuilderW.h> #include <C_CkXmlDSigW.h> void ChilkatSample(void) { BOOL success; HCkXmlW xmlToSign; HCkXmlDSigGenW gen; HCkXmlW object1; HCkCertW cert; HCkStringBuilderW sbXml; HCkXmlDSigW verifier; int numSigs; int verifyIdx; BOOL verified; // 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>Regi�o do Emissor</Region> // <Street>Rua do Emissor</Street> // <StreetDetail>Detalhe da rua do Emissor</StreetDetail> // <BuildingName>Pr�dio do Emissor</BuildingName> // <BuildingNumber>1</BuildingNumber> // <BuildingFloor>2</BuildingFloor> // <PostalCode>7600</PostalCode> // <AddressDetail>Detalhe de endere�o 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>Regi�o do Recetor</Region> // <Street>Rua do Recetor</Street> // <StreetDetail>Detalhe da rua do Recetor</StreetDetail> // <BuildingName>Pr�dio do Recetor</BuildingName> // <BuildingNumber>2</BuildingNumber> // <BuildingFloor>3</BuildingFloor> // <PostalCode>7601</PostalCode> // <AddressDetail>Detalhe de endere�o 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>Telem�vel</Description> // <Name>Telem�vel</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 P�blico</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 = CkXmlW_Create(); CkXmlW_putTag(xmlToSign,L"Dfe"); CkXmlW_AddAttribute(xmlToSign,L"xmlns",L"urn:cv:efatura:xsd:v1.0"); CkXmlW_AddAttribute(xmlToSign,L"DocumentTypeCode",L"1"); CkXmlW_AddAttribute(xmlToSign,L"Id",L"CV2210818123456789000010100000000546735014601"); CkXmlW_AddAttribute(xmlToSign,L"Version",L"1.0"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|LedCode",L"1"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Serie",L"SL"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|DocumentNumber",L"5"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|IssueDate",L"2021-08-30"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|IssueTime",L"00:01:00"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|TaxPointDate",L"2021-08-18"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|EmitterParty|TaxId",TRUE,L"CountryCode",L"CV"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|TaxId",L"123456789"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Name",L"Maria"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|EmitterParty|Address",TRUE,L"CountryCode",L"CV"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|State",L"Estado do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|City",L"Cidade do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|Region",L"Regi�o do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|Street",L"Rua do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|StreetDetail",L"Detalhe da rua do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|BuildingName",L"Pr�dio do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|BuildingNumber",L"1"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|BuildingFloor",L"2"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|PostalCode",L"7600"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|AddressDetail",L"Detalhe de endere�o do Emissor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Address|AddressCode",L"CV774999999999999319"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Contacts|Telephone",L"1234567"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Contacts|Mobilephone",L"1234568"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Contacts|Telefax",L"1234569"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Contacts|Email",L"somebody@example.com"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|EmitterParty|Contacts|Website",L"emissor.efatura.cv"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|ReceiverParty|TaxId",TRUE,L"CountryCode",L"CV"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|TaxId",L"123456789"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Name",L"Nome do Recetor"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|ReceiverParty|Address",TRUE,L"CountryCode",L"CV"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|State",L"Estado do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|City",L"Cidade do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|Region",L"Regi�o do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|Street",L"Rua do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|StreetDetail",L"Detalhe da rua do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|BuildingName",L"Pr�dio do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|BuildingNumber",L"2"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|BuildingFloor",L"3"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|PostalCode",L"7601"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|AddressDetail",L"Detalhe de endere�o do Recetor"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Address|AddressCode",L"CV774999999999999319"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Contacts|Telephone",L"2234567"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Contacts|Mobilephone",L"2234568"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Contacts|Telefax",L"2234569"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Contacts|Email",L"rector@efatura.cv"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|ReceiverParty|Contacts|Website",L"rector.efatura.cv"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|Lines|Line",TRUE,L"LineTypeCode",L"N"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Id",L"01"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|OrderLineReference",L"1"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|Lines|Line|Quantity",TRUE,L"UnitCode",L"EA"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Quantity",L"3.15"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Price",L"123456"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|PriceExtension",L"388886"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Discount",L"15"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|NetTotal",L"252776"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|Lines|Line|Tax",TRUE,L"TaxTypeCode",L"IVA"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Tax|TaxPercentage",L"15"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|Description",L"Telem�vel"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|Name",L"Telem�vel"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|BrandName",L"Apple"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|ModelName",L"iPhone X"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|EmitterIdentification",L"TLMV"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|StandardIdentification|GTIN",L"12345"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Lines|Line|Item|HazardousRiskIndicator",L"false"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|PriceExtensionTotalAmount",L"388886"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|ChargeTotalAmount",L"0"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|DiscountTotalAmount",L"136110"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|NetTotalAmount",L"252776"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|Totals|Discount",TRUE,L"ValueType",L"P"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|Discount",L"20"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|TaxTotalAmount",L"37916"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Totals|PayableAmount",L"290692"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|References|Reference|FiscalDocument",TRUE,L"IsOldDocument",L"false"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|References|Reference|FiscalDocument",L"CV1200520123456789000112345678901112345678901"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|References|Reference|PaymentAmount",L"12345"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|References|Reference|Tax",TRUE,L"TaxTypeCode",L"IR"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|References|Reference|Tax|TaxPercentage",L"10"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|References|Reference[1]|FiscalDocument",TRUE,L"IsOldDocument",L"false"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|References|Reference[1]|FiscalDocument",L"CV1200520123456789000112345678901112345678903"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|References|Reference[1]|PaymentAmount",L"98765"); CkXmlW_UpdateAttrAt(xmlToSign,L"Invoice|References|Reference[1]|Tax",TRUE,L"TaxTypeCode",L"IVA"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|References|Reference[1]|Tax|TaxPercentage",L"15"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Payments|PaymentDueDate",L"2021-12-31"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Payments|PaymentTerms|Note",L"Juros de 12% a partir da data de vencimento"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Payments|PayeeFinancialAccount|NIB",L"123456789012345678901"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Payments|PayeeFinancialAccount|Name",L"Nome da Conta 1"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Payments|PayeeFinancialAccount[1]|NIB",L"123456789012345678902"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Payments|PayeeFinancialAccount[1]|Name",L"Nome da Conta 2"); CkXmlW_UpdateChildContent(xmlToSign,L"Invoice|Note",L"Texto livre"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|IssueMode",L"2"); CkXmlW_UpdateAttrAt(xmlToSign,L"Transmission|TransmitterTaxId",TRUE,L"CountryCode",L"CV"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|TransmitterTaxId",L"123456789"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Software|Code",L"EMIPUB"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Software|Name",L"DNRE Emissor P�blico"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Software|Version",L"Build #53 12-07-2021 14:00:47 CVT - master"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Contingency|LedCode",L"1"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Contingency|IssueDate",L"2020-01-01"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Contingency|IssueTime",L"01:02:03"); CkXmlW_UpdateChildContent(xmlToSign,L"Transmission|Contingency|ReasonTypeCode",L"1"); CkXmlW_UpdateChildContent(xmlToSign,L"RepositoryCode",L"2"); gen = CkXmlDSigGenW_Create(); CkXmlDSigGenW_putSigLocation(gen,L"Dfe"); CkXmlDSigGenW_putSigLocationMod(gen,0); CkXmlDSigGenW_putSigId(gen,L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac"); CkXmlDSigGenW_putSigNamespacePrefix(gen,L"ds"); CkXmlDSigGenW_putSigNamespaceUri(gen,L"http://www.w3.org/2000/09/xmldsig#"); CkXmlDSigGenW_putSigValueId(gen,L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-sigvalue"); CkXmlDSigGenW_putSignedInfoCanonAlg(gen,L"C14N"); CkXmlDSigGenW_putSignedInfoDigestMethod(gen,L"sha256"); // Set the KeyInfoId before adding references.. CkXmlDSigGenW_putKeyInfoId(gen,L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo"); // Create an Object to be added to the Signature. object1 = CkXmlW_Create(); CkXmlW_putTag(object1,L"xades:QualifyingProperties"); CkXmlW_AddAttribute(object1,L"xmlns:xades",L"http://uri.etsi.org/01903/v1.3.2#"); CkXmlW_AddAttribute(object1,L"xmlns:xades141",L"http://uri.etsi.org/01903/v1.4.1#"); CkXmlW_AddAttribute(object1,L"Target",L"#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac"); CkXmlW_UpdateAttrAt(object1,L"xades:SignedProperties",TRUE,L"Id",L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime",L"TO BE GENERATED BY CHILKAT"); CkXmlW_UpdateAttrAt(object1,L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestMethod",TRUE,L"Algorithm",L"http://www.w3.org/2001/04/xmlenc#sha256"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestValue",L"TO BE GENERATED BY CHILKAT"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:IssuerSerialV2",L"TO BE GENERATED BY CHILKAT"); CkXmlW_UpdateAttrAt(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat",TRUE,L"ObjectReference",L"#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description",L"DFE Signature"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier",L"efatura-uri"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:DocumentationReferences|xades:DocumentationReference",L"https://efatura.cv"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType",L"text/xml"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding",L"UTF-8"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Identifier",L"http://uri.etsi.org/01903/v1.2.2#ProofOfApproval"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Description",L"Indicates that the signer has approved the content of the signed data object"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:AllSignedDataObjects",L""); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Identifier",L"http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Description",L"Indicates that the signer recognizes to have created, approved and sent the signed data object"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:ObjectReference",L"#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0"); CkXmlW_UpdateChildContent(object1,L"xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeQualifiers|xades:CommitmentTypeQualifier",L"CV-FE-123456789"); CkXmlDSigGenW_AddObject(gen,L"",CkXmlW_getXml(object1),L"",L""); // -------- Reference 1 -------- CkXmlDSigGenW_AddSameDocRef(gen,L"CV2210818123456789000010100000000546735014601",L"sha256",L"",L"",L""); CkXmlDSigGenW_SetRefIdAttr(gen,L"CV2210818123456789000010100000000546735014601",L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0"); // -------- Reference 2 -------- CkXmlDSigGenW_AddSameDocRef(gen,L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo",L"sha256",L"C14N",L"",L""); // -------- Reference 3 -------- CkXmlDSigGenW_AddObjectRef(gen,L"xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops",L"sha256",L"C14N",L"",L"http://uri.etsi.org/01903#SignedProperties"); // Provide a certificate + private key. (PFX password is test123) cert = CkCertW_Create(); success = CkCertW_LoadPfxFile(cert,L"qa_data/pfx/cert_test123.pfx",L"test123"); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(object1); CkCertW_Dispose(cert); return; } CkXmlDSigGenW_SetX509Cert(gen,cert,TRUE); CkXmlDSigGenW_putKeyInfoType(gen,L"X509Data"); CkXmlDSigGenW_putX509Type(gen,L"IssuerSerial,SubjectName,Certificate"); // Load XML to be signed... sbXml = CkStringBuilderW_Create(); CkXmlW_GetXmlSb(xmlToSign,sbXml); // Note: The last keyword (Base64Cr13Entity) requires Chilkat v9.5.0.89 or later. CkXmlDSigGenW_putBehaviors(gen,L"IndentedSignature,Base64Cr13Entity,ForceAddEnvelopedSignatureTransform,Base64Cr13Entity"); // Sign the XML... success = CkXmlDSigGenW_CreateXmlDSigSb(gen,sbXml); if (success != TRUE) { wprintf(L"%s\n",CkXmlDSigGenW_lastErrorText(gen)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(object1); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); return; } // ----------------------------------------------- // Save the signed XML to a file. success = CkStringBuilderW_WriteFile(sbXml,L"qa_output/signedXml.xml",L"utf-8",FALSE); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbXml)); // ---------------------------------------- // Verify the signatures we just produced... verifier = CkXmlDSigW_Create(); success = CkXmlDSigW_LoadSignatureSb(verifier,sbXml); if (success != TRUE) { wprintf(L"%s\n",CkXmlDSigW_lastErrorText(verifier)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(object1); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); CkXmlDSigW_Dispose(verifier); return; } numSigs = CkXmlDSigW_getNumSignatures(verifier); verifyIdx = 0; while (verifyIdx < numSigs) { CkXmlDSigW_putSelector(verifier,verifyIdx); verified = CkXmlDSigW_VerifySignature(verifier,TRUE); if (verified != TRUE) { wprintf(L"%s\n",CkXmlDSigW_lastErrorText(verifier)); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(object1); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); CkXmlDSigW_Dispose(verifier); return; } verifyIdx = verifyIdx + 1; } wprintf(L"All signatures were successfully verified.\n"); CkXmlW_Dispose(xmlToSign); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(object1); CkCertW_Dispose(cert); CkStringBuilderW_Dispose(sbXml); CkXmlDSigW_Dispose(verifier); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.