java 中keytool命令的使用

来源:互联网 发布:vmware中文破解版 mac 编辑:程序博客网 时间:2024/04/30 14:10

例如:

生成数字证书

keytool -genkeypair -keyalg RSA -keysize 2048 -sigalg SHA1withRSA -validity  36000 -alias tomcat -keystore zlex.keystore 

参数:

-genkeypair 表示生成密钥

-keyalg 指定密钥算法,这里指定为RSA算法

-keysize 指定密钥长度,默认1024位,这里指定为2048位

-sigalg 指定数字签名算法,这里指定为SHA1withRSA算法

-validity 指定证书有效期,这里指定为36000天

-alias 指定别名,这里是tomcat

-keystore 指定密钥库存储位置,这里是zlex.keystore

其他 -storetype keystore的类型

 

导出数字证书

keytool -exportcert -alias tomcat -keystore zlex.keystore -file zlex.cer -rfc 

参数:

-exportcert 表示证书导出操作

-alias 指定导别名,这里为tomcat

-keystore 指定密钥库文件,这里为zlex.keystore

-file 指定导出文件路径,这里为zlex.cer

-rfc 指定以Base64编码格式输出

 

打印数字证书

keytool -printcert -file zlex.cer

 

构建CA签名证书

keytool -certreq -alias tomcat -keystore zlex.keystore -file zlex.csr -v

参数:

-certreq 表示数字证书申请操作

-alias 指定别名,这里为tomcat

-keystore 指定密钥库文件,这里为zlex.keystore

-file 指定导出文件路径,这里为zlex.csr

-v 详细信息

 

 

导入数字证书

keytool -importcert -trustcacerts -alias tomcat -file zlex.cer -keystore zlex.keystore

参数

-importcert 表示导入数字证书

-trustcacerts 表示将数字证书导入信任库

-alias 指定导别名,这里为tomcat

-file 指定导入数字证书文件路径,这里为zlex.cer

-keystore 指定密钥库文件,这里为zlex.keystore

 

查看导入数字证书

keytool -list -alias tomcat -keystore zlex.keystore

参数:

-list 表示导入数字证书

-alias 指定别名,这里为tomcat

-keystore 指定密钥库文件,这里为zlex.keystore