利用keytool 来产生公钥和私钥对以及相关的证书

利用keytool 来产生公钥和私钥对以及相关的证书
2010-10-23 11:31

keytool的使用可以参考:

http://edocs.weblogicfans.net/wls/docs92/secmanage/identity_trust.html#wp1167001

http://java.sun.com/j2se/1.3/docs/tooldocs/win32/keytool.html

现在使用keytool工具来生成证书:

1)使用keytool来生成一个密钥库,其中-strorepass后面的密码是密钥库的密码,而-keypass是私钥的密码
C:\Program Files\Java\jre6\bin>keytool -genkey -dname "CN=hellking-Client,OU=tsi
nghua,O=tsinghua,L=BEIJING,S=BEIJING,C=CN" -storepass 666666 -keystore client.ke
ystore -keyalg RSA -keypass 888888

2)显示client.keystore中的信息,需要输入keystore的密码(666666),显示的为私钥

C:\Program Files\Java\jre6\bin>keytool -list -keystore client.keystore
输入keystore密码:

Keystore 类型: JKS
Keystore 提供者: SUN

您的 keystore 包含 1 输入

mykey, 2010-10-23, PrivateKeyEntry,
认证指纹 (MD5): 63:40:B7:7D:E4:1D:52:8B:C5:0B:26:BD:E8:9E:36:9B

3)从密钥库中导出证书为test_axis.cer,证书中包含了公钥

C:\Program Files\Java\jre6\bin>keytool -export -file test_axis.cer -storepass 66
6666 -keystore client.keystore
保存在文件中的认证 <test_axis.cer>

4)显示证书中的信息如下:

C:\Program Files\Java\jre6\bin>keytool -printcert -file test_axis.cer
所有者:CN=hellking-Client, OU=tsinghua, O=tsinghua, L=BEIJING, ST=BEIJING, C=CN
签发人:CN=hellking-Client, OU=tsinghua, O=tsinghua, L=BEIJING, ST=BEIJING, C=CN
序列号:4cc24cc9
有效期: Sat Oct 23 10:47:37 CST 2010 至Fri Jan 21 10:47:37 CST 2011
证书指纹:
         MD5:63:40:B7:7D:E4:1D:52:8B:C5:0B:26:BD:E8:9E:36:9B
         SHA1:B6:EE:A9:45:88:CE:61:23:9C:C0:7C:31:B2:AC:13:74:05:76:AD:A3
         签名算法名称:SHA1withRSA
         版本: 3

5)把私钥保存到server.truststore中

C:\Program Files\Java\jre6\bin>keytool -import -file test_axis.cer -storepass 66
6666 -keystore server.truststore -alias clientkey -noprompt
认证已添加至keystore中

7)显示server.truststore

C:\Program Files\Java\jre6\bin>keytool -list -keystore server.truststore
输入keystore密码:

Keystore 类型: JKS
Keystore 提供者: SUN

您的 keystore 包含 1 输入

clientkey, 2010-10-23, trustedCertEntry,
认证指纹 (MD5): 63:40:B7:7D:E4:1D:52:8B:C5:0B:26:BD:E8:9E:36:9B

keytool的参考示例:http://www.360doc.com/content/10/0121/10/633992_14065815.shtml

keytool密钥和证书管理工具-使用详解:http://www.51testing.com/?uid-16403-action-viewspace-itemid-87545

利用java程序导出,私钥,java代码可以参考:http://lukejin.javaeye.com/blog/586073

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值