Sample code for 30+ languages & platforms
Objective-C

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Objective-C Downloads

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

BOOL success = NO;

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

NSString *pfxPath = @"/Users/chilkat/testData/pfx/chilkat_ssl.pfx";
NSString *pfxPassword = @"test";
success = [certStore LoadPfxFile: pfxPath password: pfxPassword];
if (success != YES) {
    NSLog(@"%@",certStore.LastErrorText);
    return;
}

int numCerts = [certStore.NumCertificates intValue];

NSLog(@"%@%d%@",@"PFX contains ",numCerts,@" certificates");

CkoCert *cert = [[CkoCert alloc] init];
int i = 0;
while (i < numCerts) {
    [certStore GetCert: [NSNumber numberWithInt: i] cert: cert];

    NSLog(@"%d%@%@",i,@": (Common Name) ",cert.SubjectCN);
    NSLog(@"%d%@%@",i,@": (Serial Number) ",cert.SerialNumber);
    NSLog(@"%d%@%@",i,@": (Distinguished Name) ",cert.SubjectDN);

    i = i + 1;
}