Java Keytool is a key and certificate management utility. It allows users to manage their own public/private key pairs and certificates. It also allows users to cache certificates. Java Keytool stores the keys and certificates in what is called a keystore. By default the Java keystore is implemented as a file. It protects private keys with a password. A Keytool keystore contains the private key and any certificates necessary to complete a chain of trust and establish the trustworthiness of the primary certificate.
Java keytool是Java提供的一个密钥和证书管理的实用小程序,其为用户提供了自行管理自己的公、私钥对和证书的功能。其存储密钥和证书的地方我们称之为密钥库(keystore),默认情况,密钥库(keystore)是以密码保护的文件的形式存在。keytool密钥库存储了私钥以及任何需要建立安全信任连接所必须的证书。
下面我们看下其简单命令
- 生成密钥库
keytool -genkey -alias csdn -keystore test.jks -storetype pkcs12
注意:如果参数storetype指定为JKS,那么会出现警告信息
Warning:
JKS 密钥库使用专用格式。建议使用 "keytool -importkeystore -srckeystore test.jks -destkeystore test.jks -deststoretype pkcs12" 迁移到行业标准格式 PKCS12。
- 导入证书
keytool -import -file csdn.cer -keystore test.jks
这里,我导入的是CSDN的证书
- 查看证书
keytool -list -keystore test.jks
注意,添加-v参数可以查看更为详细的证书信息