JDK中利用keytool创建自签名证书

1、创建一个密钥库mycomstore别名my(服务器端密钥库)
keytool -genkey -dname "CN=www.my.com, OU=NC, O=Shanghai University, L=ZB, ST=Shanghai, C=CN" -alias my -keyalg RSA -keystore mycomstore -keypass wshr.ut -storepass wshr.ut -validity 4000
在文件中C:\WINDOWS\system32\drivers\etc\hosts增加127.0.0.1 www.my.com

2、导出自己创建的密钥库mycomstore别名my的证书为www.my.com.cer (服务器端证书)
keytool -export -alias my -file www.my.com.cer -keystore mycomstore -storepass wshr.ut

3、创建一个密钥库mykeystore别名mytest(客户端密钥库)
keytool -genkey -dname "CN=Xu Yingxiao, OU=Network Certer, O=Shanghai University, L=ZB, ST=Shanghai, C=CN" -alias mytest -keyalg RSA -keystore mykeystore -keypass wshr.ut -storepass wshr.ut -validity 4000

4、导出自己创建的密钥库mykeystore别名mytest的证书为mytest.cer(客户端证书)
keytool -export -alias mytest -file mytest.cer -keystore mykeystore -storepass wshr.ut

5、通过JAVA程序进行证书签名(签发者是密钥库mykeystore中的mytest条目,待签发者是www.my.com.cer)
程序会产生一个新的密钥库newstore密钥newpass;别名是lf_signed

6、导出密钥库newstore中的别名为lf_signed为证书mycomsigned.cer
keytool -export -file mynew.cer -keystore newstore -storepass newpass -alias lf_signed

7、在密钥库mycomstore中引入mytest.cer证书
keytool -import -alias camytest -keystore mycomstore -file mytest.cer -storepass wshr.ut

8、在密钥库mycomstore中引入mynew.cer证书别名为my(也就是进行安装)
keytool -import -alias my -keystore mycomstore -file mynew.cer -storepass wshr.ut

9、把证书mytest.cer发送给客户端进行安装
双击mytest.cer-->点击安装证书-->下一步-->将所有证书放入下列存储区,浏览-->受信任的根证书颁发机构-->确定-->下一步-->完成-->是-->导入成功,确定-->确定;完成安装

=========================================

所有步骤执行过程如下:

D:\>keytool -genkey -dname "CN=www.my.com, OU=NC, O=Shanghai University, L=ZB, ST=Shanghai, C=CN" -a
lias my -keyalg RSA -keystore mycomstore -keypass wshr.ut -storepass wshr.ut -validity 4000

D:\>keytool -genkey -dname "CN=Xu Yingxiao, OU=Network Certer, O=Shanghai University, L=ZB, ST=Shang
hai, C=CN" -alias mytest -keyalg RSA -keystore mykeystore -keypass wshr.ut -storepass wshr.ut -valid
ity 4000

D:\>keytool -export -alias my -file www.my.com.cer -keystore mycomstore -storepass wshr.ut
保存在文件中的认证 <www.my.com.cer>

D:\>keytool -export -alias mytest -file mytest.cer -keystore mykeystore -storepass wshr.ut
保存在文件中的认证 <mytest.cer>

JAVA程序签名证书。

D:\>keytool -export -file mynew.cer -keystore newstore -storepass newpass -alias lf_signed
保存在文件中的认证 <mynew.cer>

D:\>keytool -import -alias camytest -keystore mycomstore -file mytest.cer -storepass wshr.ut
所有者:CN=Xu Yingxiao, OU=Network Certer, O=Shanghai University, L=ZB, ST=Shanghai, C=CN
签发人:CN=Xu Yingxiao, OU=Network Certer, O=Shanghai University, L=ZB, ST=Shanghai, C=CN
序列号:4cbeebcc
有效期: Wed Oct 20 21:17:00 CST 2010 至Sat Oct 02 21:17:00 CST 2021
证书指纹:
         MD5:77:9F:1E:C0:A1:FF:17:A4:93:38:77:31:26:39:8A:EB
         SHA1:7F:1B:00:83:D4:AA:57:01:26:27:26:D8:63:92:DE:80:6A:A0:A3:2B
         签名算法名称:SHA1withRSA
         版本: 3
信任这个认证? [否]:  是
认证已添加至keystore中

D:\>keytool -import -alias my -keystore mycomstore -file mynew.cer -storepass wshr.ut
认证回复已安装在 keystore中



tomcat中的配置为:C:\Javadevelop\Tomcat6.0\conf\server.xml
<Connector port="443" minSpareThreads="5" maxSpareThreads="75" 
				enableLookups="true" disableUploadTimeout="true" 
				acceptCount="100" maxThreads="200" 
				scheme="https" secure="true" SSLEnabled="true" 
				clientAuth="false" sslProtocol="TLS" 
				keystoreFile="C:\\Users\\yaodaqing\\tmp\\mycomstore" keystorePass="wshr.ut"
				truststoreFile="C:\\Users\\yaodaqing\\tmp\\mykeystore" truststorePass="wshr.ut"/>

你可能感兴趣的:(jdk,tomcat,C++,c,C#)