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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:51:44+00:00 2026-05-27T20:51:44+00:00

I am trying to import RSA private keys into the keychain using my application.

  • 0

I am trying to import RSA private keys into the keychain using my application. The first time I import a key using SecKeychainImport() the operation is successful, a subsequent import gives me an EINVAL (100022) error.

This does not happen if I quit and relaunch the app between two imports. I am including the source code below.

    CFArrayRef array = (CFArrayRef)[NSMutableArray array];

    SecExternalFormat format = kSecFormatUnknown;

    //We are always storing a private key…
    SecExternalItemType type = kSecItemTypePrivateKey;

    SecKeyImportExportParameters params;

    SecKeychainRef keychain;

    SecKeychainCopyDefault(&keychain);

    memset(&params, 0, sizeof(params));

    params.version = SEC_KEY_IMPORT_EXPORT_PARAMS_VERSION;
    params.flags = kSecKeyNoAccessControl;
    params.keyUsage = CSSM_KEYUSE_ANY;
    params.keyAttributes = CSSM_KEYATTR_EXTRACTABLE;

    err = SecKeychainItemImport((CFDataRef)data,
                                         (CFStringRef)@"pem",
                                         &format,
                                         &type,
                                         0,
                                         NULL,
                                         keychain,
                                         &array);
    if(err == noErr)
    {
        //Change the kSecKeyPrintName attribute of the keychain item.
    }

    else
    {
        //Handle the error by displaying appropriate alert.
    }

Am I missing anything obvious?

  • 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-05-27T20:51:45+00:00Added an answer on May 27, 2026 at 8:51 pm

    Try setting the CSSM_KEYATTR_PERMANENT bit in params.keyAttribute. On Lion, I can import multiple PEM-armoured RSA private keys (generated with openssl genrsa) into a keychain if I explicitly set this attribute. If I don’t, I get errSecItemNotFound (-25300) when importing the very first key.

    (Don’t forget to remove kSecKeyNoAccessControl before deploying this code in production. Also, if you generate the key yourself, consider using SecKeyGenerate/SecKeyGenerateSymmetric instead.)

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

Sidebar

Related Questions

I'm trying to import an RSA public/private key pair generated with the Win32 Crypto
I am trying to import an excel file into a data table using GemBox
I am trying to import users into AD using a CSV file, PowerShell, and
I am trying to import details from an access database into my sql application
I am trying to import the contact list from gmail using libgmailer.php but I
I've been trying to import a table from oracle 10g into SQL Server 2005
I am trying to import BlackBerry code and into Eclipse from SVN. It isn't
I’m trying to import fixed width data from text file into SQL Server Express
I'm trying to import a IntelliJ java web application project (Maven Project) from a
I am trying to export a public key from openssl using python. I have

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.