Sample code for 30+ languages & platforms
Objective-C

Apple Keychain - List Certificates

See more Apple Keychain Examples

Iterates over the certificates in the Apple Keychain.

Chilkat Objective-C Downloads

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

BOOL success = NO;

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

// On MacOS and iOS, the OpenCurrentUserStore method opens the Keychain.
// The argument passed to OpenCurrentUserStore is ignored.
success = [certStore OpenCurrentUserStore: NO];
if (success == NO) {
    NSLog(@"%@",certStore.LastErrorText);
    return;
}

int numCerts = [certStore.NumCertificates intValue];
NSLog(@"%@%d",@"numCerts = ",numCerts);

CkoCert *cert = [[CkoCert alloc] init];
int i = 0;
while (i < numCerts) {
    [certStore GetCert: [NSNumber numberWithInt: i] cert: cert];
    NSLog(@"%@",cert.SubjectDN);
    NSLog(@"%@",cert.SubjectCN);
    NSLog(@"%@",cert.SerialNumber);
    NSLog(@"%@",@"----");
    i = i + 1;
}

[certStore CloseCertStore];