PowerBuilder
PowerBuilder
Cape Verde Fatura Eletrónica XML Digital Signature
See more XML Digital Signatures Examples
Demonstrates 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
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_XmlToSign
oleobject loo_Gen
oleobject loo_Object1
oleobject loo_Cert
oleobject loo_SbXml
oleobject loo_Verifier
integer li_NumSigs
integer li_VerifyIdx
integer li_Verified
li_Success = 0
// 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>
li_Success = 1
// Create the XML to be signed...
// Use this online tool to generate code from sample XML:
// Generate Code to Create XML
loo_XmlToSign = create oleobject
li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
destroy loo_XmlToSign
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_XmlToSign.Tag = "Dfe"
loo_XmlToSign.AddAttribute("xmlns","urn:cv:efatura:xsd:v1.0")
loo_XmlToSign.AddAttribute("DocumentTypeCode","1")
loo_XmlToSign.AddAttribute("Id","CV2210818123456789000010100000000546735014601")
loo_XmlToSign.AddAttribute("Version","1.0")
loo_XmlToSign.UpdateChildContent("Invoice|LedCode","1")
loo_XmlToSign.UpdateChildContent("Invoice|Serie","SL")
loo_XmlToSign.UpdateChildContent("Invoice|DocumentNumber","5")
loo_XmlToSign.UpdateChildContent("Invoice|IssueDate","2021-08-30")
loo_XmlToSign.UpdateChildContent("Invoice|IssueTime","00:01:00")
loo_XmlToSign.UpdateChildContent("Invoice|TaxPointDate","2021-08-18")
loo_XmlToSign.UpdateAttrAt("Invoice|EmitterParty|TaxId",1,"CountryCode","CV")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|TaxId","123456789")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Name","Maria")
loo_XmlToSign.UpdateAttrAt("Invoice|EmitterParty|Address",1,"CountryCode","CV")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|State","Estado do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|City","Cidade do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|Region","Regi�o do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|Street","Rua do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|StreetDetail","Detalhe da rua do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|BuildingName","Pr�dio do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|BuildingNumber","1")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|BuildingFloor","2")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|PostalCode","7600")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|AddressDetail","Detalhe de endere�o do Emissor")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|AddressCode","CV774999999999999319")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Telephone","1234567")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Mobilephone","1234568")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Telefax","1234569")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Email","somebody@example.com")
loo_XmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Website","emissor.efatura.cv")
loo_XmlToSign.UpdateAttrAt("Invoice|ReceiverParty|TaxId",1,"CountryCode","CV")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|TaxId","123456789")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Name","Nome do Recetor")
loo_XmlToSign.UpdateAttrAt("Invoice|ReceiverParty|Address",1,"CountryCode","CV")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|State","Estado do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|City","Cidade do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|Region","Regi�o do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|Street","Rua do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|StreetDetail","Detalhe da rua do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|BuildingName","Pr�dio do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|BuildingNumber","2")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|BuildingFloor","3")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|PostalCode","7601")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|AddressDetail","Detalhe de endere�o do Recetor")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|AddressCode","CV774999999999999319")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Telephone","2234567")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Mobilephone","2234568")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Telefax","2234569")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Email","rector@efatura.cv")
loo_XmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Website","rector.efatura.cv")
loo_XmlToSign.UpdateAttrAt("Invoice|Lines|Line",1,"LineTypeCode","N")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Id","01")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|OrderLineReference","1")
loo_XmlToSign.UpdateAttrAt("Invoice|Lines|Line|Quantity",1,"UnitCode","EA")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Quantity","3.15")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Price","123456")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|PriceExtension","388886")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Discount","15")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|NetTotal","252776")
loo_XmlToSign.UpdateAttrAt("Invoice|Lines|Line|Tax",1,"TaxTypeCode","IVA")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Tax|TaxPercentage","15")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|Description","Telem�vel")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|Name","Telem�vel")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|BrandName","Apple")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|ModelName","iPhone X")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|EmitterIdentification","TLMV")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|StandardIdentification|GTIN","12345")
loo_XmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|HazardousRiskIndicator","false")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|PriceExtensionTotalAmount","388886")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|ChargeTotalAmount","0")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|DiscountTotalAmount","136110")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|NetTotalAmount","252776")
loo_XmlToSign.UpdateAttrAt("Invoice|Totals|Discount",1,"ValueType","P")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|Discount","20")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|TaxTotalAmount","37916")
loo_XmlToSign.UpdateChildContent("Invoice|Totals|PayableAmount","290692")
loo_XmlToSign.UpdateAttrAt("Invoice|References|Reference|FiscalDocument",1,"IsOldDocument","false")
loo_XmlToSign.UpdateChildContent("Invoice|References|Reference|FiscalDocument","CV1200520123456789000112345678901112345678901")
loo_XmlToSign.UpdateChildContent("Invoice|References|Reference|PaymentAmount","12345")
loo_XmlToSign.UpdateAttrAt("Invoice|References|Reference|Tax",1,"TaxTypeCode","IR")
loo_XmlToSign.UpdateChildContent("Invoice|References|Reference|Tax|TaxPercentage","10")
loo_XmlToSign.UpdateAttrAt("Invoice|References|Reference[1]|FiscalDocument",1,"IsOldDocument","false")
loo_XmlToSign.UpdateChildContent("Invoice|References|Reference[1]|FiscalDocument","CV1200520123456789000112345678901112345678903")
loo_XmlToSign.UpdateChildContent("Invoice|References|Reference[1]|PaymentAmount","98765")
loo_XmlToSign.UpdateAttrAt("Invoice|References|Reference[1]|Tax",1,"TaxTypeCode","IVA")
loo_XmlToSign.UpdateChildContent("Invoice|References|Reference[1]|Tax|TaxPercentage","15")
loo_XmlToSign.UpdateChildContent("Invoice|Payments|PaymentDueDate","2021-12-31")
loo_XmlToSign.UpdateChildContent("Invoice|Payments|PaymentTerms|Note","Juros de 12% a partir da data de vencimento")
loo_XmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount|NIB","123456789012345678901")
loo_XmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount|Name","Nome da Conta 1")
loo_XmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount[1]|NIB","123456789012345678902")
loo_XmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount[1]|Name","Nome da Conta 2")
loo_XmlToSign.UpdateChildContent("Invoice|Note","Texto livre")
loo_XmlToSign.UpdateChildContent("Transmission|IssueMode","2")
loo_XmlToSign.UpdateAttrAt("Transmission|TransmitterTaxId",1,"CountryCode","CV")
loo_XmlToSign.UpdateChildContent("Transmission|TransmitterTaxId","123456789")
loo_XmlToSign.UpdateChildContent("Transmission|Software|Code","EMIPUB")
loo_XmlToSign.UpdateChildContent("Transmission|Software|Name","DNRE Emissor P�blico")
loo_XmlToSign.UpdateChildContent("Transmission|Software|Version","Build #53 12-07-2021 14:00:47 CVT - master")
loo_XmlToSign.UpdateChildContent("Transmission|Contingency|LedCode","1")
loo_XmlToSign.UpdateChildContent("Transmission|Contingency|IssueDate","2020-01-01")
loo_XmlToSign.UpdateChildContent("Transmission|Contingency|IssueTime","01:02:03")
loo_XmlToSign.UpdateChildContent("Transmission|Contingency|ReasonTypeCode","1")
loo_XmlToSign.UpdateChildContent("RepositoryCode","2")
loo_Gen = create oleobject
li_rc = loo_Gen.ConnectToNewObject("Chilkat.XmlDSigGen")
loo_Gen.SigLocation = "Dfe"
loo_Gen.SigLocationMod = 0
loo_Gen.SigId = "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac"
loo_Gen.SigNamespacePrefix = "ds"
loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
loo_Gen.SigValueId = "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-sigvalue"
loo_Gen.SignedInfoCanonAlg = "C14N"
loo_Gen.SignedInfoDigestMethod = "sha256"
// Set the KeyInfoId before adding references..
loo_Gen.KeyInfoId = "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo"
// Create an Object to be added to the Signature.
loo_Object1 = create oleobject
li_rc = loo_Object1.ConnectToNewObject("Chilkat.Xml")
loo_Object1.Tag = "xades:QualifyingProperties"
loo_Object1.AddAttribute("xmlns:xades","http://uri.etsi.org/01903/v1.3.2#")
loo_Object1.AddAttribute("xmlns:xades141","http://uri.etsi.org/01903/v1.4.1#")
loo_Object1.AddAttribute("Target","#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac")
loo_Object1.UpdateAttrAt("xades:SignedProperties",1,"Id","xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime","TO BE GENERATED BY CHILKAT")
loo_Object1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestMethod",1,"Algorithm","http://www.w3.org/2001/04/xmlenc#sha256")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:IssuerSerialV2","TO BE GENERATED BY CHILKAT")
loo_Object1.UpdateAttrAt("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat",1,"ObjectReference","#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description","DFE Signature")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier","efatura-uri")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:DocumentationReferences|xades:DocumentationReference","https://efatura.cv")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType","text/xml")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding","UTF-8")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Identifier","http://uri.etsi.org/01903/v1.2.2#ProofOfApproval")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Description","Indicates that the signer has approved the content of the signed data object")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:AllSignedDataObjects","")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Identifier","http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin")
loo_Object1.UpdateChildContent("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")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:ObjectReference","#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0")
loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeQualifiers|xades:CommitmentTypeQualifier","CV-FE-123456789")
loo_Gen.AddObject("",loo_Object1.GetXml(),"","")
// -------- Reference 1 --------
loo_Gen.AddSameDocRef("CV2210818123456789000010100000000546735014601","sha256","","","")
loo_Gen.SetRefIdAttr("CV2210818123456789000010100000000546735014601","xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0")
// -------- Reference 2 --------
loo_Gen.AddSameDocRef("xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo","sha256","C14N","","")
// -------- Reference 3 --------
loo_Gen.AddObjectRef("xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops","sha256","C14N","","http://uri.etsi.org/01903#SignedProperties")
// Provide a certificate + private key. (PFX password is test123)
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
if li_Success <> 1 then
Write-Debug loo_Cert.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Object1
destroy loo_Cert
return
end if
loo_Gen.SetX509Cert(loo_Cert,1)
loo_Gen.KeyInfoType = "X509Data"
loo_Gen.X509Type = "IssuerSerial,SubjectName,Certificate"
// Load XML to be signed...
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")
loo_XmlToSign.GetXmlSb(loo_SbXml)
// Note: The last keyword (Base64Cr13Entity) requires Chilkat v9.5.0.89 or later.
loo_Gen.Behaviors = "IndentedSignature,Base64Cr13Entity,ForceAddEnvelopedSignatureTransform,Base64Cr13Entity"
// Sign the XML...
li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml)
if li_Success <> 1 then
Write-Debug loo_Gen.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Object1
destroy loo_Cert
destroy loo_SbXml
return
end if
// -----------------------------------------------
// Save the signed XML to a file.
li_Success = loo_SbXml.WriteFile("qa_output/signedXml.xml","utf-8",0)
Write-Debug loo_SbXml.GetAsString()
// ----------------------------------------
// Verify the signatures we just produced...
loo_Verifier = create oleobject
li_rc = loo_Verifier.ConnectToNewObject("Chilkat.XmlDSig")
li_Success = loo_Verifier.LoadSignatureSb(loo_SbXml)
if li_Success <> 1 then
Write-Debug loo_Verifier.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Object1
destroy loo_Cert
destroy loo_SbXml
destroy loo_Verifier
return
end if
li_NumSigs = loo_Verifier.NumSignatures
li_VerifyIdx = 0
do while li_VerifyIdx < li_NumSigs
loo_Verifier.Selector = li_VerifyIdx
li_Verified = loo_Verifier.VerifySignature(1)
if li_Verified <> 1 then
Write-Debug loo_Verifier.LastErrorText
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Object1
destroy loo_Cert
destroy loo_SbXml
destroy loo_Verifier
return
end if
li_VerifyIdx = li_VerifyIdx + 1
loop
Write-Debug "All signatures were successfully verified."
destroy loo_XmlToSign
destroy loo_Gen
destroy loo_Object1
destroy loo_Cert
destroy loo_SbXml
destroy loo_Verifier