耶耶耶耶耶 发表于 2024-7-17 02:06:17

【全】OpenSSL创建生成CA证书、服务器、客户端证书及密钥说明

本文章对应的文档:使用OpenSSL创建生成CA证书服务器客户端证书及密钥资源-CSDN文库

https://download.csdn.net/download/weixin_41885845/88746920
对于SSL单向认证

服务器须要CA证书、server证书、server私钥,客户端须要CA证。
https://img-blog.csdnimg.cn/direct/f95a71305add408f991a2e03d4a865c9.png
对于SSL双向认证

服务器须要CA证书、server证书、server私钥,客户端须要CA证书,client证书、client私钥。
https://img-blog.csdnimg.cn/direct/6f4ee670715e46b1a93272b4ab3c2740.png
生成CA证书

私钥生成指令: openssl genrsa

该命令是会用来生成 RSA 私有秘钥,不会生成公钥,因为公钥提取自私钥。
   opensslgenrsa [-out filename] [-passout arg] [-f4] [-3] [-rand file(s)] [-engine id] [-des] [-des3] [-idea]
   
    -des            encrypt the generated key with DES in cbc mode
   -des3         encrypt the generated key with DES in ede cbc mode (168 bit key)
   -idea         encrypt the generated key with IDEA in cbc mode
   -seed
                   encrypt PEM output with cbc seed
   -aes128, -aes192, -aes256
                   encrypt PEM output with cbc aes
   -camellia128, -camellia192, -camellia256
                   encrypt PEM output with cbc camellia
   -out file       output the key to 'file
   -passout arg    output file pass phrase source
   -f4             use F4 (0x10001) for the E value
   -3            use 3 for the E value
   -engine e       use engine e, possibly a hardware device.
   -rand file:file:...
                   load the file (or the files in the directory) into
                      the random number generator
    -des             使用des cbc模式对私钥文件进行加密。
-des3            使用des3 cbc模式对私钥文件进行加密。
-idea            使用idea cbc模式对私钥文件进行加密。
-aes128, -aes192, -aes256               使用aes cbc模式对私钥文件进行加密。
-out file      指定输出私钥文件名。
-f4                        指定F4做为E值,默认。
-3                        指定3做为E值。
-seed arg             指定cbc的随机种子。
-rand file:file 指定随机数种子文件。
———————————————————————————————————————
-out filename :将生成的私钥生存至filename文件,若未指定输出文件,则为标准输出。
                                    
-numbits :指定要生成的私钥的长度(单元 bit),默认为1024。该项必须为命令行的末了一项参数。

-des|-des3|-idea:指定加密私钥文件用的算法,这样每次使用私钥文件都将输入密码,太麻烦以是很少使用。

-passout args :加密私钥文件时,传递密码的格式,如果要加密私钥文件时单未指定该项,则提示输入密码。传递密码的args的格式见openssl密码格式。

测试

1、 openssl genrsa -seed -out rs_pri.pem 512

https://img-blog.csdnimg.cn/direct/d3d4dcda786b427586ad540f96f49364.png
https://img-blog.csdnimg.cn/direct/8f1d636a09a942da81cb26478f7996e4.png
2、 openssl genrsa -aes256 –out rs_pri.key 512

https://img-blog.csdnimg.cn/direct/998ba24017624a1d93e3d95e5d3d73ca.png
https://img-blog.csdnimg.cn/direct/230bd17c1209488c9ccdfb601e9d95fb.png
3、 openssl genrsa -des3 -out test.key-rand hello.txt 512

https://img-blog.csdnimg.cn/direct/0899e81ae131404c9f27f6e90f673ddf.png
https://img-blog.csdnimg.cn/direct/83db064ed8f24da7a1813b547887f4a1.png
4 、openssl genrsa -des -passout pass:"123456" -out prikey.pem 1024

https://img-blog.csdnimg.cn/direct/cd1dcf77783840ef89f825f4d6c0b256.png
https://img-blog.csdnimg.cn/direct/e1be2f5e3e884a458069e60518bf3db5.png
请求CA证书(先创建CA证书私钥)

   C-----国家(Country Name)
ST----省份(State or Province Name)
L----城市(Locality Name)
O----公司(Organization Name)
OU----部门(Organizational Unit Name)
CN----产品名(Common Name)
emailAddress----邮箱(Email Address)

req指令

主要用于创建证书请求文件;

          openssl req <infile> outfile
      -inform arg            指定输入文件格式,可以为DER或PEM,默认为PEM。
    -outform arg            指定输出文件格式,可以为DER或PEM,默认为PEM。
-in arg                     指定输入文件。
-out arg                      指定输出文件。
-new                        创建新的证书请求文件。
-key file                   指定创建证书请求的私钥文件。
-keyform arg            指定创建证书请求的私钥文件的格式,可以为DER或PEM,默认为PEM。
-passin arg            指定私钥文件的口令保护泉源。
-verify                      校验证书请求文件的主体签名是否有效。
-noout                        不打印证书请求信息。
-text                           文本打印证书请求文件。
-modulus                  输出证书请求的模数信息。
-subject                      输出证书请求主体信息。
-subj arg                     设置或修改证书请求的主体信息。
-multivalue-rdn   设置或修改证书请求的主体信息时,答应多RDN格式。
-utf8                           输入字符为utf8编码,默认输入为ASCII编码。
-                     指定创建证书请求的摘要算法。
   -pubkey                      提取证书请求文件中的公钥。
    x509指令

主要用于创建、修改x509证书。

   openssl x509 <infile >outfile
       -inform arg               指定输入文件格式,可以为DER或PEM,默认为PEM。
   -outform arg            指定输出文件格式,可以为DER或PEM,默认为PEM。
   -keyform arg            指定私钥文件格式,可以为DER或PEM,默认为PEM。
   -CAform arg               指定CA文件格式,可以为DER或PEM,默认为PEM。
<
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 【全】OpenSSL创建生成CA证书、服务器、客户端证书及密钥说明