Sample code for 30+ languages & platforms
Objective-C

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Objective-C Downloads

Objective-C
#import <CkoCertStore.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;
}

CkoCert *cert = [[CkoCert alloc] init];

int numCerts = [certStore.NumCertificates intValue];
int i = 0;

while ((i < numCerts)) {
    // Load the cert object with the Nth certificate.
    [certStore GetCert: [NSNumber numberWithInt: i] cert: cert];
    NSLog(@"%d%@%@",i,@": ",cert.SubjectCN);
    i = i + 1;
}