How to create a .pem certificate for sending push notifications

When building an app, you'll probably want to be able to send your users push notifications.

Push notifications are an excellent way to keep your users coming back to use your app. So long as they're not sent too often and they're relevant to your user they're a great tool to have in your box.

Here's the process for creating the .pem file.

  1. First, you'll want to create a certificate and you'll want to save these to your keychain. You might want to create a seperate one for development purposes.

  2. Open Spotlight Search by pressing ⌘ + Space

  3. Search for "Keychain Access"

  4. In step 1, you should've saved these certificates to your keychain. So find them and select the certificate as well as the private key (you want to export them both together). Right-click and select "Export 2 items..."

    exporting the certificate and private key together

  5. Enter a name to save the file as and ensure the file format is p12.

    save the .p12 file with a name, destination and file format

  6. Enter a password to lock your certificate. Any time you want to send a push notification with this certificate, you'll require the password. Note: Without a password, anyone can send push notifications to your customers with this certificate. Keep is secret, keep it safe.

    enter a password to lock the certificate

  7. Finally, to export a certificate/private key from Keychain Access, you need to enter your password (you might have to do this twice, once for the certificate, once for the private key).

    Enter your password to export the certificate from keychain access

  8. Once you've saved it, open your Terminal with ⌘ + Space and search for "Terminal". Navigate to your wherever you saved your certificate using the cd command. By default they save in Documents, so I did this.

    cd Documents

    Here's a quick guide if you're not familiar with the cd command.

  9. Then, finally, you'll want to covert your .p12 into a .pem file with the following command.

    openssl pkcs12 -in YourFile.p12 -out YourNewFile.pem

    You'll be prompted to enter the password you used to lock the certificate. You'll also be asked for a PEM password. Create one, and confirm it.
    

Voila! You have you .pem for sending push notifications.

Sam L

12th December 2018 22:54