如何为 iOS 分发创建 P12 证书

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9418661/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:59:41  来源:igfitidea点击:

How to create P12 certificate for iOS distribution

iosiphonexcodecertificatep12

提问by RobG

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 Overflowto 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.

我们有一个 iOS 应用程序,其推送通知证书已过期,我们正在尝试创建一个新应用程序。我在 Provisioning 门户(ios_developer.cer、ios_distribution.cer)中创建了新证书并下载了它们。我正在按照Stack Overflow上的说明将其转换为 PEM,然后转换为 P12 文件,但我被卡住了。然后当我尝试将 PEM 转换为 P12 时,它需要某种私钥,但我不知道从哪里获取它。

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.

我也尝试将这些加载到 Keychain Access 中。我读过您可以从那里将它们导出为 P12,但是当我执行导入时,它们不会出现在任何地方。

回答by picciano

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.

当您在 Keychain Access 中创建签名请求时会生成您的私钥。生成并下载证书后,双击它会将其添加到 Keychain Access 中,在那里它将与私钥匹配。然后,您可以选择证书,并打开箭头以同时选择私钥并将它们一起作为 .p12 文件从 Keychain Access 导出。

回答by Jayprakash Dubey

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

.p12 文件用于在 Apple App Store 上发布应用程序

A. Create a (.certSigningRequest) CSR file

A. 创建 (.certSigningRequest) CSR 文件

  1. Open Keychain Accessfrom Utilities
  2. From Keychain Access toolbar select Keychain Access -> Preference
  3. In the pop up window select Certificatestab
  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
  1. 从实用程序打开钥匙串访问
  2. 从 Keychain Access 工具栏选择Keychain Access -> Preference
  3. 在弹出窗口中选择证书选项卡
  4. “在线证书状态协议”和“证书吊销列表”都设置为“关闭”
  5. 关闭此窗口
  6. 现在从工具栏,打开钥匙串访问>证书助手>从证书颁发机构请求证书
  7. 输入您在 iOS Developer Program 中注册时使用的电子邮件地址和常用名称
  8. 将 CA 电子邮件留空并选择“保存到磁盘”和“让我指定密钥对信息”
  9. 点击继续
  10. 选择硬盘上的文件名和目的地
  11. 点击保存
  12. 在下一个窗口中,将“密钥大小”值设置为“2048 位”
  13. “算法”设置为“RSA”
  14. 点击继续

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.

这将创建您的 certSigningRequest 文件 (CSR) 并将其保存到您的硬盘驱动器。还将在 Keychain Access 中使用输入的通用名称创建公钥和私钥。

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

B. 在 iOS 开发者账户中创建“.cer”文件

  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 Downloadto get the file
  1. 登录苹果开发者账号点击“Certificates, Identifiers & Profiles”
  2. 点击“配置文件”
  3. 在“证书”部分点击“生产”
  4. 单击主面板右上角的“添加”(+) 按钮
  5. 现在,选择“App Store 和 Ad Hoc”
  6. 点击继续
  7. 单击“选择文件”并找到您从硬盘驱动器制作的 CSR 文件
  8. 点击生成
  9. 点击下载获取文件

C. Install .cer and generate .p12 certificate

C.安装.cer并生成.p12证书

  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
  1. 找到您下载的 .cer 文件并双击
  2. 将登录下拉列表设置为“登录”并单击添加
  3. 打开 KeyChain Access,您将找到在步骤 A 中创建的配置文件
  4. 您可以展开“私钥”配置文件(显示您添加的证书)
  5. 只选择这两项(不是公钥)
  6. 右键单击并从弹出窗口中单击“导出 2 个项目...”
  7. 现在确保文件格式为“.p12”并选择硬盘驱动器上的文件名和目的地
  8. 单击保存。现在,系统会提示您设置密码,但将它们都保留为空白
  9. 单击确定。现在,您的硬盘驱动器上有一个 .p12 文件

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.

如果您的钥匙串存在于 iCloud 中,则从 iCloud 中删除所有钥匙串内容并在 iCloud 中进行新设置这应该可以工作。

回答by Abraham Lopez

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 -> Adding certificates to keychain and generating .p12 file format- alon rosenfeld 10 months ago

好的,问题解决了!似乎当我双击证书时,它会自动将其安装在 SYSTEM 钥匙串中 - 我不知道为什么。因此,我只是将证书拖放到 LOGIN 钥匙串中,然后一切都很好。感谢这篇文章 ->将证书添加到钥匙串并生成 .p12 文件格式- alon rosenfeld 10 个月前

回答by albaiti

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

除非您通过从钥匙链左下角选择 (Certificates) 进行过滤,否则您将不会获得扩展选项

回答by Dirk Boer

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

对于其他有灰色/灰色 P12 选项的人:

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

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

回答by Jessicardo

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.

对于仍然存在此问题的任何人,我的解决方案是不要同时选择和“导出 2 个项目”(密钥和证书)——而只是导出已经包含密钥的证书。截至 2016 年,我认为这是这样做的方法,因为以前与导出 2 项一起使用的上传不再有效。

回答by swiftBoy

To get your p12 file go this way..

要让你的 p12 文件走这条路..

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

步骤 1.XCode> 转到项目设置>常规>签名部分 >签名证书

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 Categorysection > Certificates

第 2 步。打开钥匙串> 在左下角类别部分 >证书

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 exportas "Certificates.p12" by giving your password eg. "123456"

第 3 步。右键单击并通过提供您的密码导出为“Certificates.p12”,例如。“123456”