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

PHP Extension 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

 

 

 

(PHP Extension) 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 PHP Downloads

PHP Extension for Windows, Linux, MAC OS X,
Alpine Linux, Solaris, OpenBSD, FreeBSD,
and Linux armhf/aarch64

<?php

// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");

//  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"

$crypt = new CkCrypt2();
$crypt->put_HashAlgorithm('sha256');
$crypt->put_EncodingMode('base64');
$base64Hash = $crypt->hashStringENC('Hello World');

$http = new CkHttp();

$requestToken = new CkBinData();
$optionalPolicyOid = '';
$addNonce = false;
$requestTsaCert = true;

//  Create a time-stamp request token
$success = $http->CreateTimestampRequest('sha256',$base64Hash,$optionalPolicyOid,$addNonce,$requestTsaCert,$requestToken);
if ($success != true) {
    print $http->lastErrorText() . "\n";
    exit;
}

//  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
$tsaUrl = 'https://freetsa.org/tsr';
// resp is a CkHttpResponse
$resp = $http->PBinaryBd('POST',$tsaUrl,$requestToken,'application/timestamp-query',false,false);
if ($http->get_LastMethodSuccess() != true) {
    print $http->lastErrorText() . "\n";
    exit;
}

//  Get the timestamp reply from the HTTP response object.
$timestampReply = new CkBinData();
$resp->GetBodyBd($timestampReply);

//  Show the base64 encoded timestamp reply.
print $timestampReply->getEncoded('base64') . "\n";

//  Let's verify the timestamp reply against the TSA's cert, which we've previously downloaded.
//  See https://freetsa.org/index_en.php
$tsaCert = new CkCert();
$success = $tsaCert->LoadFromFile('qa_data/certs/freetsa.org.cer');
if ($success != true) {
    print $tsaCert->lastErrorText() . "\n";
    exit;
}

//  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
$pkiStatus = $http->VerifyTimestampReply($timestampReply,$tsaCert);
if ($pkiStatus < 0) {
    print $http->lastErrorText() . "\n";
    exit;
}

print 'pkiStatus = ' . $pkiStatus . "\n";

?>

 

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