Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual FoxPro Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual FoxPro) 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 ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL lnSuccess
LOCAL loXmlToSign
LOCAL loGen
LOCAL loObject1
LOCAL loCert
LOCAL loSbXml
LOCAL loVerifier
LOCAL lnNumSigs
LOCAL lnVerifyIdx
LOCAL lnVerified

* 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>

lnSuccess = 1

* Create the XML to be signed...

* Use this online tool to generate code from sample XML: 
* Generate Code to Create XML

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml')
loXmlToSign = CreateObject('Chilkat.Xml')
loXmlToSign.Tag = "Dfe"
loXmlToSign.AddAttribute("xmlns","urn:cv:efatura:xsd:v1.0")
loXmlToSign.AddAttribute("DocumentTypeCode","1")
loXmlToSign.AddAttribute("Id","CV2210818123456789000010100000000546735014601")
loXmlToSign.AddAttribute("Version","1.0")
loXmlToSign.UpdateChildContent("Invoice|LedCode","1")
loXmlToSign.UpdateChildContent("Invoice|Serie","SL")
loXmlToSign.UpdateChildContent("Invoice|DocumentNumber","5")
loXmlToSign.UpdateChildContent("Invoice|IssueDate","2021-08-30")
loXmlToSign.UpdateChildContent("Invoice|IssueTime","00:01:00")
loXmlToSign.UpdateChildContent("Invoice|TaxPointDate","2021-08-18")
loXmlToSign.UpdateAttrAt("Invoice|EmitterParty|TaxId",1,"CountryCode","CV")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|TaxId","123456789")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Name","Maria")
loXmlToSign.UpdateAttrAt("Invoice|EmitterParty|Address",1,"CountryCode","CV")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|State","Estado do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|City","Cidade do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|Region","Regi�o do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|Street","Rua do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|StreetDetail","Detalhe da rua do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|BuildingName","Pr�dio do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|BuildingNumber","1")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|BuildingFloor","2")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|PostalCode","7600")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|AddressDetail","Detalhe de endere�o do Emissor")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Address|AddressCode","CV774999999999999319")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Telephone","1234567")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Mobilephone","1234568")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Telefax","1234569")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Email","somebody@example.com")
loXmlToSign.UpdateChildContent("Invoice|EmitterParty|Contacts|Website","emissor.efatura.cv")
loXmlToSign.UpdateAttrAt("Invoice|ReceiverParty|TaxId",1,"CountryCode","CV")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|TaxId","123456789")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Name","Nome do Recetor")
loXmlToSign.UpdateAttrAt("Invoice|ReceiverParty|Address",1,"CountryCode","CV")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|State","Estado do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|City","Cidade do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|Region","Regi�o do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|Street","Rua do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|StreetDetail","Detalhe da rua do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|BuildingName","Pr�dio do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|BuildingNumber","2")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|BuildingFloor","3")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|PostalCode","7601")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|AddressDetail","Detalhe de endere�o do Recetor")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Address|AddressCode","CV774999999999999319")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Telephone","2234567")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Mobilephone","2234568")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Telefax","2234569")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Email","rector@efatura.cv")
loXmlToSign.UpdateChildContent("Invoice|ReceiverParty|Contacts|Website","rector.efatura.cv")
loXmlToSign.UpdateAttrAt("Invoice|Lines|Line",1,"LineTypeCode","N")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Id","01")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|OrderLineReference","1")
loXmlToSign.UpdateAttrAt("Invoice|Lines|Line|Quantity",1,"UnitCode","EA")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Quantity","3.15")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Price","123456")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|PriceExtension","388886")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Discount","15")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|NetTotal","252776")
loXmlToSign.UpdateAttrAt("Invoice|Lines|Line|Tax",1,"TaxTypeCode","IVA")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Tax|TaxPercentage","15")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|Description","Telem�vel")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|Name","Telem�vel")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|BrandName","Apple")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|ModelName","iPhone X")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|EmitterIdentification","TLMV")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|StandardIdentification|GTIN","12345")
loXmlToSign.UpdateChildContent("Invoice|Lines|Line|Item|HazardousRiskIndicator","false")
loXmlToSign.UpdateChildContent("Invoice|Totals|PriceExtensionTotalAmount","388886")
loXmlToSign.UpdateChildContent("Invoice|Totals|ChargeTotalAmount","0")
loXmlToSign.UpdateChildContent("Invoice|Totals|DiscountTotalAmount","136110")
loXmlToSign.UpdateChildContent("Invoice|Totals|NetTotalAmount","252776")
loXmlToSign.UpdateAttrAt("Invoice|Totals|Discount",1,"ValueType","P")
loXmlToSign.UpdateChildContent("Invoice|Totals|Discount","20")
loXmlToSign.UpdateChildContent("Invoice|Totals|TaxTotalAmount","37916")
loXmlToSign.UpdateChildContent("Invoice|Totals|PayableAmount","290692")
loXmlToSign.UpdateAttrAt("Invoice|References|Reference|FiscalDocument",1,"IsOldDocument","false")
loXmlToSign.UpdateChildContent("Invoice|References|Reference|FiscalDocument","CV1200520123456789000112345678901112345678901")
loXmlToSign.UpdateChildContent("Invoice|References|Reference|PaymentAmount","12345")
loXmlToSign.UpdateAttrAt("Invoice|References|Reference|Tax",1,"TaxTypeCode","IR")
loXmlToSign.UpdateChildContent("Invoice|References|Reference|Tax|TaxPercentage","10")
loXmlToSign.UpdateAttrAt("Invoice|References|Reference[1]|FiscalDocument",1,"IsOldDocument","false")
loXmlToSign.UpdateChildContent("Invoice|References|Reference[1]|FiscalDocument","CV1200520123456789000112345678901112345678903")
loXmlToSign.UpdateChildContent("Invoice|References|Reference[1]|PaymentAmount","98765")
loXmlToSign.UpdateAttrAt("Invoice|References|Reference[1]|Tax",1,"TaxTypeCode","IVA")
loXmlToSign.UpdateChildContent("Invoice|References|Reference[1]|Tax|TaxPercentage","15")
loXmlToSign.UpdateChildContent("Invoice|Payments|PaymentDueDate","2021-12-31")
loXmlToSign.UpdateChildContent("Invoice|Payments|PaymentTerms|Note","Juros de 12% a partir da data de vencimento")
loXmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount|NIB","123456789012345678901")
loXmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount|Name","Nome da Conta 1")
loXmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount[1]|NIB","123456789012345678902")
loXmlToSign.UpdateChildContent("Invoice|Payments|PayeeFinancialAccount[1]|Name","Nome da Conta 2")
loXmlToSign.UpdateChildContent("Invoice|Note","Texto livre")
loXmlToSign.UpdateChildContent("Transmission|IssueMode","2")
loXmlToSign.UpdateAttrAt("Transmission|TransmitterTaxId",1,"CountryCode","CV")
loXmlToSign.UpdateChildContent("Transmission|TransmitterTaxId","123456789")
loXmlToSign.UpdateChildContent("Transmission|Software|Code","EMIPUB")
loXmlToSign.UpdateChildContent("Transmission|Software|Name","DNRE Emissor P�blico")
loXmlToSign.UpdateChildContent("Transmission|Software|Version","Build #53 12-07-2021 14:00:47 CVT - master")
loXmlToSign.UpdateChildContent("Transmission|Contingency|LedCode","1")
loXmlToSign.UpdateChildContent("Transmission|Contingency|IssueDate","2020-01-01")
loXmlToSign.UpdateChildContent("Transmission|Contingency|IssueTime","01:02:03")
loXmlToSign.UpdateChildContent("Transmission|Contingency|ReasonTypeCode","1")
loXmlToSign.UpdateChildContent("RepositoryCode","2")

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSigGen')
loGen = CreateObject('Chilkat.XmlDSigGen')

loGen.SigLocation = "Dfe"
loGen.SigLocationMod = 0
loGen.SigId = "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac"
loGen.SigNamespacePrefix = "ds"
loGen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
loGen.SigValueId = "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-sigvalue"
loGen.SignedInfoCanonAlg = "C14N"
loGen.SignedInfoDigestMethod = "sha256"

* Set the KeyInfoId before adding references..
loGen.KeyInfoId = "xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo"

* Create an Object to be added to the Signature.
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Xml')
loObject1 = CreateObject('Chilkat.Xml')
loObject1.Tag = "xades:QualifyingProperties"
loObject1.AddAttribute("xmlns:xades","http://uri.etsi.org/01903/v1.3.2#")
loObject1.AddAttribute("xmlns:xades141","http://uri.etsi.org/01903/v1.4.1#")
loObject1.AddAttribute("Target","#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac")
loObject1.UpdateAttrAt("xades:SignedProperties",1,"Id","xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-signedprops")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime","TO BE GENERATED BY CHILKAT")
loObject1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestMethod",1,"Algorithm","http://www.w3.org/2001/04/xmlenc#sha256")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificateV2|xades:Cert|xades:IssuerSerialV2","TO BE GENERATED BY CHILKAT")
loObject1.UpdateAttrAt("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat",1,"ObjectReference","#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Description","DFE Signature")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:Identifier","efatura-uri")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:ObjectIdentifier|xades:DocumentationReferences|xades:DocumentationReference","https://efatura.cv")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:MimeType","text/xml")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:DataObjectFormat|xades:Encoding","UTF-8")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Identifier","http://uri.etsi.org/01903/v1.2.2#ProofOfApproval")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:CommitmentTypeId|xades:Description","Indicates that the signer has approved the content of the signed data object")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication|xades:AllSignedDataObjects","")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeId|xades:Identifier","http://uri.etsi.org/01903/v1.2.2#ProofOfOrigin")
loObject1.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")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:ObjectReference","#xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0")
loObject1.UpdateChildContent("xades:SignedProperties|xades:SignedDataObjectProperties|xades:CommitmentTypeIndication[1]|xades:CommitmentTypeQualifiers|xades:CommitmentTypeQualifier","CV-FE-123456789")

loGen.AddObject("",loObject1.GetXml(),"","")

* -------- Reference 1 --------
loGen.AddSameDocRef("CV2210818123456789000010100000000546735014601","sha256","","","")
loGen.SetRefIdAttr("CV2210818123456789000010100000000546735014601","xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-ref0")

* -------- Reference 2 --------
loGen.AddSameDocRef("xmldsig-cbd86598-e75e-4ae4-9a27-3b4ee2a789ac-keyinfo","sha256","C14N","","")

* -------- Reference 3 --------
loGen.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)
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Cert')
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
IF (lnSuccess <> 1) THEN
    ? loCert.LastErrorText
    RELEASE loXmlToSign
    RELEASE loGen
    RELEASE loObject1
    RELEASE loCert
    CANCEL
ENDIF

loGen.SetX509Cert(loCert,1)

loGen.KeyInfoType = "X509Data"
loGen.X509Type = "IssuerSerial,SubjectName,Certificate"

* Load XML to be signed...
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbXml = CreateObject('Chilkat.StringBuilder')
loXmlToSign.GetXmlSb(loSbXml)

* Note: The last keyword (Base64Cr13Entity) requires Chilkat v9.5.0.89 or later.
loGen.Behaviors = "IndentedSignature,Base64Cr13Entity,ForceAddEnvelopedSignatureTransform,Base64Cr13Entity"

* Sign the XML...
lnSuccess = loGen.CreateXmlDSigSb(loSbXml)
IF (lnSuccess <> 1) THEN
    ? loGen.LastErrorText
    RELEASE loXmlToSign
    RELEASE loGen
    RELEASE loObject1
    RELEASE loCert
    RELEASE loSbXml
    CANCEL
ENDIF

* -----------------------------------------------

* Save the signed XML to a file.
lnSuccess = loSbXml.WriteFile("qa_output/signedXml.xml","utf-8",0)

? loSbXml.GetAsString()

* ----------------------------------------
* Verify the signatures we just produced...
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.XmlDSig')
loVerifier = CreateObject('Chilkat.XmlDSig')
lnSuccess = loVerifier.LoadSignatureSb(loSbXml)
IF (lnSuccess <> 1) THEN
    ? loVerifier.LastErrorText
    RELEASE loXmlToSign
    RELEASE loGen
    RELEASE loObject1
    RELEASE loCert
    RELEASE loSbXml
    RELEASE loVerifier
    CANCEL
ENDIF

lnNumSigs = loVerifier.NumSignatures
lnVerifyIdx = 0
DO WHILE lnVerifyIdx < lnNumSigs
    loVerifier.Selector = lnVerifyIdx
    lnVerified = loVerifier.VerifySignature(1)
    IF (lnVerified <> 1) THEN
        ? loVerifier.LastErrorText
        RELEASE loXmlToSign
        RELEASE loGen
        RELEASE loObject1
        RELEASE loCert
        RELEASE loSbXml
        RELEASE loVerifier
        CANCEL
    ENDIF

    lnVerifyIdx = lnVerifyIdx + 1
ENDDO
? "All signatures were successfully verified."

RELEASE loXmlToSign
RELEASE loGen
RELEASE loObject1
RELEASE loCert
RELEASE loSbXml
RELEASE loVerifier


 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.