[APNs] Generate APNs Keys : .p12 -> .pem

less than 1 minute read

1. 첫번째 방법

키체인을 열어서, Apple Development Push Notification 인증서를 Export 합니다.

.p12파일로 생성을 Export 하며, Export시 임의의 암호를 설정해야 합니다.(cert.p12 파일 생성)

인증서의 개인키 또한 .p12파일로 Export 합니다.(key.p12 파일 생성)

이제 Terminal을 실행하여, 해당 키파일이 있는 곳으로 이동합니다.

먼저 인증서(cert.p12)의 형식을 .pem으로 변환합니다.

$ openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12

인증서 Export시에 설정했던 암호를 입력하여 완료하면, cert.pem이라는 파일이 생성됩니다.

개인키(key.p12)에도 같은 작업을 진행합니다.

$ openssl pkcs12 -nocerts -out key.pem -in key.p12

cert.pem과는 다르게 암호를 체크 하고, 다른 암호를 다시 설정해주는 단계가 있습니다.

이렇게 암호가 설정되어 만들어진 key.pem을 가지고 key.unencrypted.pem으로 변환해야 합니다.

이 단계에서 방금 새로 설정한 암호가 사용됩니다.

$ openssl rsa -in key.pem -out key.unencrypted.pem

마지막으로 key와 cert를 합쳐 최종 APNs에서 쓰이는 인증서를 만들어줍니다.

$ cat cert.pem key.unencrypted.pem > apns.pem

2. 두번째 방법

https://github.com/tigi44/NodeJS_APNs_Server

  • export cert.cer in keychain access

Image Image

  • export key.p12 in keychain access

Image Image

  • generate cert.cer & key.p12 to .pem files
$ openssl x509 -in cert.cer -inform DER -outform PEM -out cert.pem
$ openssl pkcs12 -in key.p12 -out key.pem -nodes

Leave a comment