Java 如何访问 jvm 默认密钥库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9837562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:23:36  来源:igfitidea点击:

How to acess jvm default KeyStore?

javasecurityjvmcertificate

提问by bhavesh1988

I want to use java key store to save keys and certificates. can anybody share some code to help me with this?

我想使用 java 密钥库来保存密钥和证书。有人可以分享一些代码来帮助我吗?

采纳答案by Chris White

There should be enough example code in the KeyStore Javadocs page to get you started:

KeyStore Javadocs 页面中应该有足够的示例代码来帮助您入门:

As for the 'default' keystore - I'm not sure such a thing exists, normally you either load it explicitly from a file, or you can configure it using the following system properties:

至于“默认”密钥库 - 我不确定是否存在这样的东西,通常您可以从文件中显式加载它,或者您可以使用以下系统属性对其进行配置:

  • javax.net.ssl.keyStore - Keystore location
  • javax.net.ssl.keyStorePassword - Keystore password
  • javax.net.ssl.keyStoreType - Keystore type (JKS, P12 etc)
  • javax.net.ssl.keyStore - 密钥库位置
  • javax.net.ssl.keyStorePassword - 密钥库密码
  • javax.net.ssl.keyStoreType - 密钥库类型(JKS、P12 等)

And similar for the trust store:

与信任商店类似:

  • javax.net.ssl.trustStore
  • javax.net.ssl.trustStorePassword
  • javax.net.ssl.trustStoreType
  • javax.net.ssl.trustStore
  • javax.net.ssl.trustStorePassword
  • javax.net.ssl.trustStoreType

回答by Bruno

There is no default keystore in Java. This is documented in the customization section of the JSSE Reference Guide.

Java 中没有默认的密钥库。这记录在JSSE 参考指南定制部分

The default trust store is:

默认信任存储是:

jssecacerts, if it exists. Otherwise, cacerts

jssecacerts,如果它存在。否则,cacerts

However, it doesn't mean that these are the stores used by the default SSLContext, since it's also possible to change the default SSLContext(since Java 6) with one that would have been initialised with custom trust managers. (See this answerfor more details).

但是,这并不意味着这些是 default 使用的存储SSLContext,因为也可以SSLContext使用自定义信任管理器初始化的存储来更改默认值(自 Java 6 起)。(有关更多详细信息,请参阅此答案)。