title: Importing a Private Key to Keychain returns EINVAL error
body: <p>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. </p>
  
  <p>This does not happen if I quit and relaunch the app between two imports. I am including the source code below.</p>
  
  <blockquote>
  <pre><code>    CFArrayRef array = (CFArrayRef)[NSMutableArray array];
  
      SecExternalFormat format = kSecFormatUnknown;
  
      //We are always storing a private key…
      SecExternalItemType type = kSecItemTypePrivateKey;
  
      SecKeyImportExportParameters params;
  
      SecKeychainRef keychain;
  
      SecKeychainCopyDefault(&amp;keychain);
  
      memset(&amp;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",
                                           &amp;format,
                                           &amp;type,
                                           0,
                                           NULL,
                                           keychain,
                                           &amp;array);
      if(err == noErr)
      {
          //Change the kSecKeyPrintName attribute of the keychain item.
      }
  
      else
      {
          //Handle the error by displaying appropriate alert.
      }
  </code></pre>
  </blockquote>
  
  <p>Am I missing anything obvious?</p>