Creating Keys Using Java Keytool

The Java keytool application manages a  database of keys  and certificates.Users can create their own self-authenticated certificates and public/private key pairs.

1.Create A Pair Of Keys

In the open terminal/command window, type:

keytool –genkey –alias %alias% -keystore %keystore%

  Replacing  %alias%  with a name for your pair of keys and %keystore% with a name for your keystore, then press Enter.In this example, %alias% is KeyPair_1, and %keystore% is MyPrivateKey.store.Once you have completed these steps, your keystore will be saved on the computer.  It may be saved in your Documents folder, /home folder, or on the root drive.

2.Export A Certificate

In the terminal/command window, type:

keytool –export   –alias  %alias% -file  %file% -keystore %keystore%
  Replacing  %alias% and %keystore%   with the values you used previously, and %file% with the name you would like to save your certificate as.In this example, %file% is Certificate1.cert, but you should name yours something different.You will also be asked for the keystore password.It will be saved in the same location as the keystore(usually your Documents or /home folder or the root drive).

3.Import A Certificate

In the terminal/command window, type:

keytool –import   –alias  %alias%   -file  %file% -keystore %keystore%
  Where %alias%  and %keystore% are  differen   t values than you used previously, and %file% is the name of the file you saved your certificate to.You will also be asked to create a password for this new keystore. 
Usually you want to import your cetificate to jre's keystore,now fllowing steps:
cd  /usr/java/jdk/jdk1.6.0_29/jre/lib/security  # cd your $java_home/jre/lib/security

then import to jre keystore:

sudo  keytool -import -alias test -file /home/guolei/client.cert -keystore cacerts

jre's keystore default password is changeit,type the password,then everything is ok.




转载于:https://my.oschina.net/xishuixixia/blog/87951

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值