對這文章發表回應
發表限制: 非會員 可以發表
keytool指令整理
JDK提供keytool指令來進行私鑰(private key)及其相對應證書(certificate)的管理,並將其放置於keystore中(預設為一個檔案,也可用其它媒體來儲存)。
keytool可用來產生self-signed certificate, 發出certificate sign request(CSR), 使用digital signature, 及以證書的方式來存放communication peers的公鑰。
certificate(證書)是經由數位簽章過的statement,其代表一個實體(entity),可以是公司, 個人等。certificate可用以達到資料完整性(Data Integrity)及身份認證(Authentication)的需求。
JDK提供的另一個指令jarsigner,則可利用certificate裡的資訊來 產生(generate)或 驗證(verify)JAR檔所使用的數位簽章。
keystore
在java.security package中的KeyStore class是一個介面,其實作可以由不同的provider來提供(在程式中產生KeyStore時指定)。不同的provider提供不同型態的keystore,且彼此不相容。預設的keystore type為 JKS(java keystore),另一種則為 pkcs12。
keystore中包含兩種項目,一個是key entries; 另一個則是certificate entries,在存取這兩種項目時,都需透過其alias(別名)來存取。
支援的加密演算法
key-pair:DSA(預設) ==> signature: SHA1withDSA
key-pair:RSA ==> signatureMD5withRSA
支援的證書格式
X.500
X.509
RFC 1421
這些標準規定了証書可以包含什麼資訊,並說明怎麼記錄(數據格式) 。除了簽名外,証書還包含以下數據:
版本 序列號 簽名算法標識符 簽發人姓名 有效期 主體名 主體公鑰資訊
指令語法
1. 產生金錀對
keytool -genkey -alias xxx -keyalg RSA -keystore .keystore
2. 查詢keystore
keytool –list –v –keystore .keystore
3. 刪除keystore內的其中一個憑證
keytool –delete –alias xxx –keystore .keystore
4. 匯入憑證到keystore
keytool –import –alias xxx –file xxx.cer –keystore .keystore
5. 產生憑證申請檔
keytool -certreq -alias xxx -file certreq.txt -keystore .keystore
6. 查詢PKCS12類型keystore的內容
keytool –list –v –keystore .keystore -storetype pkcs12
7. 建立一個含有私鑰的keystore
keytool -genkey -alias keyAlias -keyalg RSA -keystore keystore.jks
8. 修改keystore的密碼
keytool -storepasswd -new newPassword -keystore keystore.jks
註: 當使用 -genkey, -import, -identitydb 指令時,當指定的keystore不存在時,此時便會產生一個新的keystore檔案,若沒指定檔名,則預設名稱為”.keystore”。
例:產生Tomcat使用的keystore(內含私鑰及certificate)
keytool -genkey -alias tomcat -keyalg RSA –keystore yourstorepath
在產生的過程中,keystore pwd及private key pwd要設成一致,預設密碼為 “changeit”。
References:
http://cooking-java.blogspot.tw/2010/01/java-keytool.html
http://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/keytool.html
http://debut.cis.nctu.edu.tw/Demo/HighCapacityImageSteganographicTool/stego/security.htm
原文出處:keytool指令整理 - 華勒斯筆記本