Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7756091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:43:50+00:00 2026-06-01T12:43:50+00:00

I’ve solved my previos problem of converting XML RSA private key to PEM file,

  • 0

I’ve solved my previos problem of converting XML RSA private key to PEM file, but I run into another problem that I get null data when importing P12 private key. Following is my steps:

  1. Convert PEM file to P12 file

    openssl> pkcs12 -export -in rsa.pem -inkey rsa.pem -out rsa.p12 -nocerts
    
  2. Read P12 file to iOS project

    NSString *path = [[NSBundle bundleForClass:[self class]]    
                        pathForResource:@"MyPrivateKey" ofType:@"p12"];
    NSData *p12data = [NSData dataWithContentsOfFile:path];
    if (![self getPrivateKeyRef]) 
        RSAPrivateKey = getPrivateKeywithRawKey(p12data);
    
  3. Import P12 Private Key

    SecKeyRef getPrivateKeywithRawKey(NSData *pfxkeydata)
    { 
        NSMutableDictionary * options = [[[NSMutableDictionary alloc] init] autorelease];
    
        // Set the public key query dictionary
        //change to your .pfx  password here 
        [options setObject:@"MyPassword" forKey:(id)kSecImportExportPassphrase];
    
        CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
    
        OSStatus securityError = SecPKCS12Import((CFDataRef) pfxkeydata,
                                                 (CFDictionaryRef)options, &items);
    
        CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0);
        SecIdentityRef identityApp =
        (SecIdentityRef)CFDictionaryGetValue(identityDict,
                                             kSecImportItemIdentity);
        //NSLog(@"%@", securityError);
    
        assert(securityError == noErr);
        SecKeyRef privateKeyRef;
        SecIdentityCopyPrivateKey(identityApp, &privateKeyRef);
    
        return privateKeyRef;
    
    }
    

Thought there was no err(OSStatus value is 0), but the items array didn’t get any identity data. I am wondering if i didn’t get the correct p12 file format due to wrong OpenSSl usage. Has anyone successfully import p12 file? I’ve stuck in this problem for a couple of days, please give me advices if you got clues, thanks!

Hubert

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:43:51+00:00Added an answer on June 1, 2026 at 12:43 pm

    I got some tips from the internet, and following is the steps to get iOS acceptable p12 key and certification file:

    1. convert XML to PEM
      Shell> compile XMLSpec2PEM.java
      Shell> XMLSpec2PEM rsa.xml
      save the output result to rsa.pem
      (borrow from here)

    2. convert PEM to RSA Private Key
      OpenSSL> rsa -in rsa.pem -out rsaPrivate.key

    3. Generate a certification request
      OpenSSL> req -new -key rsaPrivate.key -out rsaCertReq.crt
      (input some basic certification data)

    4. Sign certification of the request
      OpenSSL> x509 -req -days 3650 -in rsaCertReq.crt -signkey rsaPrivate.key -out rsaCert.crt

    5. Convert the certification file format to DER (iOS acceptable format)
      OpenSSL> x509 -outform der -in rsaCert.crt -out rsaCert.der

    6. Generate PKCS12 Private key(iOS acceptable format)
      OpenSSL> pkcs12 -export -out rsaPrivate.pfx -inkey rsaPrivate.key -in rsaCert.crt

    No further steps, files generated in step 5 and 6 now can be used in iOS!

    reference of OpenSSL instructions:
    http://blogs.yaclife.com/?tag=ios%E3%80%80seckeyref%E3%80%80raw%E3%80%80key%E3%80%80rsa%E3%80%803des

    http://devsec.org/info/ssl-cert.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am currently running into a problem where an element is coming back from
I'm parsing an XML file, the creators of it stuck in a bunch social
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.