1.建立根证书
(1)生成私钥
openssl genrsa -des3 -out CAroot.key 2048。产生一个2048位的私钥,在安装的openssl目录下调用openssl命令。
命令详解:
- genrsa: Generation of RSA Private Key.
- des3:Triple Des加密算法,支持其他加密算法,aes256、base64、chacha20等
需要输入私钥保护口令,产生CAroot.key文件。
(2)生成证书请求
openssl req -new -key CAroot.key -out rootca.csr -config D:OpensslInstallopenssl.cnf
- req: This command primarily creates and processes certificate requests (CSRs) in PKCS#10 format. It can additionally create self-signed certificates for use as root CAs for example.
- new :This option generates a new certificate request. It will prompt the user for the relevant field values. The actual fields prompted for and their maximum and minimum sizes are specified in the configuration file and any requested extensions.
If the -key option is not given it will generate a new private key using information specified in the configuration file or given with the -newkey and -pkeyopt options, else by default an RSA key with 2048 bits length.
需要输入CAroot.key私钥保护口令。
根据提示输入:国家、省份、组织名、邮箱、等信息。
最后生成rootca.csr证书请求文件。
(本人将编译安装过程中产生的openssl.cnf文件拷贝到D:OpensslInstall目录下)
(3)签发证书
openssl req -x509 -days 666 -key rootca.key -in rootca.csr -out CARoot.crt -config D:OpensslInstallopenssl.cnf
最后生成自签名的根证书 CARoot.crt.。
下面将介绍以CARoot.crt为根证书签发下级证书的过程。
(1)生成自己的私钥。
openssl genrsa -des3 -out myprivate.key 1024
(2)生成证书请求文件
openssl req -new -key myprivate.key -out MyCaReq.csr -config D:OpensslInstallopenssl.cnf
(3)根证书签发下级证书
openssl x509 -req -in MyCaReq.csr -out MyCa.crt -signkey myprivate.key -CA CARoot.crt -CAkey rootca.key
-CAcreateserial -days 990
签发的证书制作完成。
OpenSSL 1.0.0生成p12、jks、crt等格式证书的命令个过程
此生成的证书可用于浏览器、Java、tomcat、c++等。在此备忘!
1.创建根证私钥
命令:
openssl genrsa -out root-key.key 1024
2.创建根证书请求文件
命令:
openssl req -new -out root-req.csr -key root-key.key -keyform PEM
3.自签根证书
命令:
openssl x509 -req -in root-req.csr -out root-cert.cer -signkey root-key.key -CAcreateserial -days 3650
4.导出p12格式根证书
命令:
openssl pkcs12 -export -clcerts -in root-cert.cer -inkey root-key.key -out root.p12
5.生成root.jks文件
keytool -import -v -trustcacerts -storepass 123456 -alias root -file root-cert.cer -keystore
root.jks
生成客户端文件:
1.生成客户端key
openssl genrsa -out client-key.key 1024
2.生成客户端请求文件
openssl req -new -out client-req.csr -key client-key.key
3.生成客户端证书(root证书,rootkey,客户端key,客户端请求文件这4个生成客户端证书)
openssl x509 -req -in client-req.csr -out client-cert.cer -signkey client-key.key -CA root-cert.cer
-CAkey root-key.key -CAcreateserial -days 3650
4.生成客户端p12格式根证书
openssl pkcs12 -export -clcerts -in client-cert.cer -inkey client-key.key -out client.p12
客户端jks:
keytool -import -v -trustcacerts -storepass 123456 -alias client -file client-cert.cer -keystore
client.jks
生成服务端文件:
1.生成服务端key
openssl genrsa -out server-key.key 1024
2.生成服务端请求文件
openssl req -new -out server-req.csr -key server-key.key
3.生成服务端证书(root证书,rootkey,客户端key,客户端请求文件这4个生成客户端证书)
openssl x509 -req -in server-req.csr -out server-cert.cer -signkey server-key.key -CA root-cert.cer
-CAkey root-key.key -CAcreateserial -days 3650
4.生成服务端p12格式根证书
openssl pkcs12 -export -clcerts -in server-cert.cer -inkey server-key.key -out server.p12
服务端JKS
keytool -import -v -trustcacerts -storepass 123456 -alias server -file server-cert.cer -keystore
server.jks
无密码key命令:
openssl rsa -in client-key.key -out client-key.key.unsecure
以上产生的Base64编码方式,PEM、cer,crt
DER编码方式也是有DER .Cer, crt后缀。
PEM–DER/CER(BASE64–DER编码的转换)
openssl x509 -outform der -in certificate.pem -out certificate.der
PEM–P7B(PEM–PKCS#7)
openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer
PEM–PFX(PEM–PKCS#12)
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt
PEM–p12(PEM–PKCS#12)
openssl pkcs12 -export -out Cert.p12 -in Cert.pem -inkey key.pem
CER/DER–PEM(编码DER–BASE64)
openssl x509 -inform der -in certificate.cer -out certificate.pem
P7B–PEM(PKCS#7–PEM)
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
P7B–PFX(PKCS#7–PKCS#12)
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer
PFX/p12–PEM(PKCS#12–PEM)
openssl pkcs12 -in certificate.pfx -out certificate.cer
如无需加密pem中私钥,可以添加选项-nodes;
如无需导出私钥,可以添加选项-nokeys;
PEM BASE64–X.509文本格式
openssl x509 -in Key.pem -text -out Cert.pem
PFX文件中提取私钥(.key)
openssl pkcs12 -in mycert.pfx -nocerts -nodes -out mycert.key
PEM–SPC
openssl crl2pkcs7 -nocrl -certfile venus.pem -outform DER -out venus.spc
PEM--PVK(openssl 1.x开始支持)
openssl rsa -in mycert.pem -outform PVK -pvk-strong -out mypvk.pvk
PEM--PVK(对于openssl 1.x之前的版本,可以下载pvk转换器后通过以下命令完成)
pvk -in ca.key -out ca.pvk -nocrypt -topvk
d2i_X509_AUX或者函数d2i_X509()将DER编码大的证书转化为OpenSSL中的X509结构,便于、、读写操作、、
参考链接:
http://t.zoukankan.com/kenshinobiy-p-7441819.html