(Objective-C) Find Certificate by Serial Number
Demonstrates how to find a certificate having the specified hexadecimal serial number.
Note: Requires Chilkat v10.1.2 or later.
#import <CkoCertStore.h>
#import <NSString.h>
#import <CkoJsonObject.h>
#import <CkoCert.h>
CkoCertStore *certStore = [[CkoCertStore alloc] init];
// This example will search the certs on connected USB tokens and smartcards.
NSString *argNotUsed = @"";
BOOL success = [certStore OpenSmartcard: argNotUsed];
if (success == NO) {
NSLog(@"%@",certStore.LastErrorText);
return;
}
// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
NSString *hexSerial = @"48FC93B46055948D36A7C98A89D69416";
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"serial" value: hexSerial];
CkoCert *cert = [[CkoCert alloc] init];
success = [certStore FindCert: json cert: cert];
if (success == YES) {
// Show the serial number and subject CN
NSLog(@"%@%@%@%@",@"Found: ",cert.SerialNumber,@", ",cert.SubjectCN);
}
else {
NSLog(@"%@",@"Not found.");
}
|