使用keytool在密钥库中“密钥密码”的意义是什么

G.S*_*G.S 8 java keystore keytool ssl-certificate

我使用以下命令为我的Web应用程序生成了jks。

keytool -genkey -keyalg RSA -alias my-app -validity 10800 -keysize 2048 -sigalg SHA1withRSA -keystore myapp.jks
Run Code Online (Sandbox Code Playgroud)

该命令提示了一些问题,如下所示:

Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:  GS
What is the name of your organizational unit?
  [Unknown]:  XX
What is the name of your organization?
  [Unknown]:  YY
What is the name of your City or Locality?
  [Unknown]:  ZZ
What is the name of your State or Province?
  [Unknown]:  AA
What is the two-letter country code for this unit?
  [Unknown]:  BB
Is CN=GS, OU=XX, O=YY, L=ZZ, ST=AA, C=BB correct?
  [no]:  yes

Enter key password for <my-app> //Why this password is required???
        (RETURN if same as keystore password):  
Run Code Online (Sandbox Code Playgroud)

只有在密钥库密码(首次提示)和密钥密码都使用时,Tomcat才能读取此密钥库。当我使用其他密码代替“密钥密码”时,由于密钥库文件,tomcat无法启动。
我的问题是密钥密码的意义是什么?

PS:我看到了此链接。他们在这里说:

Press RETURN when prompted for the key password (this action makes the key password the same as the KeyStore password).
Run Code Online (Sandbox Code Playgroud)

如果两个密码必须相同,那么知道两次输入密码有什么意义?

Maa*_*aas 7

JavaDoc所述

提示您输入的密钥密码值指定将要生成的私钥的密码。您将始终需要此密码才能访问包含该密钥的密钥库条目。该条目不必具有自己的密码。当提示您输入密钥密码时,可以选择与密钥库密码相同。

密钥库可以包含多个密钥,并且每个密钥只能使用密码进行访问。因此,如果您希望保持密钥密码与创建的密钥库相同,keytool只是给您一个选择。


Sus*_*Sah 5

正如@Maas 已经回答的那样,访问存储在 KeyStore 中的密钥条目需要 keyPassword。

它发生的方式是首先使用 KeyStore 密码来访问/解锁 KeyStore,然后使用 keyPassword 解密该 KeyStore 中的密钥条目。

通常,ssl 的各种实现/使用考虑对 KeyStorePassword 和 keyPassword 使用相同的密码

在 tomcat 中也是如此。如果你看到文档tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html他们已经明确指出“你的私钥密码和密钥库密码应该相同。如果它们不同,你会得到一个错误java.io.IOException 的行:无法恢复密钥,如Bugzilla 问题 38217 中所述,其中包含对此问题的进一步参考”

在此处输入图片说明

甚至 JSSE 实现也希望 KeyStorePassword 和 KeyPassword 相同。

在此处输入图片说明

https://access.redhat.com/documentation/en-US/Fuse_MQ_Enterprise/7.1/html/Security_Guide/files/SSL-SysProps.html

https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#KeyManagerFactory