openssl的證書格式轉換
證書轉換
PKCS 全稱是 Public-Key Cryptography Standards ,是由 RSA 實驗室與其它安全系統(tǒng)開發(fā)商為促進公鑰密碼的發(fā)展而制訂的一系列標準,PKCS 目前共發(fā)布過 15 個標準。 常用的有:
PKCS#7 Cryptographic Message Syntax Standard
PKCS#10 Certification Request Standard
PKCS#12 Personal Information Exchange Syntax Standard
X.509是常見通用的證書格式。所有的證書都符合為Public Key Infrastructure (PKI) 制定的 ITU-T X509 國際標準。
PKCS#7 常用的后綴是: .P7B .P7C .SPC
PKCS#12 常用的后綴有: .P12 .PFX
X.509 DER 編碼(ASCII)的后綴是: .DER .CER .CRT
X.509 PAM 編碼(Base64)的后綴是: .PEM .CER .CRT
.cer/.crt是用于存放證書,它是2進制形式存放的,不含私鑰。
.pem跟crt/cer的區(qū)別是它以Ascii來表示。
pfx/p12用于存放個人證書/私鑰,他通常包含保護密碼,2進制方式
p10是證書請求
p7r是CA對證書請求的回復,只用于導入
p7b以樹狀展示證書鏈(certificate chain),同時也支持單個證書,不含私鑰。
1. CA證書
用openssl創(chuàng)建CA證書的RSA密鑰(PEM格式):
openssl genrsa -des3 -out ca.key 1024
2. 創(chuàng)建CA證書有效期為一年
用openssl創(chuàng)建CA證書(PEM格式,假如有效期為一年):
openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config openssl.cnf
openssl是可以生成DER格式的CA證書的,最好用IE將PEM格式的CA證書轉換成DER格式的CA證書。
3. x509轉換為pfx
openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
4. PEM格式的ca.key轉換為Microsoft可以識別的pvk格式
pvk -in ca.key -out ca.pvk -nocrypt -topvk
5. PKCS#12 到 PEM 的轉換
openssl pkcs12 -nocerts -nodes -in cert.p12 -out private.pem? 驗證? openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem
6. 從 PFX 格式文件中提取私鑰格式文件 (.key)
openssl pkcs12 -in mycert.pfx -nocerts -nodes -out mycert.key
7. 轉換 pem 到到 spc
openssl crl2pkcs7 -nocrl -certfile venus.pem? -outform DER -out venus.spc
用 -outform -inform 指定 DER 還是 PAM 格式。例如:
openssl x509 -in Cert.pem -inform PEM -out cert.der -outform DER
8. PEM 到 PKCS#12 的轉換
openssl pkcs12 -export -in Cert.pem -out Cert.p12 -inkey key.pem
IIS 證書
cd c:\openssl ? set OPENSSL_CONF=openssl.cnf ? openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
server.key和server.crt文件是Apache的證書文件,生成的server.pfx用于導入IIS
9. How to Convert PFX Certificate to PEM Format for SOAP
$ openssl pkcs12 -in test.pfx -out client.pem? Enter Import Password:? MAC verified OK? Enter PEM pass phrase:? Verifying - Enter PEM pass phrase:
IOS開發(fā) 把cer證書轉為p12證書
在?Mac?OS?上將?iPhone?開發(fā)人員證書轉換為?P12?文件
從?Apple?下載?Apple?iPhone?證書后,將其導出為?P12?證書格式。在?Mac??OS?上執(zhí)行以下操作:
打開鑰匙串訪問應用程序(位于應用程序/實用工具文件夾中)。
如果尚未將該證書添加到鑰匙串,請選擇“文件”>“導入”。然后瀏覽到您從?Apple?獲取的證書文件(.cer?文件)。
在鑰匙串訪問中選擇密鑰類別。
選擇與?iPhone?開發(fā)證書相關聯(lián)的私鑰。
該私鑰由?iPhone?開發(fā)人員識別:與之配對的<名字><姓氏>公共證書。
選擇“文件”>“導出項目”。
以個人信息交換?(.p12)?文件格式保存您的密鑰。
系統(tǒng)將提示您創(chuàng)建一個嘗試在其他計算機上導入此密鑰時需要使用的密碼。
在?Windows?上將?Apple?開發(fā)人員證書轉換為?P12?文件
要使用?Flash?CS5?開發(fā)?iPhone?應用程序,則必須使用?P12?證書文件。基于從?Apple?收到的?Apple?iPhone?開發(fā)人員證書文件生成此證書。
將從?Apple?收到的開發(fā)人員證書文件轉換成?PEM?證書文件。從?OpenSSL?bin?目錄運行以下命令行語句:
openssl?x509?-in?developer_identity.cer?-inform?DER?-out?developer_identity.pem?-outform?PEM
如果您使用的是?Mac?計算機上鑰匙串中的私鑰,則將其轉換成?PEM?密鑰:
openssl?pkcs12?-nocerts?-in?mykey.p12?-out?mykey.pem
現(xiàn)在,您可以基于密鑰和?PEM?版本的?iPhone?開發(fā)人員證書生成有效的?P12?文件:
openssl?pkcs12?-export?-inkey?mykey.key?-in?developer_identity.pem?-out?iphone_dev.p12
如果您使用的是?Mac?OS?鑰匙串中的密鑰,則使用上一步驟中生成的?PEM?版本。否則,請使用以前生成的?OpenSSL?密鑰(位于?Windows?上)。
按步驟來,拿到cer文件后發(fā)覺無法導出p12,有過來人指點下啊
我先到開發(fā)者授權系統(tǒng),進入Certificates頁面后,點擊Distribution標簽。如下圖,下載一個
AppleWWDRCA(Apple World Wide Developer Relations Certification Authority)證書文件到本地,
2:然后到開發(fā)者授權系統(tǒng)證書頁面,點擊Request Certificate,按照我們之前介紹過的流程上傳一個
CSR文件,然后下載一個cer文件,
打開cer文件之后,在鑰匙串里面沒有發(fā)現(xiàn)相應的鑰匙。
也無導出p12的提示
這是怎么回事?誰解決過啊?
雙擊cer文件,鑰匙串里面沒相應的鑰匙??在certificates分欄里面哦,注意找找看。找到key單擊右鍵就又導出p12文件選項
http://blog.csdn.net/wave_1102/article/details/7669152
里面有介紹
謝謝 解決了??我把里面我在我的證書里面,把所有證書都刪除了,然后新建證書請求,然后再申請cer回來安裝后就能導出P12了,不過還是沒明白什么原因,可能跟以前生成的證書有沖突還是怎么滴
將開發(fā)人員證書轉換為 P12 文件
要使用 Flash Professional CS5 開發(fā) iPhone 應用程序,您必須使用 P12 證書文件。基于從 Apple 收到的 Apple iPhone 開發(fā)人員證書文件生成此證書。
在 Mac OS 上將 iPhone 開發(fā)人員證書轉換為 P12 文件
從 Apple 下載 Apple iPhone 證書后,將其導出為 P12 證書格式。在 Mac? OS 上執(zhí)行以下操作:
打開鑰匙串訪問應用程序(位于應用程序/實用工具文件夾中)。
如果尚未將該證書添加到鑰匙串,請選擇“文件”>“導入”。然后瀏覽到您從 Apple 獲取的證書文件(.cer 文件)。
在鑰匙串訪問中選擇密鑰類別。
選擇與 iPhone 開發(fā)證書相關聯(lián)的私鑰。
該私鑰由 iPhone 開發(fā)人員識別:與之配對的<名字><姓氏>公共證書。
選擇“文件”>“導出項目”。
以個人信息交換 (.p12) 文件格式保存您的密鑰。
系統(tǒng)將提示您創(chuàng)建一個嘗試在其他計算機上導入此密鑰時需要使用的密碼。
在 Windows 上將 Apple 開發(fā)人員證書轉換為 P12 文件
要使用 Flash CS5 開發(fā) iPhone 應用程序,則必須使用 P12 證書文件。基于從 Apple 收到的 Apple iPhone 開發(fā)人員證書文件生成此證書。
將從 Apple 收到的開發(fā)人員證書文件轉換成 PEM 證書文件。從 OpenSSL bin 目錄運行以下命令行語句:
openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM
如果您使用的是 Mac 計算機上鑰匙串中的私鑰,則將其轉換成 PEM 密鑰:
openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem
現(xiàn)在,您可以基于密鑰和 PEM 版本的 iPhone 開發(fā)人員證書生成有效的 P12 文件:
openssl pkcs12 -export -inkey mykey.key -in developer_identity.pem -out iphone_dev.p12
如果您使用的是 Mac OS 鑰匙串中的密鑰,則使用上一步驟中生成的 PEM 版本。否則,請使用以前生成的 OpenSSL 密鑰(位于 Windows 上)。
This section provides a tutorial example on how to convert a
private key file from the traditional format into PKCS#8 format using
the 'openssl pkcs8' command. Keys can still be encoded with DER or PEM
with or without DES encryption in PKCS#8 format.
Once I have my private key stored in the traditional format,
I can use the "openssl pkcs8" command to convert it into PKCS#8 format.
My plan was to try to do the following:
"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with PEM encoding, but no encryption.
"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with DER encoding, but no encryption.
"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with PEM encoding and encryption.
"openssl pkcs8 -topk8" to convert the key file format to PKCS#8 with DER encoding and encryption.
My command session was recorded as blow:
>rem PKCS#8 format, PEM encoding, no encryption
>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem
-out openssl_key_pk8.pem -outform pem -nocrypt
>rem PKCS#8 format, DER encoding, no encryption
>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem
-out openssl_key_pk8.der -outform der -nocrypt
>rem PKCS#8 format, PEM encoding, encrypted
>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem
-out openssl_key_pk8_enc.pem -outform pem
Enter Encryption Password: keypass
Verifying - Enter Encryption Password: keypass
Loading 'screen' into random state - done
>rem PKCS#8 format, DER encoding, encrypted
>openssl pkcs8 -topk8 -in openssl_key.pem -inform pem
-out openssl_key_pk8_enc.der -outform der
Enter Encryption Password: keypass
Verifying - Enter Encryption Password: keypass
Loading 'screen' into random state - done
All commands executed as expected this time. I got my RSA private key stored in
OpenSSL traditional format and PKCS#8 format in 7 flavors:
04/01/2007? 09:55 AM? ? ? ? ? ? ? 608 openssl_key.der
04/01/2007? 09:52 AM? ? ? ? ? ? ? 887 openssl_key.pem
04/01/2007? 10:01 AM? ? ? ? ? ? ? 958 openssl_key_des.pem
04/01/2007? 10:29 AM? ? ? ? ? ? ? 634 openssl_key_pk8.der
04/01/2007? 10:28 AM? ? ? ? ? ? ? 916 openssl_key_pk8.pem
04/01/2007? 11:53 AM? ? ? ? ? ? ? 677 openssl_key_pk8_enc.der
04/01/2007? 10:29 AM? ? ? ? ? ? ? 993 openssl_key_pk8_enc.pem
Now the question is how to verify them? Looks like there no easy tool to do this.
I will leave this task later by writing a Java program to verify them.