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

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

 

 

 

(PowerBuilder) Combine Timestamp Reply and Content File into a TimeStampData

Demonstrates how to combine a timestamp reply (RFC 3161) with a data file (any type of file) to create a TimeStampData structure (RFC 5544).

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_BdTsr
integer li_Success
oleobject loo_AsnTsr
oleobject loo_XmlTsr
oleobject loo_BdContent
oleobject loo_Xml
oleobject loo_XContext
oleobject loo_Tsd
string ls_TsdBase64

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

// Also see this example:
// Send a TimeStamp Request to a TimeStamp Authority and get the Response

// Load a timestamp reply file
loo_BdTsr = create oleobject
li_rc = loo_BdTsr.ConnectToNewObject("Chilkat_9_5_0.BinData")
if li_rc < 0 then
    destroy loo_BdTsr
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_BdTsr.LoadFile("qa_data/tsd/sample.tsr")
if li_Success <> 1 then
    Write-Debug "Failed to load timestamp reply file."
    destroy loo_BdTsr
    return
end if

// Load the tsr into an ASN.1 object.
loo_AsnTsr = create oleobject
li_rc = loo_AsnTsr.ConnectToNewObject("Chilkat_9_5_0.Asn")

li_Success = loo_AsnTsr.LoadEncoded(loo_BdTsr.GetEncoded("base64"),"base64")
if li_Success <> 1 then
    Write-Debug loo_AsnTsr.LastErrorText
    destroy loo_BdTsr
    destroy loo_AsnTsr
    return
end if

// Get the timestamp reply as XML.
loo_XmlTsr = create oleobject
li_rc = loo_XmlTsr.ConnectToNewObject("Chilkat_9_5_0.Xml")

loo_XmlTsr.LoadXml(loo_AsnTsr.AsnToXml())

// The timestamp reply XML begins like this:
// We'll want to remove the 1st "sequence" subtree.

//     <?xml version="1.0" encoding="utf-8"?>
//     <sequence>
//         <sequence>       <---- Remove this sub-tree.
//             <int>00</int>
//             <sequence>
//                 <utf8>Operation Okay</utf8>
//             </sequence>
//         </sequence>
//         <sequence>   
//             <oid>1.2.840.113549.1.7.2</oid>
//             <contextSpecific tag="0" constructed="1">
//             ...

// Remove the 1st sub-tree..
loo_XmlTsr.RemoveChildByIndex(0)

// In this example, the data file we're combining with the timestamp into a timestampData is a .p7m.
// However, it can be any type of file (text or binary), it doesn't matter..
loo_BdContent = create oleobject
li_rc = loo_BdContent.ConnectToNewObject("Chilkat_9_5_0.BinData")

li_Success = loo_BdContent.LoadFile("qa_data/tsd/sample.p7m")
if li_Success <> 1 then
    Write-Debug "Failed to load content file."
    destroy loo_BdTsr
    destroy loo_AsnTsr
    destroy loo_XmlTsr
    destroy loo_BdContent
    return
end if

// Begin building the TimeStampData.  
// We'll build as XML and then convert to ASN.1
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat_9_5_0.Xml")

loo_Xml.Tag = "sequence"
loo_Xml.UpdateChildContent("oid","1.2.840.113549.1.9.16.1.31")
loo_Xml.UpdateAttrAt("contextSpecific",1,"tag","0")
loo_Xml.UpdateAttrAt("contextSpecific",1,"constructed","1")
loo_Xml.UpdateChildContent("contextSpecific|sequence|int","01")
loo_Xml.UpdateChildContent("contextSpecific|sequence|octets",loo_BdContent.GetEncoded("base64"))
loo_Xml.UpdateAttrAt("contextSpecific|sequence|contextSpecific",1,"tag","0")
loo_Xml.UpdateAttrAt("contextSpecific|sequence|contextSpecific",1,"constructed","1")

loo_XContext = loo_Xml.GetChildWithTag("contextSpecific|sequence|contextSpecific")
loo_XContext.AddChildTree(loo_XmlTsr)
destroy loo_XContext

// Convert the XML to ASN.1
loo_Tsd = create oleobject
li_rc = loo_Tsd.ConnectToNewObject("Chilkat_9_5_0.Asn")

loo_Tsd.LoadAsnXml(loo_Xml.GetXml())

// Write the timestamped data to a file.
li_Success = loo_Tsd.WriteBinaryDer("qa_output/sample.tsd")

// Alternatively, get the tsd ASN.1 as base64..
ls_TsdBase64 = loo_Tsd.GetEncodedDer("base64_mime")
Write-Debug ls_TsdBase64


destroy loo_BdTsr
destroy loo_AsnTsr
destroy loo_XmlTsr
destroy loo_BdContent
destroy loo_Xml
destroy loo_Tsd

 

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