Sample code for 30+ languages & platforms
Objective-C

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Objective-C Downloads

Objective-C
#import <CkoCertStore.h>
#import <NSString.h>
#import <CkoJsonObject.h>
#import <CkoCert.h>

BOOL success = NO;

CkoCertStore *certStore = [[CkoCertStore alloc] init];

// This example will search the certs on connected USB tokens and smartcards.
NSString *argNotUsed = @"";
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.");
}