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 8883485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:49:25+00:00 2026-06-14T20:49:25+00:00

I’m trying to generate a CSR in iOS. Since apparently the Apple security framework

  • 0

I’m trying to generate a CSR in iOS. Since apparently the Apple security framework for iOS doesn’t include methods for CSR generation I had to compile the OpenSSL source code for my project.

Now I want to know how to use these methods with the keys I’ve generated in the Keychain previously. That is, I need to convert SecKeyRef type into OpenSSL types like EVP_PKEY. That will allow me to call the OpenSSL method X509_REQ_set_pubkey.

Does anyone know a way to achieve this?

  • 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-14T20:49:26+00:00Added an answer on June 14, 2026 at 8:49 pm

    Found the solution myself.

    First of all you need to extract the key from the Keychain as NSData.

    - (NSData *) getKeyDataWithIdentifier:(NSString *) identifier
    {
        NSData * keyBits = nil;
        NSMutableDictionary * keyQuery = [[NSMutableDictionary alloc] init];
        NSData * encodedId = [identifier dataUsingEncoding:NSUTF8StringEncoding];
        [keyQuery setObject:encodedId forKey:kSecAttrApplicationTag];
        [keyQuery setObject:kSecClassKey forKey:kSecClass];
        [keyQuery setObject:[NSNumber numberWithBool:YES] forKey:kSecReturnData];
        [keyQuery setObject:kSecAttrKeyTypeRSA forKey:kSecAttrKeyType];
    
        OSStatus sanityCheck = SecItemCopyMatching((CFDictionaryRef)keyQuery, (CFTypeRef *)&keyBits);
    
        if (sanityCheck != noErr) {
            NSLog(@"Error: %ld", sanityCheck);
        }
    
        return keyBits;
    }
    

    Now we need to cast this data as unsigned char and give it to the method d2i_RSAPublicKey

    - (void) generateCSR:(NSData *) keyData
    {
        X509_REQ *req = NULL;
        X509_NAME *name= NULL;
        EVP_PKEY *key;
        const unsigned char * bits = (unsigned char *) [keyData bytes];
        int length = [keyData length];
    
        if ((req=X509_REQ_new()) == NULL) {
            NSLog(@"big error");
            return;
        }
    
        RSA * rsa = NULL;
        key=EVP_PKEY_new();
        d2i_RSAPublicKey(&rsa, &bits, length);
        EVP_PKEY_assign_RSA(key,rsa);
        name = X509_REQ_get_subject_name(req);
        X509_REQ_set_pubkey(req, key);
    
        /* This function creates and adds the entry, working out the
         * correct string type and performing checks on its length.
         * Normally we'd check the return value for errors...
                 */
        X509_NAME_add_entry_by_txt(name,"CN",
                                   MBSTRING_ASC, "My certificate request", -1, -1, 0);
        X509_REQ_print_fp(stdout, req);
    }
    

    That generates a simple CSR in OpenSSL (not signed) with a public key and a common name and prints it to the standard out.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.