windows下使用openssl

1.下载地址
2.安装
安装目录为:C:\Program Files (x86)\GnuWin32
3.设置环境变量
path后面加上";C:\Program Files (x86)\GnuWin32\bin"
新建一个:OPENSSL_CONF=C:\Program Files (x86)\GnuWin32\share\openssl.cnf

  4.建立相关目录以及文件
我是在D:/openssl下操作,结构如下:
├─demoCA(配置文件种的目录名,存贮一些信息)
│ │ index.txt(文本数据库,签发证书后会更新该数据库)
│ │ serial(序列号文件 赋值1或者其他数字)
│ │
│ └─newcerts(空目录)
├─test(用来存放应用证书等)
├─testCA(用来存放CA等)
5.命令
#构建根证书私钥
genrsa -des3 -out testCA/ca.key 2048
# 签发根证书
req -new -x509 -days 3650 -key testCA/ca.key -out testCA/ca.crt -subj "/C=CN/ST=beijing/L=chaoyang/O=test/OU=test/CN=test-ca"
#根证书转化
pkcs12 -export -inkey testCA/ca.key -in testCA/ca.crt -out testCA/ca.p12
#通过keytool密钥库导入命令importkeystore,将密钥库格式由PKCS#12转换为JKS
keytool -v -importkeystore -srckeystore testCA/ca.p12 -srcstoretype PKCS12 -destkeystore testCA/ca.jks -deststoretype JKS
#构建服务器私钥
genrsa -des3 -out test/test.key 2048
# 生成服务器证书签发申请
req -new -key test/test.key -out test/test.csr -subj "/C=CN/ST=beijing/L=chaoyang/O=test/OU=test/CN=127.0.0.1"
#签发服务器证书
ca -in test/test.csr -out test/test.crt -cert testCA/ca.crt -keyfile testCA/ca.key
#服务器证书转换
pkcs12 -export -inkey test/test.key -in test/test.crt -out test/test.p12
#通过keytool密钥库导入命令importkeystore,将密钥库格式由PKCS#12转换为JKS
keytool -v -importkeystore -srckeystore test/test.p12 -srcstoretype PKCS12 -destkeystore test/test.jks -deststoretype JKS
 
6.详解
genrsa 产生RSA密钥命令
req 产生证书签发申请命令
x509 签发X.509格式证书命令
-days 表示有效天数
-new 表示新请求
-key 密钥
-in 表示输入文件
-out 表示输出文件
-subj 指定用户信息,可以使用泛域名"*.xxxxxx.com"
pkcs12 PKCS#12编码格式证书命令。
-export 表示导出证书
-cacerts 表示仅导出CA证书。
-inkey 表示输入密钥
 
通过keytool密钥库导入命令importkeystore,将密钥库格式由PKCS#12转换为JKS。
keytool -v -importkeystore
-srckeystore testCA/ca.p12
-srcstoretype PKCS12
-srcstorepass 123456
-destkeystore testCA/ca.jks
-deststoretype JKS
-deststorepass 123456
-importkeystore导入密钥库,通过格式设定,我们可以将PKCS#12文件转换为JKS格式。
-v显示详情
-srckeystore 源密钥库
-srcstoretype 源密钥库格式,这里为pkcs12
-srcstorepass 源密钥库密码,这里为123456
-destkeystore 目标密钥库
-deststoretype 目标密钥库格式,这里为jks,默认值也如此
-deststorepass 目标密钥库密码,这里为123456
 

猜你喜欢

转载自389708585.iteye.com/blog/2346582
今日推荐