有谁知道如何在 Java 中使用没有密钥库的 StartCom SSL 或使用自定义密钥库?

发布于 2024-12-14 08:20:57 字数 718 浏览 2 评论 0 原文

我找到了以下帖子,我认为我可能会有所帮助,因为我需要一种验证我的网站(我的 java 应用程序连接到的)的方法,而无需使用 java 密钥库:

http://www.mombu.com/programming/java/t-ssl-for-java-without-keystores-1366416.html

但是,我对这个世界还很陌生SSL 并且不知道我需要使用哪些文件和密码,所以如果有人能给我指出正确的方向,那就太好了。如果您没有猜到,我从 StartSSL 获得了我的 SSL 证书,该证书由 StartCom Ltd 运营/拥有/某物。这是我用来将详细信息放入密钥库的帖子:

https://forum.startcom.org/viewtopic.php?t=1390

提前致谢!

或者,我有什么办法可以使用自定义密钥库。即我将使用默认密钥库执行我需要的操作,然后将密钥库复制到 .JAR 中,以便我可以告诉我的应用程序使用 .JAR 中的密钥库而不是 Java 安装目录中的密钥库,等等...

I have found the following post, which I think I may help because I need a way of verifying my website (that my java application connects to) without having to use the java keystore:

http://www.mombu.com/programming/java/t-ssl-for-java-without-keystores-1366416.html

However, I'm quite new to the world of SSL and don't know which files and passwords I need to use, so if anybody can point me in the right direction that would be great. If you didn't guess, I got my SSL certificate from StartSSL, who are ran/owned/something by StartCom Ltd. Here is a post I used for putting the details into the keystore:

https://forum.startcom.org/viewtopic.php?t=1390

Thanks in Advance!

Alternitively, is there any way for me to use a custom keystore. i.e I'll do what I need with the default keystore and then copy the keystore into the .JAR so that I can tell my application to use the one in the .JAR instead of the one in the Java install directory, etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-12-21 08:20:57

是的,您可以使用

Properties properties = System.getProperties();
properties.put("javax.net.ssl.keyStore", path/to/keystorefile);
properties.put("javax.net.ssl.keyStorePassword", keyStorePassword);
properties.put("javax.net.ssl.trustStore", path/to/truststore);
properties.put("javax.net.ssl.trustStorePassword", trustStorePassword);

编辑:

是的,您可以指定密钥库和密钥库。属性文件中的 trustore 位置及其密码,并将属性文件加载为 myProperties.load(myProperties.getClass().getResourceAsStream("/path/to/proertyfile.properties"));

然后在代码中使用它(省略异常处理)(这不会影响任何其他应用程序):

KeyStore mykeystore = KeyStore.getInstance("JKS");
InputStream is = new FileInputStream("/path/from/myproperties");
mykeystore.load(is, myKeystorePasswordFromProperties.toCharArray());

Yes, you can create and use your own keystore for your app using the keytool utility which comes with the JDK.

Basically, a keystore is a datastore for your keys & certificates, which will be used in your app either to authenticate yourself to another entity or to digitally sign your messages or any other data.

A distinct keystore called trustore is used to keep the public key certificates of the entities you trust.

You can have these keystores placed in your classpath and specify the path in your app in code like (these are VM params which will affect all apps running in this VM):

Properties properties = System.getProperties();
properties.put("javax.net.ssl.keyStore", path/to/keystorefile);
properties.put("javax.net.ssl.keyStorePassword", keyStorePassword);
properties.put("javax.net.ssl.trustStore", path/to/truststore);
properties.put("javax.net.ssl.trustStorePassword", trustStorePassword);

EDIT:

Yes, you can specify the keystore & trustore locations and their passwords in a property file and load the properties file as myProperties.load(myProperties.getClass().getResourceAsStream("/path/to/proertyfile.properties"));

and then use it in your code as (exception handling omitted)(this will not affect any other app):

KeyStore mykeystore = KeyStore.getInstance("JKS");
InputStream is = new FileInputStream("/path/from/myproperties");
mykeystore.load(is, myKeystorePasswordFromProperties.toCharArray());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文