Skip to content

Retrieving a certificate and private key from a P12 file


How to retrieve a certificate and private key from a .p12 file.
I needed it when I was writing AWS SNS with Terraform.

$ openssl pkcs12 -in xxxx.p12 -nodes -nokeys -out certificate.pem
$ openssl pkcs12 -in xxxx.p12 -nodes -nocerts -out privatekey.oem

This way, however, the file will have text starting with NoArgument at the beginning.
NoArgument doesn't do any harm when it's in, but I was curious about it, so I tried to remove it. The secret key was converted without NoArgument by executing the following command.
I gave up on the certificate because I couldn't find a way to erase the text.
I'll post it if I can.

$ openssl pkcs12 -in xxxx.p12 -nodes -nocerts | openssl rsa -out privatekey.pem

参考: Push通知の証明書、p12 -> pem変換について

  1. Update cocoapods installed with gem.
  2. I had a chance to speak at iOSDCJapan2019 Day 1 in the Rookies LT slot.
  3. Changing the height of a TableView cell (Swift5.0.1)
  4. UIButton, display a button (Swift5.0)
  5. Using UISlider to retrieve a value at regular intervals (Swift5.0)
  6. Getting a value with UISlider (Swift5.0)
  7. Displaying an incoming call screen using CallKit.