Java之keytool命令学习

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参数可以查看更为详细的证书信息

在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章