ios 如何在 iphone 中为推送通知生成 pem 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16055756/
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 23:13:04  来源:igfitidea点击:

How can I generate pem file for push notifications in iphone?

iospush-notificationapple-push-notificationsssl-certificate

提问by nitin kachhadiya

Using this linkfor generate pem file for push notification, but I can't understand following steps...

使用此链接生成推送通知的 pem 文件,但我无法理解以下步骤...

Installing the SSL Certificate and Key on the Server

You should install the SSL distribution certificate and private cryptographic key you obtained earlier on the server computer on which the provider code runs and from which it connects with the sandbox or production versions of APNs. To do so, complete the following steps:

  1. Open Keychain Access utility and click the My Certificates category in the left pane.

  2. Find the certificate you want to install and disclose its contents. You'll see both a certificate and a private key.

  3. Select both the certificate and key, choose File > Export Items, and export them as a Personal Information Exchange (.p12) file.

  4. Servers implemented in languages such as Ruby and Perl often are better able to deal with certificates in the Personal Information Exchange format. To convert the certificate to this format, complete the following steps:

    • In KeyChain Access, select the certificate and choose File > Export Items. Select the Personal Information Exchange (.p12) option, select a save location, and click Save.

    • Launch the Terminal application and enter the following command after the prompt: openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes.

  5. Copy the .pem certificate to the new computer and install it in the appropriate place.

在服务器上安装 SSL 证书和密钥

您应该在运行提供程序代码的服务器计算机上安装之前获得的 SSL 分发证书和私有加密密钥,并从该计算机连接沙箱或 APN 的生产版本。为此,请完成以下步骤:

  1. 打开钥匙串访问实用程序,然后单击左窗格中的我的证书类别。

  2. 找到您要安装的证书并公开其内容。您将同时看到证书和私钥。

  3. 选择证书和密钥,选择文件 > 导出项目,然后将它们导出为个人信息交换 (.p12) 文件。

  4. 以 Ruby 和 Perl 等语言实现的服务器通常能够更好地处理个人信息交换格式的证书。要将证书转换为这种格式,请完成以下步骤:

    • 在 KeyChain Access 中,选择证书并选择 File > Export Items。选择个人信息交换 (.p12) 选项,选择保存位置,然后单击保存。

    • 启动终端应用程序并在提示后输入以下命令:openssl pkcs12 -in CertificateName.p12 -out CertificateName.pem -nodes。

  5. 将 .pem 证书复制到新计算机并安装在适当的位置。

采纳答案by nitin kachhadiya

finally i sloved generate push notification certifcates

最后我喜欢生成推送通知证书

complete step for generate push notification certificates.....

生成推送通知证书的完整步骤.....

1) open key chain and request certificate show in below image.

1) 打开钥匙链并请求证书如下图所示。

enter image description here

在此处输入图片说明

2) change common name as your project_name.

2) 将通用名称更改为您的 project_name。

enter image description here

在此处输入图片说明

3) in keychain open key you can show two key public and private

3)在钥匙串打开密钥中,您可以显示两个密钥公钥和私钥

enter image description here

在此处输入图片说明

4) write click on private key and export it.

4)写点击私钥并导出。

enter image description here

在此处输入图片说明

5) make name project_name_key.p12

5) 命名 project_name_key.p12

6) add password ex-1234

6) 添加密码 ex-1234

7) enter system login password and save it. now you have following certificates.

7) 输入系统登录密码并保存。现在你有以下证书。

enter image description here

在此处输入图片说明

8) now goto developer account (https://developer.apple.com/devcenter/ios/index.action) and goto identifier create new if not exits. and edit setting.

8) 现在转到开发者帐户 ( https://developer.apple.com/devcenter/ios/index.action) 并转到标识符创建新如果不退出。并编辑设置。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

if push notification disable then enable it from edit.

如果推送通知禁用,则从编辑中启用它。

enter image description here

在此处输入图片说明

9) for development you can create first one and distribution you can select last one.

9)对于开发,您可以创建第一个,分发您可以选择最后一个。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

10) after select and generate download apns certificate and put into desktop and double click on it.

10)选择生成下载apns证书后放入桌面双击。

11) then open key chain and goto certificates. and you can show your push service open then you show private key.

11)然后打开钥匙链并转到证书。你可以显示你的推送服务打开然后你显示私钥。

export it with 1234 password.

用1234密码导出。

enter image description here

在此处输入图片说明

12) now you have following file.

12)现在你有以下文件。

enter image description here

在此处输入图片说明

13) open terminal and goto desktop.

13) 打开终端并转到桌面。

enter image description here

在此处输入图片说明

14) generate .pem file using following line for push_cert.p12 file

14) 使用以下行为 push_cert.p12 文件生成 .pem 文件

openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in push_cert.p12

then enter password:-1234

然后输入密码:-1234

enter image description here

在此处输入图片说明

15) generate .pem file using following line for project_name_key.p12 file

15) 使用以下行为 project_name_key.p12 文件生成 .pem 文件

openssl pkcs12 -nocerts -out apns-dev-key.pem -in project_name_key.p12

then enter password:-1234 Enter PEM pass phrase:1234 Verifying - Enter PEM pass phrase:1234

然后输入密码:-1234 输入 PEM 密码:1234 验证 - 输入 PEM 密码:1234

enter image description here

在此处输入图片说明

16) enter following 3 line in terminal

16) 在终端输入以下 3 行

openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem

Enter pass phrase for apns-dev-key.pem:1234

输入 apns-dev-key.pem:1234 的密码

cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem

enter image description here

在此处输入图片说明

17) you have following certificate.

17) 你有以下证书。

enter image description here

在此处输入图片说明

18) apns-dev.pem file send on server and it pass is 1234

18) apns-dev.pem 文件在服务器上发送并且通过的是 1234

19) for development you must use gateway.sandbox.push.apple.com server. and distribution you can use gateway.push.apple.com server.

19) 开发必须使用 gateway.sandbox.push.apple.com 服务器。和分发你可以使用 gateway.push.apple.com 服务器。

回答by Mannam Brahmam

For **

为了 **

  • Production Push Notification
  • 生产推送通知

**

**

I took reference from this link

我参考了这个链接

To enable Push Notification for your iOS app, you will need to create and upload the Apple Push Notification Certificate (.pem file) to us so we will be able to connect to Apple Push Server on your behalf.

要为您的 iOS 应用启用推送通知,您需要创建 Apple 推送通知证书(.pem 文件)并将其上传给我们,以便我们能够代表您连接到 Apple 推送服务器。

(Updated version with updated screen shots Here http://www.apptuitions.com/generate-pem-file-for-push-notification/)

(更新版本的屏幕截图在这里http://www.apptuitions.com/generate-pem-file-for-push-notification/

Step 1:Login to iOS Provisioning Portal, click "Certificates" on the left navigation bar. Then, click "+" button.

第一步:登录iOS Provisioning Portal,点击左侧导航栏的“Certificates”。然后,单击“+”按钮。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Step 2:Select Apple Push Notification service SSL (Production) option under Distribution section, then click "Continue" button. enter image description here

步骤 2:在分发部分下选择 Apple 推送通知服务 SSL(生产)选项,然后单击“继续”按钮。 在此处输入图片说明

Step 3:Select the App ID you want to use for your BYO app (How to Create An App ID), then click "Continue" to go to next step.

第 3 步:选择您要用于 BYO 应用程序的 App ID(如何创建 App ID),然后单击“继续”进入下一步。

enter image description here

在此处输入图片说明

Step 4:Follow the steps "About Creating a Certificate Signing Request (CSR)" to create a Certificate Signing Request. enter image description here

步骤 4:按照“关于创建证书签名请求 (CSR)”的步骤创建证书签名请求。 在此处输入图片说明

To supplement the instruction provided by Apple. Here are some of the additional screenshots to assist you to complete the required steps:

补充 Apple 提供的说明。以下是一些额外的屏幕截图,可帮助您完成所需的步骤:

Step 4 Supplementary Screenshot 1: Navigate to Certificate Assistant of Keychain Access on your Mac.

第 4 步补充截图 1:在 Mac 上导航到 Keychain Access 的证书助手。

enter image description here

在此处输入图片说明

Step 4 Supplementary Screenshot 2:Fill in the Certificate Information. Click Continue.

步骤4 补充截图2:填写证书信息。单击继续。

enter image description here

在此处输入图片说明

Step 5:Upload the ".certSigningRequest" file which is generated in Step 4, then click "Generate" button. enter image description here

第五步:上传第四步生成的“.certSigningRequest”文件,然后点击“生成”按钮。 在此处输入图片说明

Step 6:Click "Done" to finish the registration, the iOS Provisioning Portal Page will be refreshed that looks like the following screen: enter image description here

第六步:点击“完成”完成注册,iOS Provisioning Portal页面将刷新如下图所示: 在此处输入图片说明

Then Click "Download" button to download the certificate (.cer file) you've created just now. - Double click the downloaded file to install the certificate into Keychain Access on your Mac.

然后单击“下载”按钮下载您刚刚创建的证书(.cer 文件)。- 双击下载的文件,将证书安装到 Mac 上的 Keychain Access 中。

Step 7:On your Mac, go to "Keychain", look for the certificate you have just installed. If unsure which certificate is the correct one, it should start with "Apple Production IOS Push Services:" followed by your app's bundle ID. enter image description here

第 7 步:在您的 Mac 上,转到“钥匙串”,查找您刚刚安装的证书。如果不确定哪个证书是正确的,它应该以“Apple Production IOS Push Services:”开头,然后是您的应用程序包 ID。 在此处输入图片说明

Step 8:Expand the certificate, you should see the private key with either your name or your company name. Select both items by using the "Select" key on your keyboard, right click (or cmd-click if you use a single button mouse), choose "Export 2 items", like Below: enter image description here

第 8 步:展开证书,您应该会看到带有您的姓名或公司名称的私钥。使用键盘上的“选择”键选择这两个项目,右键单击(如果使用单键鼠标,则单击 cmd),选择“导出 2 个项目”,如下所示: 在此处输入图片说明

Then save the p12 file with name "pushcert.p12" to your Desktop - now you will be prompted to enter a password to protect it, you can either click Enter to skip the password or enter a password you desire.

然后将名为“pushcert.p12”的 p12 文件保存到您的桌面 - 现在系统将提示您输入密码来保护它,您可以单击 Enter 跳过密码或输入您想要的密码。

Step 9:Now the most difficult part - open "Terminal" on your Mac, and run the following commands:

第 9 步:现在是最困难的部分 - 在 Mac 上打开“终端”,然后运行以下命令:

cd
cd Desktop
openssl pkcs12 -in pushcert.p12 -out pushcert.pem -nodes -clcerts

Step 10:By using this link(click here)

第 10 步:通过使用此链接(单击此处)

You can check weather the .PEM file is valid or not ---> if it's valid you will get success message with notification like: enter image description here

您可以检查 .PEM 文件是否有效 ---> 如果有效,您将收到带有通知的成功消息,例如: 在此处输入图片说明

For **

为了 **

  • Development Push Notification
  • 开发推送通知

**

**

Just Watch the following Youtube link Click hereand enjoy..

只需观看以下 Youtube 链接点击此处即可享受..

回答by Eran

Here's a screenshot of what you have to select in step 3. It's not two certificates. It's a certificate + key.

这是您在第 3 步中必须选择的内容的屏幕截图。它不是两个证书。这是证书+密钥。

enter image description here

在此处输入图片说明

回答by arturdev

I would suggest a much more simple solution. Just use Certifire.
Certifireis a macOS application that generates Apple Push Notification Certificates with just one click in a couple of seconds.

我会建议一个更简单的解决方案。只需使用Certifire
Certifire是一款 macOS 应用程序,只需在几秒钟内单击一下即可生成 Apple 推送通知证书。

Here are the steps:
1. Download the app.
2. Log in using your Apple Developer Account credentials.
3. Choose the App-ID
4. Click "Generate" button
5. You're done!

步骤如下:
1. 下载应用程序。
2. 使用您的 Apple 开发者帐户凭据登录。
3. 选择 App-ID
4. 单击“生成”按钮
5. 大功告成!

You will get APN certificates in .pem format as well as in .p12 format. Even more, you will get also combined .pem and .p12 too (key+cert)!
Much more, you will get no-passphrase versions of all these certificates also!

您将获得 .pem 格式和 .p12 格式的 APN 证书。更重要的是,您还将获得 .pem 和 .p12 的组合(密钥+证书)!
更重要的是,您还将获得所有这些证书的无密码版本!

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Gautam Jain

Just to add the @Nitin's very well described answer. After creating the pem, you can validate it with the openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert MyKey.pem -key MyKey.pemwhere MyKey is the name of your pem file.

只是为了添加@Nitin 很好描述的答案。创建 pem 后,您可以使用openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert MyKey.pem -key MyKey.pemMyKey 是 pem 文件的名称来验证它 。

Replace the gateway.sandbox.push.apple.com with gateway.push.apple.com, to connect to the live APNS.

将 gateway.sandbox.push.apple.com 替换为 gateway.push.apple.com,以连接到实时 APNS。

回答by Gautam Jain

  1. Right click on your APNs certificate and click on export. This will generate the .p12 certificate on desktop
  2. open terminal cd desktop and convert .p12 into .pem using following command

    openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes -clcerts

    as shown in picture

  1. 右键单击您的 APNs 证书,然后单击导出。这将在桌面上生成 .p12 证书
  2. 打开终端 cd desktop 并使用以下命令将 .p12 转换为 .pem

    openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes -clcerts

    如图所示