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

PowerBuilder Examples

Web API Categories

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

 

 

 

(PowerBuilder) RFC3161 Timestamp Client - Fetch from Timestamp Authority (TSA) and Verify

Sends an RFC 3161 timestamp request to a TSA (Timestamp Authority) server and validates the timestamp token response.

Note: This example requires Chilkat v9.5.0.75 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Crypt
string ls_Base64Hash
oleobject loo_Http
oleobject loo_RequestToken
string ls_OptionalPolicyOid
integer li_AddNonce
integer li_RequestTsaCert
string ls_TsaUrl
oleobject loo_Resp
oleobject loo_TimestampReply
oleobject loo_TsaCert
integer li_PkiStatus

//  Note: Requires Chilkat v9.5.0.75 or greater.

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

//  First sha-256 hash the data that is to be timestamped.
//  In this example, the data is the string "Hello World"

loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2")
if li_rc < 0 then
    destroy loo_Crypt
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Crypt.HashAlgorithm = "sha256"
loo_Crypt.EncodingMode = "base64"
ls_Base64Hash = loo_Crypt.HashStringENC("Hello World")

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")

loo_RequestToken = create oleobject
li_rc = loo_RequestToken.ConnectToNewObject("Chilkat_9_5_0.BinData")

ls_OptionalPolicyOid = ""
li_AddNonce = 0
li_RequestTsaCert = 1

//  Create a time-stamp request token
li_Success = loo_Http.CreateTimestampRequest("sha256",ls_Base64Hash,ls_OptionalPolicyOid,li_AddNonce,li_RequestTsaCert,loo_RequestToken)
if li_Success <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Crypt
    destroy loo_Http
    destroy loo_RequestToken
    return
end if

//  Send the time-stamp request token to the TSA.
//  This is the equivalent of the following CURL command:
//  curl -H "Content-Type: application/timestamp-query" --data-binary '@file.tsq' https://freetsa.org/tsr > file.tsr
ls_TsaUrl = "https://freetsa.org/tsr"
loo_Resp = loo_Http.PBinaryBd("POST",ls_TsaUrl,loo_RequestToken,"application/timestamp-query",0,0)
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Crypt
    destroy loo_Http
    destroy loo_RequestToken
    return
end if

//  Get the timestamp reply from the HTTP response object.
loo_TimestampReply = create oleobject
li_rc = loo_TimestampReply.ConnectToNewObject("Chilkat_9_5_0.BinData")

loo_Resp.GetBodyBd(loo_TimestampReply)
destroy loo_Resp

//  Show the base64 encoded timestamp reply.
Write-Debug loo_TimestampReply.GetEncoded("base64")

//  Let's verify the timestamp reply against the TSA's cert, which we've previously downloaded.
//  See https://freetsa.org/index_en.php
loo_TsaCert = create oleobject
li_rc = loo_TsaCert.ConnectToNewObject("Chilkat_9_5_0.Cert")

li_Success = loo_TsaCert.LoadFromFile("qa_data/certs/freetsa.org.cer")
if li_Success <> 1 then
    Write-Debug loo_TsaCert.LastErrorText
    destroy loo_Crypt
    destroy loo_Http
    destroy loo_RequestToken
    destroy loo_TimestampReply
    destroy loo_TsaCert
    return
end if

//  The VerifyTimestampReply method will return one of the following values:
//  -1:  The timestampReply does not contain a valid timestamp reply.
//  -2: The  timestampReply is a valid timestamp reply, but failed verification using the public key of the tsaCert.
//  0:  Granted and verified.
//  1: Granted and verified, with mods (see RFC 3161)
//  2: Rejected.
//  3: Waiting.
//  4: Revocation Warning
//  5: Revocation Notification
li_PkiStatus = loo_Http.VerifyTimestampReply(loo_TimestampReply,loo_TsaCert)
if li_PkiStatus < 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Crypt
    destroy loo_Http
    destroy loo_RequestToken
    destroy loo_TimestampReply
    destroy loo_TsaCert
    return
end if

Write-Debug "pkiStatus = " + string(li_PkiStatus)


destroy loo_Crypt
destroy loo_Http
destroy loo_RequestToken
destroy loo_TimestampReply
destroy loo_TsaCert

 

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