keytool命令

本文详细介绍了如何使用keytool工具生成keystore文件、p12文件,以及如何从这些文件中导出私钥和公钥证书。还涵盖了将不同格式的密钥库相互转换的操作,包括jks到p12,p12到keystore,以及pfx到jks的转换。此外,还讲解了查看keystore信息的方法,对于涉及密钥管理和证书转换的IT专业人员来说是一份实用的参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

keystore生成密钥工具

1.生成keystore文件

对应目录下,打开命令窗口cmd,执行如下命令:

keytool -genkey -alias ynhr -keyalg RSA -keysize 1024 -keypass 123456 -validity 36500 -keystore test.keystore -storepass 123456

命令解读:

-alias 别名:ynhr

-keyalg 算法:RSA

-keysize 密码长度:1024

-keypass 私钥访问密码:123456

-validity 有效期:36500天

-keystore 名称:test.keystore

-storepass keystone文件访问密码:123456

命令执行完毕后,在目录下就会生成对应的 test.keystore 文件。

2.通过keystore导出p12文件

keytool -importkeystore -srcstoretype JKS -srckeystore test.keystore -srcstorepass 123456 -srcalias ynhr -srckeypass 123456 -deststoretype PKCS12 -destkeystore test.p12 -deststorepass 123456 -destalias client -destkeypass 123456 -noprompt

3.从p12导出.key私钥文件

openssl pkcs12 -in test.p12 -nocerts -nodes -out test.key

4.从keystore导出cer公钥证书

keytool -export -alias ynhr -keystore test.keystore -rfc -file test.cer

有时候需要.crt格式的文件,调整下格式即可

keytool -export -alias ynhr -keystore test.keystore -rfc -file test.crt

5.查看keystore信息

keytool -v -list -keystore file.keystore

6.jks文件转为p12文件

keytool -importkeystore -srckeystore ‪x:\xxx\xxx.jks(jks文件路径) -srcstoretype JKS -deststoretype PKCS12 -destkeystore x:\xxx\xxx.p12(后缀改为p12)

7.p12文件转为keystore文件

keytool -v -importkeystore -srckeystore x:\xxx\xxx.p12(p12文件路径) -srcstoretype PKCS12 -destkeystore x:\xxx\xxx.keystore -deststoretype JKS

8.pfx文件转jks文件

keytool -importkeystore -srckeystore com.cn.pfx -destkeystore PEP.jks -srcstoretype PKCS12 -deststoretype JKS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值