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參數可以查看更爲詳細的證書信息

在這裏插入圖片描述

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