Sample code for 30+ languages & platforms
Objective-C

Find Certificate by Subject CN (Common Name)

See more Cert Store Examples

Demonstrates how to find a certificate having the specified subject CN.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Objective-C Downloads

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

BOOL success = NO;

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

// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
BOOL readOnly = NO;
success = [certStore OpenCurrentUserStore: readOnly];
if (success == NO) {
    NSLog(@"%@",certStore.LastErrorText);
    return;
}

// Find the certificate having a Subject CN = "Example ABC".
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"CN" value: @"Example ABC"];

CkoCert *cert = [[CkoCert alloc] init];
success = [certStore FindCert: json cert: cert];
if (success == YES) {
    // Show the full distinguished name of the certificate.
    NSLog(@"%@%@",@"Found: ",cert.SubjectDN);
}
else {
    NSLog(@"%@",@"Not found.");
}