How to create P12 certificate for iOS distribution

IosIphoneXcodeCertificateP12

Ios Problem Overview


We have an iOS app whose push notification cert has expired and we're trying to create a new one. I've created new certs in the Provisioning portal (ios_developer.cer, ios_distribution.cer) and downloaded them. I was following instructions here on Stack Overflow to convert it to PEM and then to P12 files, but I'm stuck. When I then attempt to convert the PEM to P12, it wants a private key of some sort, and I don't know where to get it.

I've also tried loading these into Keychain Access. I had read that you could export them as P12 from there, but when I do the Import, they don't appear anywhere.

Ios Solutions


Solution 1 - Ios

Your private key is generated when you created the signing request in Keychain Access. After the cert is generated and downloaded, double-clicking it will add it to Keychain Access where it will be matched up with the private key. You can then select the cert, and open the arrow to also select the private key and export them together as a .p12 file from Keychain Access.

Solution 2 - Ios

.p12 files are used to publish app on the Apple App Store

A. On your Mac Create a (.certSigningRequest) CSR file

  1. Open Keychain Access from Utilities
  2. From Keychain Access toolbar select Keychain Access -> Preference
  3. In the pop up window select Certificates tab
  4. Set both “Online Certificate Status Protocol” and “Certificate Revocation List” to “Off"
  5. Close this window
  6. Now from toolbar, open Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority
  7. Enter email address and common name that you used to register in the iOS Developer Program
  8. Keep CA Email blank and select “Saved to disk” and “Let me specify key pair information”
  9. Click Continue
  10. Choose a filename & destination on your hard drive
  11. Click Save
  12. In the next window, set “Key Size” value to “2048 bits”
  13. Set “Algorithm” to “RSA”
  14. Click Continue

This will create and save your certSigningRequest file (CSR) to your hard drive. A public and private key will also be created in Keychain Access with the Common Name entered.

B. Create ".cer" file in iOS developer account

  1. Login to apple developer account Click “Certificates, Identifiers & Profiles”
  2. Click “Provisioning Profiles”
  3. In the “Certificates” section click “Production”
  4. Click the “Add” (+) button at the top-right of the main panel
  5. Now, choose “App Store and Ad Hoc”
  6. Click Continue
  7. Click “Choose File” & find CSR file you’ve made from your hard drive
  8. Click Generate
  9. Click Download to get the file

C. Install .cer and generate .p12 certificate

  1. Find .cer file you’ve downloaded and double-click
  2. Set Login drop-down to “login" and Click Add
  3. Open up KeyChain Access and you'll find profile created in Step A
  4. You can expand “private key” profile (shows certificate you added)
  5. Select only these two items (not the public key)
  6. Right click and click “Export 2 items…” from popup
  7. Now make sure file format is “.p12” and choose filename and destination on your hard drive
  8. Click Save. Now, you’ll be prompted to set a password but keep these both blank
  9. Click OK. Now, you have a .p12 file on your hard drive

Take a note that if issue still persists then try below step as well:

If your keychain is present in iCloud then remove all keychain content from iCloud and do new setup in iCloud This should work.

Solution 3 - Ios

you will not get the expand option unless you filter by choosing (Certificates) from key chain left bottom corner

Solution 4 - Ios

OK, problem solved! it seems that when i double click on the certificate, it automatically installs it in the SYSTEM keychain - i don't know why. So instead, i simply drag and drop the certificate into the LOGIN keychain and then all is good. Thanks to this article -> https://stackoverflow.com/questions/14315205/adding-certificates-to-keychain-and-generating-p12-file-format - alon rosenfeld 10 months ago

Solution 5 - Ios

To get your p12 file go this way..

Step 1. In XCode > Go to Project settings > General > Signing section > Signing Certificate

See which certificate you are using for this particular app as shown in image below

enter image description here

Step 2. Open Keychain > on Left bottom Category section > Certificates

Look for the certificate and open child by clicking on down arrow as show in image

enter image description here

Step 3. Right click and export as "Certificates.p12" by giving your password eg. "123456"

Solution 6 - Ios

For anyone else having the greyed/grayed out P12 option:

> Make sure you are in the My Certificates or Certificates category in > Keychain Access.

https://sailthru.zendesk.com/hc/en-us/articles/115000032546-Can-t-export-my-certificate-in-p12-format

Solution 7 - Ios

For anyone still having this issue, the solution for me was to NOT select both and "Export 2 items" (the key and the certificate) - rather just export the certificate which ALREADY includes the key. As of 2016 i think this is the way to do it because previous uploads that worked with the export 2 items no longer work.

Solution 8 - Ios

I ended up here as I was trying to build an iOS app in the cloud using MS Visual Studio App Center WITHOUT a Mac. The issue is every tutorial uses the top rated answer above by Jayprakash Dubey. That approach uses a Mac and KeyChain. The solution comes from SO here.

You need a Key (aps_development.key), and then:

  1. Create key pair : openssl genrsa -out aps_development.key 2048
  2. Create CSR : openssl req -new -sha256 -key aps_development.key -out aps_development.csr
  3. Upload the CSR to developer portal to get the certificate aps_development.cer
  4. Convert the certificate: openssl x509 -inform DER -outform PEM -in aps_development.cer -out aps_development.pem
  5. Build the PKCS#12: openssl pkcs12 -inkey aps_development.key -in aps_development.pem -export -out aps_development.p12

You can then go ahead and make an app id and a provisioning profile. This will allow you to build in the App Center.

Solution 9 - Ios

For anyone else having the greyed/grayed out P12 option,

here is the latest screenshot (2021) from my macbook pro.

keychain access v11.0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobGView Question on Stackoverflow
Solution 1 - IospiccianoView Answer on Stackoverflow
Solution 2 - IosJayprakash DubeyView Answer on Stackoverflow
Solution 3 - IosalbaitiView Answer on Stackoverflow
Solution 4 - IosAbraham LopezView Answer on Stackoverflow
Solution 5 - IosswiftBoyView Answer on Stackoverflow
Solution 6 - IosDirk BoerView Answer on Stackoverflow
Solution 7 - IosJessicardoView Answer on Stackoverflow
Solution 8 - IosMattPil29View Answer on Stackoverflow
Solution 9 - IosLai LeeView Answer on Stackoverflow