ssl證書怎麼格式轉化

SSL證書格式主要有公鑰證書格式標準X.509中定義的PEM和DER、公鑰密碼標準PKCS中定義的PKCS#7和PKCS#12、Tomcat專用的JKS。常見的SSL證書格式及轉化方法如下:

常見的SSL證書格式

DER:Distinguished Encoding Rules的縮寫,二進位制編碼的證書格式,相當於PEM格式的二進位制版本,證書字尾有: .DER .CER .CRT,主要用於Java平臺

PEM: Privacy Enhanced Mail的縮寫,Base64編碼的證書格式,是將二進位制版本Base64編碼後,以”—–BEGIN…”開頭, “—–END…”結尾。證書字尾有: .PEM .CER .CRT,主要用於Apache和Nginx。

PKCS#7: PKCS(Public-Key Cryptography Standards)標準中的PKCS#7(Cryptographic Message Syntax Standard)。它不包含私鑰,並將證書鏈和使用者證書單獨存放。證書字尾有: .P7B .P7C .SPC,主要用於Tomcat和Windows Server。

PKCS#12:PKCS(Public-Key Cryptography Standards)標準中的PKCS#12(Personal Information Exchange Syntax Standard)。它包含私鑰,證書鏈,使用者證書,並設定了密碼。證書字尾有: .P12 .PFX,主要用於Windows Server。

JKS: JavaKeyStore的縮寫,它包含私鑰,證書鏈,使用者證書,並設定了密碼。證書字尾是.jks。主要用於Tomcat。

SSL證書格式轉化方法

WebTrust認證的CA機構簽發的證書通常只提供PEM格式或PKCS#7格式,如需其他證書格式,可以在下面常用的兩種方法中任選其一進行格式轉化。

方法一:使用OpenSSL、Keytool轉化

1.pem轉換pfx

openssl pkcs12 -export -in 'test.pem' -inkey 'test.key' -out 'test.p12' -passout pass:123456

2.pem轉換jks

openssl pkcs12 -export -in 'test.pem' -inkey 'test.key' -out 'test.p12' -passout pass:123456

keytool -importkeystore -srckeystore 'test.p12' -srcstoretype PKCS12 -destkeystore 'test.jks' -srcstorepass 123456 -deststorepass 123456

3.pfx轉換pem

openssl pkcs12 -in test.p12 -passin pass:123456 -out test3.pem -nodes

4.pfx轉換jks

keytool -importkeystore -srckeystore 'test.p12' -srcstoretype PKCS12 -destkeystore 'test.jks' -srcstorepass 123456 -deststorepass 123456

5.jks轉換pem

keytool -importkeystore -srckeystore 'test.jks' -srcstoretype jks -destkeystore 'test.p12' -deststoretype PKCS12 -srcstorepass 123456 -deststorepass 123456

openssl pkcs12 -in test.p12 -passin pass:123456 -out test3.pem -nodes

6.jks轉化pfx

keytool -importkeystore -srckeystore 'test.jks' -srcstoretype jks -destkeystore 'test.p12' -deststoretype PKCS12 -srcstorepass 123456 -deststorepass 123456

方法二:SSL證書格式轉化工具

對於非專業人士,方法一顯得有點複雜。線上SSL證書轉化工具只需要按要求提示上傳相關證書檔案,選擇目標格式後即可完成轉換,較為簡單。如下圖:

不同伺服器型別支援的SSL證書格式不同,請根據自己的伺服器選擇對應的證書格式即可安裝SSL證書。