SSL 轉換常見問題

關於 SSL 憑證格式轉換的常見問題

憑證格式比較

格式副檔名編碼用途
PEM.pem, .crt, .keyBase64 (ASCII)最常見的格式,用於 Apache、Nginx
DER.der, .cer二進位 (DER)二進位格式,用於 Java 及部分 Windows 應用程式
P7B/PKCS#7.p7b, .p7cBase64 (ASCII)憑證鏈結格式,用於 Windows
PFX/PKCS#12.pfx, .p12二進位 (DER)包含私鑰的封存格式,用於 Windows/IIS

常見轉換

PEM → DER

將 PEM 轉換為 DER 二進位格式

openssl x509 -in cert.pem -outform DER -out cert.der

DER → PEM

將 DER 二進位轉換為 PEM 文字格式

openssl x509 -in cert.der -inform DER -outform PEM -out cert.pem

PEM → P7B

將 PEM 憑證轉換為 PKCS#7 格式

openssl crl2pkcs7 -nocrl -certfile cert.pem -out cert.p7b

P7B → PEM

將 PKCS#7 轉換為 PEM 憑證格式

openssl pkcs7 -in cert.p7b -print_certs -out cert.pem

PEM → PFX

將 PEM 憑證和金鑰轉換為 PFX 封存

openssl pkcs12 -export -out cert.pfx -inkey private.key -in cert.pem -certfile chain.pem

PFX → PEM

從 PFX 封存中擷取 PEM 憑證和金鑰

openssl pkcs12 -in cert.pfx -out cert.pem -nodes

提示

  • 轉換前務必備份您的憑證
  • 轉換過程中请保管好您的私鑰
  • 驗證轉換後的憑證是否正常運作
  • 部分轉換需要私鑰密碼