使用keytool和OpenSSL创建证书并保存到keystore(步骤)
=============================
1、创建一个密钥对并生成一个keystore
D:\bea81\user_projects\domains\proxydomain\certs>keytool -keystore pp.jks -genkeypair -alias mycert
输入keystore密码:<输入证书库密码>
再次输入新密码: <输入证书库密码>
您的名字与姓氏是什么?
[Unknown]: mycert
您的组织单位名称是什么?
[Unknown]: DP
您的组织名称是什么?
[Unknown]: WS
您所在的城市或区域名称是什么?
[Unknown]: XM
您所在的州或省份名称是什么?
[Unknown]: FJ
该单位的两字母国家代码是什么
[Unknown]: CN
CN=mycert, OU=DP, O=WS, L=XM, ST=FJ, C=CN 正确吗?
[否]: y
输入<mycert>的主密码
(如果和 keystore 密码相同,按回车): <输入证书库密码>
再次输入新密码: <输入证书库密码>
=============================
2、根据刚才生成的密钥对生成一个证书请求:
D:\bea81\user_projects\domains\proxydomain\certs>keytool -keystore pp.jks -certreq -alias MyCert -file mycert.csr
输入keystore密码: <输入证书库密码>
3、根据证书请求用OpenSSL签发证书
D:\tools\编程\CA\OpenSSL1>openssl ca -config .\openssl.conf -policy policy_anything -notext -in .\mycert.csr -out .\mycert.crt
Using configuration from .\openssl.conf
Loading 'screen' into random state - done
Enter pass phrase for .\\CA\private\CAkey.pem: <输入根证书密码>
DEBUG[load_index]: unique_subject = "yes"
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'XM'
localityName :PRINTABLE:'FJ'
organizationName :PRINTABLE:'WS'
organizationalUnitName:PRINTABLE:'DP'
commonName :PRINTABLE:'SHENG'
Certificate is to be certified until Nov 10 17:47:31 2009 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
=============================
3、把根证书导入证书库
D:\bea81\user_projects\domains\proxydomain\certs>keytool -keystore pp.jks -importcert -alias root -file CAcert.pem
输入keystore密码: <输入证书库密码>
所有者:EMAILADDRESS=SHENGROOT@YAHOO.COM, CN=SHENGROOT, OU=DP, O=WS, L=XM, ST=FJ, C=CN
签发人:EMAILADDRESS=SHENGROOT@YAHOO.COM, CN=SHENGROOT, OU=DP, O=WS, L=XM, ST=FJ, C=CN
序列号:ebd62446d8ecd9e2
有效期: Tue Nov 11 00:35:35 CST 2008 至Thu Dec 11 00:35:35 CST 2008
证书指纹:
MD5:80:90:61:43:A6:C6:3A:1C:5B:EC:6F:D4:14:73:8A:CD
SHA1:16:8B:E7:D6:04:90:E3:3D:5A:A8:41:61:AA:32:87:03:F7:E1:A8:CF
签名算法名称:MD5withRSA
版本: 3
扩展:
#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 40 F6 C7 13 28 65 AC 9B 1F 2B 58 BF 3A BA 6D 64 @...(e...+X.:.md
0010: 34 36 18 31 46.1
]
]
#2: ObjectId: 2.5.29.19 Criticality=false
BasicConstraints:[
CA:true
PathLen:2147483647
]
#3: ObjectId: 2.5.29.35 Criticality=false
AuthorityKeyIdentifier [
KeyIdentifier [
0000: 40 F6 C7 13 28 65 AC 9B 1F 2B 58 BF 3A BA 6D 64 @...(e...+X.:.md
0010: 34 36 18 31 46.1
]
[EMAILADDRESS=SHENGROOT@YAHOO.COM, CN=SHENGROOT, OU=DP, O=WS, L=XM, ST=FJ, C=CN]
SerialNumber: [ ebd62446 d8ecd9e2]
]
信任这个认证? [否]: y
认证已添加至keystore中
注:
如果不导入根证书而直接操作下面一步的话,会得到一个错误:
D:\bea81\user_projects\domains\proxydomain\certs>keytool -keystore pp.jks -importcert -alias mycert -file mycert.der
输入keystore密码:
keytool错误: java.lang.Exception: 无法从回复中建立链接
=============================
4、把生成的证书导入到keystore
D:\bea81\user_projects\domains\proxydomain\certs>keytool -keystore pp.jks -importcert -alias mycert -file mycert.crt
输入keystore密码: <输入证书库密码>
认证回复已安装在 keystore中