{"id":240,"date":"2012-04-18T19:01:19","date_gmt":"2012-04-18T19:01:19","guid":{"rendered":"335f5352088d7d9bf74191e006d8e24c"},"modified":"2012-04-18T19:01:19","modified_gmt":"2012-04-18T19:01:19","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/240","title":{"rendered":"openssl\u7684\u8bc1\u4e66\u683c\u5f0f\u8f6c\u6362"},"content":{"rendered":"<div>\n<h2 style=\"clear:both;\">\u8bc1\u4e66\u8f6c\u6362<\/h2>\n<\/div>\n<div>\n<p>\nPKCS \u5168\u79f0\u662f Public-Key Cryptography Standards \uff0c\u662f\u7531 RSA \u5b9e\u9a8c\u5ba4\u4e0e\u5176\u5b83\u5b89\u5168\u7cfb\u7edf\u5f00\u53d1\u5546\u4e3a\u4fc3\u8fdb\u516c\u94a5\u5bc6\u7801\u7684\u53d1\u5c55\u800c\u5236\u8ba2\u7684\u4e00\u7cfb\u5217\u6807\u51c6\uff0cPKCS \u76ee\u524d\u5171\u53d1\u5e03\u8fc7 15 \u4e2a\u6807\u51c6\u3002 \u5e38\u7528\u7684\u6709\uff1a<br \/>\nPKCS#7 Cryptographic Message Syntax Standard<br \/>\nPKCS#10 Certification Request Standard<br \/>\nPKCS#12 Personal Information Exchange Syntax Standard<br \/>\nX.509\u662f\u5e38\u89c1\u901a\u7528\u7684\u8bc1\u4e66\u683c\u5f0f\u3002\u6240\u6709\u7684\u8bc1\u4e66\u90fd\u7b26\u5408\u4e3aPublic Key Infrastructure (PKI) \u5236\u5b9a\u7684 ITU-T X509 \u56fd\u9645\u6807\u51c6\u3002<br \/>\nPKCS#7 \u5e38\u7528\u7684\u540e\u7f00\u662f\uff1a .P7B .P7C .SPC<br \/>\nPKCS#12 \u5e38\u7528\u7684\u540e\u7f00\u6709\uff1a .P12 .PFX<br \/>\nX.509 DER \u7f16\u7801(ASCII)\u7684\u540e\u7f00\u662f\uff1a .DER .CER .CRT<br \/>\nX.509 PAM \u7f16\u7801(Base64)\u7684\u540e\u7f00\u662f\uff1a .PEM .CER .CRT<br \/>\n.cer\/.crt\u662f\u7528\u4e8e\u5b58\u653e\u8bc1\u4e66\uff0c\u5b83\u662f2\u8fdb\u5236\u5f62\u5f0f\u5b58\u653e\u7684\uff0c\u4e0d\u542b\u79c1\u94a5\u3002<br \/>\n.pem\u8ddfcrt\/cer\u7684\u533a\u522b\u662f\u5b83\u4ee5Ascii\u6765\u8868\u793a\u3002<br \/>\npfx\/p12\u7528\u4e8e\u5b58\u653e\u4e2a\u4eba\u8bc1\u4e66\/\u79c1\u94a5\uff0c\u4ed6\u901a\u5e38\u5305\u542b\u4fdd\u62a4\u5bc6\u7801\uff0c2\u8fdb\u5236\u65b9\u5f0f<br \/>\np10\u662f\u8bc1\u4e66\u8bf7\u6c42<br \/>\np7r\u662fCA\u5bf9\u8bc1\u4e66\u8bf7\u6c42\u7684\u56de\u590d\uff0c\u53ea\u7528\u4e8e\u5bfc\u5165<br \/>\np7b\u4ee5\u6811\u72b6\u5c55\u793a\u8bc1\u4e66\u94fe(certificate chain)\uff0c\u540c\u65f6\u4e5f\u652f\u6301\u5355\u4e2a\u8bc1\u4e66\uff0c\u4e0d\u542b\u79c1\u94a5\u3002 <\/p>\n<\/div>\n<div title=\"4.1. CA\u8bc1\u4e66\">\n<div>\n<div>\n<div>\n<h3>1. CA\u8bc1\u4e66<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7528openssl\u521b\u5efaCA\u8bc1\u4e66\u7684RSA\u5bc6\u94a5(PEM\u683c\u5f0f)\uff1a<\/p>\n<pre>openssl genrsa -des3 -out ca.key 1024        <\/pre>\n<\/div>\n<div title=\"4.2. \u521b\u5efaCA\u8bc1\u4e66\u6709\u6548\u671f\u4e3a\u4e00\u5e74\">\n<div>\n<div>\n<div>\n<h3>2. \u521b\u5efaCA\u8bc1\u4e66\u6709\u6548\u671f\u4e3a\u4e00\u5e74<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<p>\u7528openssl\u521b\u5efaCA\u8bc1\u4e66(PEM\u683c\u5f0f,\u5047\u5982\u6709\u6548\u671f\u4e3a\u4e00\u5e74)\uff1a<\/p>\n<pre>openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config openssl.cnf        <\/pre>\n<p>openssl\u662f\u53ef\u4ee5\u751f\u6210DER\u683c\u5f0f\u7684CA\u8bc1\u4e66\u7684\uff0c\u6700\u597d\u7528IE\u5c06PEM\u683c\u5f0f\u7684CA\u8bc1\u4e66\u8f6c\u6362\u6210DER\u683c\u5f0f\u7684CA\u8bc1\u4e66\u3002<\/p>\n<\/div>\n<div title=\"4.3. x509\u8f6c\u6362\u4e3apfx\">\n<div>\n<div>\n<div>\n<h3>3. x509\u8f6c\u6362\u4e3apfx<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt     <\/pre>\n<\/div>\n<div title=\"4.4. PEM\u683c\u5f0f\u7684ca.key\u8f6c\u6362\u4e3aMicrosoft\u53ef\u4ee5\u8bc6\u522b\u7684pvk\u683c\u5f0f\">\n<div>\n<div>\n<div>\n<h3>4. PEM\u683c\u5f0f\u7684ca.key\u8f6c\u6362\u4e3aMicrosoft\u53ef\u4ee5\u8bc6\u522b\u7684pvk\u683c\u5f0f<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>pvk -in ca.key -out ca.pvk -nocrypt -topvk        <\/pre>\n<\/div>\n<div title=\"4.5. PKCS#12 \u5230 PEM \u7684\u8f6c\u6362\">\n<div>\n<div>\n<div>\n<h3>5. PKCS#12 \u5230 PEM \u7684\u8f6c\u6362<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>openssl pkcs12 -nocerts -nodes -in cert.p12 -out private.pem  <\/pre>\n<pre>\u9a8c\u8bc1   <\/pre>\n<pre>openssl pkcs12 -clcerts -nokeys -in cert.p12 -out cert.pem        <\/pre>\n<\/div>\n<div title=\"4.6. \u4ece PFX \u683c\u5f0f\u6587\u4ef6\u4e2d\u63d0\u53d6\u79c1\u94a5\u683c\u5f0f\u6587\u4ef6 (.key)\">\n<div>\n<div>\n<div>\n<h3>6. \u4ece PFX \u683c\u5f0f\u6587\u4ef6\u4e2d\u63d0\u53d6\u79c1\u94a5\u683c\u5f0f\u6587\u4ef6 (.key) <\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>openssl pkcs12 -in mycert.pfx -nocerts -nodes -out mycert.key     <\/pre>\n<\/div>\n<div title=\"4.7. \u8f6c\u6362 pem \u5230\u5230 spc\">\n<div>\n<div>\n<div>\n<h3>7. \u8f6c\u6362 pem \u5230\u5230 spc<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>   openssl crl2pkcs7 -nocrl -certfile venus.pem  -outform DER -out venus.spc     <\/pre>\n<p>\u7528 -outform -inform \u6307\u5b9a DER \u8fd8\u662f PAM \u683c\u5f0f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>openssl x509 -in Cert.pem -inform PEM -out cert.der -outform DER        <\/pre>\n<\/div>\n<div title=\"4.8. PEM \u5230 PKCS#12 \u7684\u8f6c\u6362\">\n<div>\n<div>\n<div>\n<h3>8. PEM \u5230 PKCS#12 \u7684\u8f6c\u6362<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>openssl pkcs12 -export -in Cert.pem -out Cert.p12 -inkey key.pem        <\/pre>\n<p>IIS \u8bc1\u4e66<\/p>\n<pre>cd c:\\openssl \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000  set OPENSSL_CONF=openssl.cnf \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000  <\/pre>\n<pre>openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt \u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000        <\/pre>\n<p>server.key\u548cserver.crt\u6587\u4ef6\u662fApache\u7684\u8bc1\u4e66\u6587\u4ef6\uff0c\u751f\u6210\u7684server.pfx\u7528\u4e8e\u5bfc\u5165IIS<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<div title=\"4.9. How to Convert PFX Certificate to PEM Format for SOAP\">\n<div>\n<div>\n<div>\n<h3>9. How to Convert PFX Certificate to PEM Format for SOAP<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>$ openssl pkcs12 -in test.pfx -out client.pem  <\/pre>\n<pre>Enter Import Password:  MAC verified OK  Enter PEM pass phrase:  <\/pre>\n<pre>Verifying - Enter PEM pass phrase:  <\/pre>\n<div title=\"4.9. How to Convert PFX Certificate to PEM Format for SOAP\">\n<div>\n<div>\n<div>\n<h3>10. Private Key Convert to RSA<br \/>\n<\/h3>\n<\/div>\n<\/div>\n<\/div>\n<pre>$ openssl rsa -in test.key -out test.rsa<\/pre>\n<p>Enter pass phrase for mail.xbcorp.com.key:<br \/>\nwriting RSA key<\/div>\n<pre> <\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\nPKCS \u5168\u79f0\u662f Public-Key Cryptography Standards \uff0c\u662f\u7531 RSA \u5b9e\u9a8c\u5ba4\u4e0e\u5176\u5b83\u5b89\u5168\u7cfb\u7edf\u5f00\u53d1\u5546\u4e3a\u4fc3\u8fdb\u516c\u94a5\u5bc6\u7801\u7684\u53d1\u5c55\u800c\u5236\u8ba2\u7684\u4e00\u7cfb\u5217\u6807\u51c6\uff0cPKCS \u76ee\u524d\u5171\u53d1\u5e03\u8fc7 15 \u4e2a\u6807\u51c6\u3002 \u5e38\u7528\u7684\u6709\uff1a<br \/>\nPKCS#7 Cryptographic Message Syntax Standard<br \/>\nPKCS#10 Certification Request Standard<br \/>\nPKCS#12 Personal Information Exchange Syntax Standard<br \/>\nX.509\u662f\u5e38\u89c1\u901a\u7528\u7684\u8bc1\u4e66\u683c\u5f0f\u3002\u6240\u6709\u7684\u8bc1\u4e66\u90fd\u7b26\u5408\u4e3aPublic Key Infras...<\/p>\n<p> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/240\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[79],"class_list":["post-240","post","type-post","status-publish","format-standard","hentry","category-article","tag-openssl"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}