Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

VBScript Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
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)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(VBScript) Create Enveloping XML Digital Signature

This example creates an enveloping digital signature.
An enveloping signature is where the signed data is contained within the Signature within an Object element.
This example signs non-XML text data where the XML signature constitutes the entire output.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

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

'  Let's use the ECDSA private key at https://www.chilkatsoft.com/exampleData/secp256r1-key.zip
'  for signing.
set http = CreateObject("Chilkat_9_5_0.Http")
set zipFile = CreateObject("Chilkat_9_5_0.BinData")
keyUrl = "https://www.chilkatsoft.com/exampleData/secp256r1-key.zip"

success = http.QuickGetBd(keyUrl,zipFile)
If (success <> 1) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

set zip = CreateObject("Chilkat_9_5_0.Zip")
success = zip.OpenBd(zipFile)
' zipEntry is a Chilkat_9_5_0.ZipEntry
Set zipEntry = zip.FirstMatchingEntry("*.pem")
set ecKey = CreateObject("Chilkat_9_5_0.PrivateKey")
success = ecKey.LoadPem(zipEntry.UnzipToString(0,"utf-8"))
If (success <> 1) Then
    outFile.WriteLine(ecKey.LastErrorText)

    WScript.Quit
End If

'  ----------------------------------------------------------------------------
set gen = CreateObject("Chilkat_9_5_0.XmlDSigGen")

'  Provide the ECDSA key to the XML Digital Signature generator
success = gen.SetPrivateKey(ecKey)

'  Add an enveloped reference to the content to be signed.
set sbContent = CreateObject("Chilkat_9_5_0.StringBuilder")
success = sbContent.Append("This is the content that is signed.")
success = gen.AddEnvelopedRef("abc123",sbContent,"sha256","C14N","")

'  Generate the XML digital signature.
'  Notice that in other examples, the sbXml passed to CreateXmlDSigSb
'  already contains XML, and the XML signature is inserted at the location
'  specified by the SigLocation property.  In this case, both SigLocation
'  and sbXml are empty.  The result is that sbXml will contain just the Signature.
set sbXml = CreateObject("Chilkat_9_5_0.StringBuilder")
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    outFile.WriteLine(gen.LastErrorText)
    WScript.Quit
End If

'  Examine the enveloped signature, where the data is contained within the XML Signature
outFile.WriteLine(sbXml.GetAsString())

'  The Signature returned is compact and in a single line, like this:
'  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"/><ds:Reference URI="#abc123"><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>tEVrbXXjeTXjF3tIojul4/sgeEGN49E1dxr/GMs8GNE=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>/pILUshwrzgdGc4bPgp85TDfbUiM9pn8EIPNRVWKuoVEtPsv4XRthUrv9aDDvajmyl2okLwTakANgtaxO1ULMw==</ds:SignatureValue><ds:KeyInfo><ds:KeyValue><ds:ECKeyValue xmlns="http://www.w3.org/2009/xmldsig11#"><ds:NamedCurve URI="urn:oid:1.2.840.10045.3.1.7" /><ds:PublicKey>BOVKaiLPKEDChhkA64UEBOXTv/VFHnhrUPN+bXqCvEl7rroAYpH5tKzbiGTtMSlp4JO9Pxg44zeX7EoWDvOrpD0=</ds:PublicKey></ds:ECKeyValue></ds:KeyValue></ds:KeyInfo><ds:Object Id="abc123">This is the content that is signed.</ds:Object></ds:Signature>

'  XML pretty-printed, the signature is as follows, but pretty-printing introductes whitespace that breaks the signature..

'  <?xml version="1.0" encoding="utf-8" ?>
'  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
'      <ds:SignedInfo>
'          <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
'          <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256" />
'          <ds:Reference URI="#abc123">
'              <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
'              <ds:DigestValue>tEVrbXXjeTXjF3tIojul4/sgeEGN49E1dxr/GMs8GNE=</ds:DigestValue>
'          </ds:Reference>
'      </ds:SignedInfo>
'      <ds:SignatureValue>/pILUshwrzgdGc4bPgp85TDfbUiM9pn8EIPNRVWKuoVEtPsv4XRthUrv9aDDvajmyl2okLwTakANgtaxO1ULMw==</ds:SignatureValue>
'      <ds:KeyInfo>
'          <ds:KeyValue>
'              <ds:ECKeyValue xmlns="http://www.w3.org/2009/xmldsig11#">
'                  <ds:NamedCurve URI="urn:oid:1.2.840.10045.3.1.7" />
'                  <ds:PublicKey>BOVKaiLPKEDChhkA64UEBOXTv/VFHnhrUPN+bXqCvEl7rroAYpH5tKzbiGTtMSlp4JO9Pxg44zeX7EoWDvOrpD0=</ds:PublicKey>
'              </ds:ECKeyValue>
'          </ds:KeyValue>
'      </ds:KeyInfo>
'      <ds:Object Id="abc123">This is the content that is signed.</ds:Object>
'  </ds:Signature>
' 

outFile.Close

 

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