Sample code for 30+ languages & platforms
Objective-C

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

Chilkat Objective-C Downloads

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

BOOL success = NO;

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

//  This only loads the contents of the PFX file into the certStore object.
//  It is not importing the PFX into the Windows certificate stores.
NSString *pfxPassword = @"badssl.com";
success = [certStore LoadPfxFile: @"qa_data/pfx/badssl.com-client.p12" password: pfxPassword];
if (success == NO) {
    NSLog(@"%@",certStore.LastErrorText);
    return;
}

//  Examine each certificate (loaded from the PFX) in this certStore object
CkoCert *cert = [[CkoCert alloc] init];
int numCerts = [certStore.NumCertificates intValue];
int i = 0;
while (i < numCerts) {
    [certStore GetCert: [NSNumber numberWithInt: i] cert: cert];
    NSLog(@"%@%d%@%@",@"hasPrivateKey=",[cert HasPrivateKey],@", ",cert.SubjectCN);
    i = i + 1;
}