programing tip

.key 및 .crt 파일에서 .pem 파일을 가져 오는 방법은 무엇입니까?

itbloger 2020. 10. 4. 10:37
반응형

.key 및 .crt 파일에서 .pem 파일을 가져 오는 방법은 무엇입니까?


SSL 인증서에서 PEM 파일을 생성하려면 어떻게해야합니까?

다음은 내가 사용할 수있는 파일입니다.

  • .crt
  • server.csr
  • server.key

키는 이미 PEM 형식 일 수 있지만 .crt 또는 .key로 이름이 지정됩니다.

파일 내용이로 시작 -----BEGIN하고 텍스트 편집기에서 읽을 수있는 경우 :

이 파일은 바이너리 형식이 아닌 ASCII로 읽을 수있는 base64를 사용합니다. 인증서가 이미 PEM 형식입니다. 확장자를 .pem으로 변경하십시오.

파일이 바이너리 인 경우 :

server.crt의 경우 다음을 사용합니다.

openssl x509 -inform DER -outform PEM -in server.crt -out server.crt.pem

server.key openssl rsa의 경우 openssl x509.

server.key는 개인 키일 가능성이 높고 .crt 파일은 반환되고 서명 된 x509 인증서입니다.

웹 서버용이고 별도의 개인 및 공개 키로드를 지정할 수없는 경우 :

두 파일을 연결해야 할 수도 있습니다. 이 용도 :

cat server.crt server.key > server.includesprivatekey.pem

이 파일에 대해 유지하는 권한을 관리하는 데 도움이되도록 "includesprivatekey"로 파일 이름을 지정하는 것이 좋습니다.


AWS ELB에 대해이 작업을 수행해야했습니다. 대화에 여러 번 맞았을 때 마침내 이것이 저에게 효과적이었습니다.

openssl rsa -in server.key -text > private.pem
openssl x509 -inform PEM -in server.crt > public.pem

감사합니다 NCZ

편집 : @floatingrock이 말했듯이

AWS에서는 파일 이름 앞에 file://. 따라서 다음과 같이 보일 것입니다.

 aws iam upload-server-certificate --server-certificate-name blah --certificate-body file://path/to/server.crt --private-key file://path/to/private.key --path /cloudfront/static/

http://docs.aws.amazon.com/cli/latest/reference/iam/upload-server-certificate.html


pem파일은 인증서와 개인 키가 포함되어 있습니다. 인증서 / 키의 형식에 따라 다르지만 다음과 같이 간단합니다.

cat server.crt server.key > server.pem

또한 암호를 요청하지 않으려면 다음 명령을 실행해야합니다.

openssl rsa -in server.key -out server.key

.pem 파일을 만드는 가장 좋은 옵션입니다.

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

내가 관찰 한 것은 인증서를 생성하기 위해 openssl을 사용하는 경우 crt 파일의 텍스트 부분과 base64 인증서 부분을 모두 캡처합니다. 엄격한 pem 형식은 파일이 BEGIN과 END로 시작하고 끝나야 한다고 ( wiki definition ) 말합니다 .

.pem – (Privacy Enhanced Mail) Base64로 인코딩 된 DER 인증서, "----- BEGIN CERTIFICATE -----"와 "----- END CERTIFICATE -----"사이에 포함

따라서 엄격한 pem 형식을 예상하는 일부 라이브러리 (Java에서이 문제가 발생했습니다)의 경우 생성 된 crt는 '잘못된 pem 형식'으로 유효성 검사에 실패합니다.

BEGIN / END CERTIFICATE로 행을 복사하거나 grep하여 cert.pem 파일에 붙여 넣어도 작동합니다.

다음은 내가하는 일입니다. 매우 깨끗하지는 않지만 저에게 효과적입니다. 기본적으로 BEGIN 줄에서 시작하는 텍스트를 필터링합니다.

grep -A 1000 BEGIN cert.crt> cert.pem


나는 godaddy에서 앱 엔진으로 이동하려고했습니다. 트릭은이 줄을 사용하는 것입니다.

openssl req -new -newkey rsa:2048 -nodes -keyout name.unencrypted.priv.key -out name.csr

그대로 있지만 이름을 내 도메인 이름으로 대체합니다 (정말 중요하지 않음).

그리고 나는 www.name.com으로 일반 이름 / 조직과 관련된 모든 질문에 대답했습니다.

그런 다음 csr을 열고 복사하고 go daddy에 붙여 넣은 다음 다운로드하고 압축을 푼 다음 터미널로 압축이 풀린 폴더로 이동하여 다음을 입력했습니다.

cat otherfilegodaddygivesyou.crt gd_bundle-g2-g1.crt > name.crt

그런 다음 Trouble with Google Apps Custom Domain SSL의 다음 안내를 사용했습니다 .

openssl rsa -in privateKey.key -text > private.pem
openssl x509 -inform PEM -in www_mydomain_com.crt > public.pem

정확히 그대로, privateKey.key 대신 name.unencrypted.priv.key를 사용했고 www_mydomain_com.crt 대신 name.crt를 사용했습니다.

Then I uploaded the public.pem to the admin console for the "PEM encoded X.509 certificate", and uploaded the private.pem for the "Unencrypted PEM encoded RSA private key"..

.. And that finally worked.


Trying to upload a GoDaddy certificate to AWS I failed several times, but in the end it was pretty simple. No need to convert anything to .pem. You just have to be sure to include the GoDaddy bundle certificate in the chain parameter, e.g.

aws iam upload-server-certificate
    --server-certificate-name mycert
    --certificate-body file://try2/40271b1b25236fd1.crt
    --private-key file://server.key
    --path /cloudfront/production/
    --certificate-chain file://try2/gdig2_bundle.crt

And to delete your previous failed upload you can do

aws iam delete-server-certificate --server-certificate-name mypreviouscert

  1. Download certificate from provisional portal by appleId,
  2. Export certificate  from Key chain and  give name (Certificates.p12),
  3. Open terminal and goto folder where you save above Certificates.p12 file,
  4. Run below commands:

    a) openssl pkcs12 -in Certificates.p12 -out CertificateName.pem -nodes,

    b) openssl pkcs12 -in Certificates.p12 -out pushcert.pem -nodes -clcerts

  5. Your .pem file ready "pushcert.pem".

  • Open terminal.
  • Go to the folder where your certificate is located.
  • Execute below command by replacing name with your certificate.

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

  • Hope it will work!!

참고URL : https://stackoverflow.com/questions/991758/how-to-get-pem-file-from-key-and-crt-files

반응형