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 Basic 6.0 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
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 Basic 6.0) Create XAdES-T Signed XML

See more XAdES Examples

This example signs XML using the XAdES-T profile. XAdES-T is a profile within the XAdES standard that adds support for secure timestamping of signatures.

Secure timestamping involves adding a timestamp to the signature, indicating the exact time when the signature was applied.

Timestamping enhances the long-term validity of signatures by providing evidence that the signature existed at a specific point in time, even if the signer's certificate has expired or been revoked.

XAdES-T signatures include elements for embedding timestamp data within the XML signature, along with information about the timestamp authority and the timestamp verification process.

XAdES-T signatures are suitable for scenarios where long-term validity and integrity of signatures are essential, such as in legal and regulatory contexts where archived documents may need to be validated years or decades later.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

Dim success As Long
success = 1
' Create the XML to be signed...

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

' <?xml version="1.0" encoding="UTF-8"?>
' <es:Dossier xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns="http://uri.etsi.org/01903/v1.3.2#" xmlns:es="https://www.microsec.hu/ds/e-szigno30#" xsi:schemaLocation="https://www.microsec.hu/ds/e-szigno30# https://www.microsec.hu/ds/e-szigno30.xsd">
' 	<es:DossierProfile Id="PObject0" OBJREF="Object0">
' 	<es:Title>e-akta.es3</es:Title>
' 	<es:E-category>electronic dossier</es:E-category>
' 	<es:CreationDate>2022-12-02T07:55:16Z</es:CreationDate>
' 	</es:DossierProfile>
' 	<es:Documents Id="Object0"/>
' </es:Dossier>

Dim xmlToSign As New ChilkatXml
xmlToSign.Tag = "es:Dossier"
success = xmlToSign.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
success = xmlToSign.AddAttribute("xmlns:ds","http://www.w3.org/2000/09/xmldsig#")
success = xmlToSign.AddAttribute("xmlns","http://uri.etsi.org/01903/v1.3.2#")
success = xmlToSign.AddAttribute("xmlns:es","https://www.microsec.hu/ds/e-szigno30#")
success = xmlToSign.AddAttribute("xsi:schemaLocation","https://www.microsec.hu/ds/e-szigno30# https://www.microsec.hu/ds/e-szigno30.xsd")
success = xmlToSign.UpdateAttrAt("es:DossierProfile",1,"Id","PObject0")
success = xmlToSign.UpdateAttrAt("es:DossierProfile",1,"OBJREF","Object0")
xmlToSign.UpdateChildContent "es:DossierProfile|es:Title","e-akta.es3"
xmlToSign.UpdateChildContent "es:DossierProfile|es:E-category","electronic dossier"
xmlToSign.UpdateChildContent "es:DossierProfile|es:CreationDate","2022-12-02T07:55:16Z"
success = xmlToSign.UpdateAttrAt("es:Documents",1,"Id","Object0")

Dim gen As New ChilkatXmlDSigGen

gen.SigLocation = "es:Dossier"
gen.SigLocationMod = 0
gen.SigId = "S9fe8096e-2cac-415d-9222-f6cf2ecb314b"
gen.SigValueId = "VS9fe8096e-2cac-415d-9222-f6cf2ecb314b"
gen.SignedInfoId = "SIS9fe8096e-2cac-415d-9222-f6cf2ecb314b"
gen.SignedInfoCanonAlg = "EXCL_C14N"
gen.SignedInfoDigestMethod = "sha256"

' Set the KeyInfoId before adding references..
gen.KeyInfoId = "KS9fe8096e-2cac-415d-9222-f6cf2ecb314b"

' Create an Object to be added to the Signature.
Dim object1 As New ChilkatXml
object1.Tag = "es:SignatureProfile"
success = object1.AddAttribute("Id","PS9fe8096e-2cac-415d-9222-f6cf2ecb314b")
success = object1.AddAttribute("OBJREF","Object0")
success = object1.AddAttribute("SIGREF","S9fe8096e-2cac-415d-9222-f6cf2ecb314b")
success = object1.AddAttribute("SIGREFLIST","#Object0 #PS9fe8096e-2cac-415d-9222-f6cf2ecb314b #PObject0 #XS9fe8096e-2cac-415d-9222-f6cf2ecb314b")
object1.UpdateChildContent "es:SignerName","EC Minsített-Tesztel Péterke"
object1.UpdateChildContent "es:SDPresented","false"
object1.UpdateChildContent "es:Type","signature"
success = object1.UpdateAttrAt("es:Generator|es:Program",1,"name","e-Szigno")
success = object1.UpdateAttrAt("es:Generator|es:Program",1,"version","3.3.6.8")
success = object1.UpdateAttrAt("es:Generator|es:Device",1,"name","OpenSSL 1.1.1n  15 Mar 2022")
success = object1.UpdateAttrAt("es:Generator|es:Device",1,"type","")

success = gen.AddObject("O1S9fe8096e-2cac-415d-9222-f6cf2ecb314b",object1.GetXml(),"","")

' Create an Object to be added to the Signature.
Dim object2 As New ChilkatXml
object2.Tag = "QualifyingProperties"
success = object2.AddAttribute("Target","#S9fe8096e-2cac-415d-9222-f6cf2ecb314b")
success = object2.AddAttribute("Id","QPS9fe8096e-2cac-415d-9222-f6cf2ecb314b")
success = object2.UpdateAttrAt("SignedProperties",1,"Id","XS9fe8096e-2cac-415d-9222-f6cf2ecb314b")
object2.UpdateChildContent "SignedProperties|SignedSignatureProperties|SigningTime","TO BE GENERATED BY CHILKAT"
success = object2.UpdateAttrAt("SignedProperties|SignedSignatureProperties|SigningCertificateV2|Cert|CertDigest|ds:DigestMethod",1,"Algorithm","http://www.w3.org/2001/04/xmlenc#sha256")
object2.UpdateChildContent "SignedProperties|SignedSignatureProperties|SigningCertificateV2|Cert|CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT"
object2.UpdateChildContent "SignedProperties|SignedSignatureProperties|SigningCertificateV2|Cert|IssuerSerialV2","TO BE GENERATED BY CHILKAT"
object2.UpdateChildContent "SignedProperties|SignedSignatureProperties|SignaturePolicyIdentifier|SignaturePolicyImplied",""
object2.UpdateChildContent "SignedProperties|SignedSignatureProperties|SignerRoleV2|ClaimedRoles|ClaimedRole","tesztel"

' Here we have the EncapsulatedTimestamp found in the unsigned signature properties.
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|SignatureTimeStamp",1,"Id","T72cb4961-4326-4319-857a-7cf55e7ef899")
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|SignatureTimeStamp|ds:CanonicalizationMethod",1,"Algorithm","http://www.w3.org/2001/10/xml-exc-c14n#")
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|SignatureTimeStamp|EncapsulatedTimeStamp",1,"Id","ET72cb4961-4326-4319-857a-7cf55e7ef899")
object2.UpdateChildContent "UnsignedProperties|UnsignedSignatureProperties|SignatureTimeStamp|EncapsulatedTimeStamp","TO BE GENERATED BY CHILKAT"
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|TimeStampValidationData",1,"xmlns","http://uri.etsi.org/01903/v1.4.1#")
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|CertificateValues",1,"Id","CV18c7702d-d45b-44bc-853a-a720f41053cd")
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|CertificateValues|EncapsulatedX509Certificate",1,"Id","EC42db04c8-1422-407b-8c42-189353a55268")
object2.UpdateChildContent "UnsignedProperties|UnsignedSignatureProperties|CertificateValues|EncapsulatedX509Certificate","BASE64_CONTENT"
success = object2.UpdateAttrAt("UnsignedProperties|UnsignedSignatureProperties|CertificateValues|EncapsulatedX509Certificate[1]",1,"Id","EC04728b44-a32c-46c1-b9bb-85b1f6b3c7d3")
object2.UpdateChildContent "UnsignedProperties|UnsignedSignatureProperties|CertificateValues|EncapsulatedX509Certificate[1]","BASE64_CONTENT"

success = gen.AddObject("O2S9fe8096e-2cac-415d-9222-f6cf2ecb314b",object2.GetXml(),"","")

' -------- Reference 1 --------
success = gen.AddSameDocRef("Object0","sha256","EXCL_C14N","","")
success = gen.SetRefIdAttr("Object0","Re1f816c4-7898-4544-9b41-f4156dc0c528")

' -------- Reference 2 --------
success = gen.AddObjectRef("PS9fe8096e-2cac-415d-9222-f6cf2ecb314b","sha256","EXCL_C14N","","")
success = gen.SetRefIdAttr("PS9fe8096e-2cac-415d-9222-f6cf2ecb314b","Ra873b616-e568-4c38-ae94-27fbff67cc43")

' -------- Reference 3 --------
success = gen.AddSameDocRef("PObject0","sha256","EXCL_C14N","","")
success = gen.SetRefIdAttr("PObject0","Ra5d85948-5d6a-4914-8c32-242f5d6d9e81")

' -------- Reference 4 --------
success = gen.AddObjectRef("XS9fe8096e-2cac-415d-9222-f6cf2ecb314b","sha256","EXCL_C14N","","http://uri.etsi.org/01903#SignedProperties")
success = gen.SetRefIdAttr("XS9fe8096e-2cac-415d-9222-f6cf2ecb314b","Ra7412a43-dc05-4e0a-ac84-e9a070214757")

' Provide a certificate + private key. (PFX password is test123)
Dim cert As New ChilkatCert
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> 1) Then
    Debug.Print cert.LastErrorText
    Exit Sub
End If

success = gen.SetX509Cert(cert,1)

gen.KeyInfoType = "X509Data"
gen.X509Type = "Certificate"

' -------------------------------------------------------------------------------------------
' To have the EncapsulatedTimeStamp automatically added, we only need to do 2 things.
' 1) Add the <xades:EncapsulatedTimeStamp Encoding="http://uri.etsi.org/01903/v1.2.2#DER">TO BE GENERATED BY CHILKAT</xades:EncapsulatedTimeStamp>
'    to the unsigned properties.
' 2) Specify the TSA URL (Timestamping Authority URL).
'    Here we specify the TSA URL:
' -------------------------------------------------------------------------------------------

Dim jsonTsa As New ChilkatJsonObject
success = jsonTsa.UpdateString("timestampToken.tsaUrl","http://timestamp.digicert.com")
success = jsonTsa.UpdateBool("timestampToken.requestTsaCert",1)
success = gen.SetTsa(jsonTsa)

' Load XML to be signed...
Dim sbXml As New ChilkatStringBuilder
success = xmlToSign.GetXmlSb(sbXml)

gen.Behaviors = "IndentedSignature,OmitAlreadyDefinedSigNamespace"

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    Debug.Print gen.LastErrorText
    Exit Sub
End If

' -----------------------------------------------

' Save the signed XML to a file.
success = sbXml.WriteFile("c:/temp/qa_output/signedXml.xml","utf-8",0)

Debug.Print sbXml.GetAsString()

' ----------------------------------------
' Verify the signatures we just produced...
Dim verifier As New ChilkatXmlDSig
success = verifier.LoadSignatureSb(sbXml)
If (success <> 1) Then
    Debug.Print verifier.LastErrorText
    Exit Sub
End If

Dim numSigs As Long
numSigs = verifier.NumSignatures
Dim verifyIdx As Long
verifyIdx = 0
Do While verifyIdx < numSigs
    verifier.Selector = verifyIdx
    Dim verified As Long
    verified = verifier.VerifySignature(1)
    If (verified <> 1) Then
        Debug.Print verifier.LastErrorText
        Exit Sub
    End If

    verifyIdx = verifyIdx + 1
Loop
Debug.Print "All signatures were successfully verified."

 

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