这是我使用的一种方法:
NSArray *paths = [[NSBundle mainBundle] pathsForResourcesOfType:@"p12" inDirectory:nil];
NSMutableArray *idents = [NSMutableArray array];
for (NSString *certPath in paths) {
CFDataRef certData = (CFDataRef)[[NSData alloc] initWithContentsOfFile:certPath];
const void *keys[] = {kSecImportExportPassphrase};
const void *values[] = {(CFStringRef)kPassword}; // kPassword should be your password
CFDictionaryRef optsDict = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL);
OSStatus status = -1;
CFArrayRef items = NULL;
status = SecPKCS12Import(certData, optsDict, &items);
if (status == 0) { // noErr or errSecSuccess
CFDictionaryRef item = CFArrayGetValueAtIndex(items, 0);
SecIdentityRef bundleIdent = (SecIdentityRef)CFDictionaryGetValue(item, kSecImportItemIdentity);
[idents addObject:(id)bundleIdent];
}
if (optsDict) CFRelease(optsDict);
if (items) CFRelease(items);
if (certData) CFRelease(certData);
}
瞧——你已经准备好了一切SecIdentityRefs
。idents
编辑:这是Apple 文档,它描述了如何做你想做的事。