Created certificate using SecCertificateCreateWithData on iOS

I want to create a certificate programmatically in an iOS application. The closest API I could find is SecCertificateCreateWithData , which requires DER encoded binary input.

Given that I have all the data needed to be used as runtime objects, how can I build DER binary encoded input data?

+4
source share
2 answers

Here's how it can be doen:

NSString* certPath = [[NSBundle mainBundle] pathForResource:@"myCertificate" ofType:@"cer"]; NSData* certData = [NSData dataWithContentsOfFile:certPath]; SecCertificateRef cert; if( [certData length] ) { cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certData); if( cert != NULL ) { CFStringRef certSummary = SecCertificateCopySubjectSummary(cert); NSString* summaryString = [[NSString alloc] initWithString:(__bridge NSString*)certSummary]; NSLog(@"CERT SUMMARY: %@", summaryString); CFRelease(certSummary); } else { NSLog(@" *** ERROR *** trying to create the SSL certificate from data located at %@, but failed", certPath); } } // play with cert here 

myCertificate.cer should be in your application. I am creating a cer file using openssl. If you plan to use this in your iOS app, make sure your certificate contains the necessary extensions, check here . Even though the answer is -1, it helped me achieve this.

+5
source

Take a look at SecKeyGeneratePair. I think this is what you are looking for.

-1
source

Source: https://habr.com/ru/post/1401345/


All Articles