I have created a public key like this:
NSString *pkFilePath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"];
NSData *myCertData = [NSData dataWithContentsOfFile:pkFilePath];
SecCertificateRef cert = SecCertificateCreateWithData (kCFAllocatorDefault, (CFDataRef)myCertData);
CFArrayRef certs = CFArrayCreate(kCFAllocatorDefault, (const void **) &cert, 1, NULL);
SecTrustRef trust;
SecPolicyRef myPolicy = SecPolicyCreateBasicX509();
SecTrustCreateWithCertificates(certs, myPolicy, &trust);
SecTrustResultType trustResult;
SecTrustEvaluate(trust, &trustResult);
SecKeyRef pub_key_leaf = SecTrustCopyPublicKey(trust);
NSLog(@"%@",pub_key_leaf);
But how to create private key from file?
Here is some related code to create a private key but I am not getting how to create private key from this using my privatekey file.
I had the same problem, it turns out you need to use a p12 file to import the private key.
See my answer here https://stackoverflow.com/a/17295321/480467
AFAIK there is no easy way to create a SecPrivateKeyRef from NSData. If at all possible - combine your private & public file into a p12:
and then do
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: @"12345678", kSecImportExportPassphrase, nil];
In the cases where I had to deal with DER/PEM - I've found it easiest to link with openssl. And take it from there.
Dw.