Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

C# Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
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
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(C#) 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 .NET Downloads

Chilkat .NET Assemblies

Chilkat for .NET Core

Chilkat for Mono

//  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"
bool success;
Chilkat.Crypt2 crypt = new Chilkat.Crypt2();
crypt.HashAlgorithm = "sha256";
crypt.EncodingMode = "base64";
string base64Hash = crypt.HashStringENC("Hello World");

Chilkat.Http http = new Chilkat.Http();

Chilkat.BinData requestToken = new Chilkat.BinData();
string optionalPolicyOid = "";
bool addNonce = false;
bool requestTsaCert = true;

//  Create a time-stamp request token
success = http.CreateTimestampRequest("sha256",base64Hash,optionalPolicyOid,addNonce,requestTsaCert,requestToken);
if (success != true) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

//  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
string tsaUrl = "https://freetsa.org/tsr";
Chilkat.HttpResponse resp = http.PBinaryBd("POST",tsaUrl,requestToken,"application/timestamp-query",false,false);
if (http.LastMethodSuccess != true) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

//  Get the timestamp reply from the HTTP response object.
Chilkat.BinData timestampReply = new Chilkat.BinData();
resp.GetBodyBd(timestampReply);

//  Show the base64 encoded timestamp reply.
Debug.WriteLine(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
Chilkat.Cert tsaCert = new Chilkat.Cert();
success = tsaCert.LoadFromFile("qa_data/certs/freetsa.org.cer");
if (success != true) {
    Debug.WriteLine(tsaCert.LastErrorText);
    return;
}

//  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
int pkiStatus = http.VerifyTimestampReply(timestampReply,tsaCert);
if (pkiStatus < 0) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Debug.WriteLine("pkiStatus = " + Convert.ToString(pkiStatus));

 

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