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

VBScript 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

 

 

 

(VBScript) XAdES using TSA Requiring Client Certificate

See more XML Digital Signatures Examples

Demonstrates how to create an XMLDSig (XAdES) signed document which includes an EncapsulatedTimestamp using a TSA (TimeStamp Authority) server requiring client certificate authentication. One such TSA is https://www3.postsignum.cz/TSS/TSS_crt/

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

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

success = 1

' Load the XML to be signed.  For example, the XML to be signed might contain something like this:

' <?xml version="1.0" encoding="utf-8"?>
' <TransakcniLogSystemu xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://nsess.public.cz/erms_trans/v_01_01" Id="Signature1">
'   <TransLogInfo>
'     <Identifikator>XYZ ABC</Identifikator>
'     <DatumVzniku>2022-12-20T14:39:02.3625922+01:00</DatumVzniku>
'     <DatumCasOd>2022-12-20T14:26:26.88</DatumCasOd>
'     <DatumCasDo>2022-12-20T14:39:02.287</DatumCasDo>
'     <Software>XYZ</Software>
'     <VerzeSoftware>2.0.19.32</VerzeSoftware>
'   </TransLogInfo>
'   <Udalosti>
'     <Udalost>
'       <Poradi>1</Poradi>
' ...

' Load the XML to be signed from a file.
' (XML can be loaded from other source, such as a string variable.)
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder")
set sbXml = CreateObject("Chilkat.StringBuilder")
success = sbXml.LoadFile("xmlToSign.xml","utf-8")

' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.XmlDSigGen")
set gen = CreateObject("Chilkat.XmlDSigGen")

gen.SigLocation = "TransakcniLogSystemu"
gen.SigLocationMod = 0
gen.SigId = "SignatureID-Signature1"
gen.SigNamespacePrefix = "ds"
gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
gen.SignedInfoCanonAlg = "C14N"
gen.SignedInfoDigestMethod = "sha256"

' Set the KeyInfoId before adding references..
gen.KeyInfoId = "KeyInfoId-Signature-Signature1"

' Create an Object to be added to the Signature.

' Note: Chilkat will automatically fill in the values marked as "TO BE GENERATED BY CHILKAT" at the time of signing.
' The EncapsulatedTimestamp will be automatically generated.

' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Xml")
set object1 = CreateObject("Chilkat.Xml")
object1.Tag = "xades:QualifyingProperties"
success = object1.AddAttribute("Target","#Signature1")

success = object1.UpdateAttrAt("xades:SignedProperties",1,"Id","SignedProperties-Signature-Signature1")
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime","TO BE GENERATED BY CHILKAT"
success = object1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod",1,"Algorithm","http://www.w3.org/2001/04/xmlenc#sha256")
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT"
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName","TO BE GENERATED BY CHILKAT"
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber","TO BE GENERATED BY CHILKAT"

' The EncapsulatedTimestamp will be included in the unsigned properties.
success = object1.UpdateAttrAt("xades:UnsignedProperties|xades:UnsignedSignatureProperties|xades:SignatureTimeStamp",1,"Id","signature-timestamp-5561-8212-3316-5191")
success = object1.UpdateAttrAt("xades:UnsignedProperties|xades:UnsignedSignatureProperties|xades:SignatureTimeStamp|ds:CanonicalizationMethod",1,"Algorithm","http://www.w3.org/2001/10/xml-exc-c14n#")
success = object1.UpdateAttrAt("xades:UnsignedProperties|xades:UnsignedSignatureProperties|xades:SignatureTimeStamp|xades:EncapsulatedTimeStamp",1,"Encoding","http://uri.etsi.org/01903/v1.2.2#DER")
object1.UpdateChildContent "xades:UnsignedProperties|xades:UnsignedSignatureProperties|xades:SignatureTimeStamp|xades:EncapsulatedTimeStamp","TO BE GENERATED BY CHILKAT"

success = gen.AddObject("XadesObjectId-Signature1",object1.GetXml(),"","")

' -------- Reference 1 --------
success = gen.AddObjectRef("SignedProperties-Signature-Signature1","sha256","EXCL_C14N","","http://uri.etsi.org/01903#SignedProperties")

' -------- Reference 2 --------
success = gen.AddSameDocRef("KeyInfoId-Signature-Signature1","sha256","EXCL_C14N","","")
success = gen.SetRefIdAttr("KeyInfoId-Signature-Signature1","ReferenceKeyInfo")

' -------- Reference 3 --------
success = gen.AddSameDocRef("","sha256","EXCL_C14N","","")
success = gen.SetRefIdAttr("","Reference-Signature1")

' Provide a certificate + private key. (PFX password is test123)
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Cert")
set cert = CreateObject("Chilkat.Cert")
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> 1) Then
    outFile.WriteLine(cert.LastErrorText)
    WScript.Quit
End If

success = gen.SetX509Cert(cert,1)

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

gen.Behaviors = "IndentedSignature"

' -------------------------------------------------------------------------------------------
' To have the EncapsulatedTimeStamp automatically added... 
' 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.  (This was accomplished in the above code.)
' 2) Specify the TSA URL (Timestamping Authority URL).
'    Here we specify the TSA URL:
' -------------------------------------------------------------------------------------------

' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.JsonObject")
set jsonTsa = CreateObject("Chilkat.JsonObject")
success = jsonTsa.UpdateString("timestampToken.tsaUrl","https://www3.postsignum.cz/TSS/TSS_crt/")
success = jsonTsa.UpdateBool("timestampToken.requestTsaCert",1)
success = gen.SetTsa(jsonTsa)

' -------------------------------------------------------------------------------------------
' In this case, the TSA requires client certificate authentication.
' To provide your client certificate, the application will instantiate a Chilkat HTTP object,
' then set it up with a SSL/TLS client certificate, and then tell the XmlDSigGen object
' to use the HTTP object for connections to the TSA server.
' -------------------------------------------------------------------------------------------
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.Http")
set http = CreateObject("Chilkat.Http")
success = http.SetSslClientCertPfx("/home/bob/pfxFiles/myClientSideCertWithPrivateKey.pfx","pfxPassword")
If (success <> 1) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

' Tell the XmlDSigGen object to use the above HTTP object for TSA communications.
gen.SetHttpObj http

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    outFile.WriteLine(gen.LastErrorText)
    WScript.Quit
End If

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

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

outFile.WriteLine(sbXml.GetAsString())

outFile.Close

 

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