Java-为什么我可以';是否使用密钥库中的证书别名来枚举证书?

Java-为什么我可以';是否使用密钥库中的证书别名来枚举证书?,java,keystore,pkcs12,Java,Keystore,Pkcs12,您没有获得证书的原因是您没有提供密码。仔细查看您收到的警告: $ openssl pkcs12 -export -out 2.pfx -in server.crt -inkey server.key $ keytool -list -keystore 2.pfx Enter keystore password: ***************** WARNING WARNING WARNING ***************** * The integrity of th

您没有获得证书的原因是您没有提供密码。仔细查看您收到的警告:

$ openssl pkcs12 -export -out 2.pfx -in server.crt -inkey server.key  
$ keytool  -list -keystore 2.pfx  
Enter keystore password:  

*****************  WARNING WARNING WARNING  *****************  
* The integrity of the information stored in your keystore  *  
* has NOT been verified!  In order to verify its integrity, *  
* you must provide your keystore password.                  *  
*****************  WARNING WARNING WARNING  *****************  

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

1, May 9, 2016, PrivateKeyEntry,
如果您对代码进行JUnit测试,并尝试使用密码和不使用密码的密钥存储库,您将看到只有需要密码的密钥存储库才允许您通过此代码获取证书,当然前提是您输入了正确的密码

如果尝试从命令行中提取,您将看到的另一件事是:

*****************  WARNING WARNING WARNING  *****************  
* The integrity of the information stored in your keystore  *  
* has NOT been verified!  In order to verify its integrity, *  
* you must provide your keystore password.                  *  
*****************  WARNING WARNING WARNING  ***************** 
****************警告*****************
*存储在密钥库中的信息的完整性*
*还没有被证实!为了验证其完整性*
*您必须提供密钥库密码*
*****************警告*****************
keytool错误:java.lang.Exception:别名没有证书

Hi@Tom,keystore\u client.getCertificate(别名)返回空值。您检查过哪个别名导致该问题了吗?这也可能意味着,别名存在,但没有为其分配任何证书。嗨@Tom,谢谢你的帮助。我刚刚添加了关于pfx文件的信息。请看一看。别名为“1”。您总是会遇到什么异常?嗨@EJP,抱歉,已编辑。pfx文件没有密码。那么我必须为它添加密码吗?如果你不输入密码,它将无法验证请求。试着给它添加一个密码,看看会发生什么。如果使用类似于提取证书的命令,您将看到“keytool error:java.lang.Exception:Alias没有证书”。尝试此命令行“keytool-keystore 2.pfx-storetype pkcs12-exportcert-alias 1-file server.crt”
*****************  WARNING WARNING WARNING  *****************  
* The integrity of the information stored in your keystore  *  
* has NOT been verified!  In order to verify its integrity, *  
* you must provide your keystore password.                  *  
*****************  WARNING WARNING WARNING  ***************** 
*****************  WARNING WARNING WARNING  *****************
* The integrity of the information stored in your keystore  *
* has NOT been verified!  In order to verify its integrity, *
* you must provide your keystore password.                  *
*****************  WARNING WARNING WARNING  *****************

keytool error: java.lang.Exception: Alias <1> has no certificate