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

Objective-C 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 Encryption
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

 

 

 

(Objective-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 Objective-C Library Downloads

MAC OS X (Cocoa) Libs

iOS Libs

#import <CkoCrypt2.h>
#import <NSString.h>
#import <CkoHttp.h>
#import <CkoBinData.h>
#import <CkoHttpResponse.h>
#import <CkoCert.h>

//  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;
CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init];
crypt.HashAlgorithm = @"sha256";
crypt.EncodingMode = @"base64";
NSString *base64Hash = [crypt HashStringENC: @"Hello World"];

CkoHttp *http = [[CkoHttp alloc] init];

CkoBinData *requestToken = [[CkoBinData alloc] init];
NSString *optionalPolicyOid = @"";
BOOL addNonce = NO;
BOOL requestTsaCert = YES;

//  Create a time-stamp request token
success = [http CreateTimestampRequest: @"sha256" hashVal: base64Hash reqPolicyOid: optionalPolicyOid addNonce: addNonce reqTsaCert: requestTsaCert tmestampToken: requestToken];
if (success != YES) {
    NSLog(@"%@",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
NSString *tsaUrl = @"https://freetsa.org/tsr";
CkoHttpResponse *resp = [http PBinaryBd: @"POST" url: tsaUrl data: requestToken contentType: @"application/timestamp-query" md5: NO gzip: NO];
if (http.LastMethodSuccess != YES) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

//  Get the timestamp reply from the HTTP response object.
CkoBinData *timestampReply = [[CkoBinData alloc] init];
[resp GetBodyBd: timestampReply];

//  Show the base64 encoded timestamp reply.
NSLog(@"%@",[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
CkoCert *tsaCert = [[CkoCert alloc] init];
success = [tsaCert LoadFromFile: @"qa_data/certs/freetsa.org.cer"];
if (success != YES) {
    NSLog(@"%@",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: tsaCert] intValue];
if (pkiStatus < 0) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%@%d",@"pkiStatus = ",pkiStatus);
 

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