Java 将 SSL 证书导入 Eclipse
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/684081/
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
Importing SSL Certificate into Eclipse
提问by MahlerFive
How do you import an SSL certificate created by java into a project in Eclipse?
Eclipse中如何将java创建的SSL证书导入到项目中?
采纳答案by sourcerebels
Probably you want to import a "fake" SSL cert in JRE's trustcacerts for avoiding not-a-valid-certificate issues. Isn't it?
可能您想在 JRE 的 trustcacerts 中导入“假”SSL 证书,以避免出现无效证书问题。不是吗?
As Jon said, you can do the job with keytool:
正如乔恩所说,您可以使用keytool完成这项工作:
keytool
-import
-alias <provide_an_alias>
-file <certificate_file>
-keystore <your_path_to_jre>/lib/security/cacerts
Use "changeit" as the default password when asked (thanks Brian Clozel). Ensure to use this runtime at your server or launch configuration.
询问时使用“changeit”作为默认密码(感谢 Brian Clozel)。确保在您的服务器或启动配置中使用此运行时。
回答by Jon
You should probably create the certificate and import it into the default keystore using keytool. I'm not sure what you're trying to do with your application, but it should then be able to use that certificate.
您可能应该创建证书并使用 keytool 将其导入默认密钥库。我不确定你想用你的应用程序做什么,但它应该能够使用该证书。
回答by Navaneeth
We need to import a certificate means we need to use :
我们需要导入证书意味着我们需要使用:
keytool
-importcert
-file <certificate_location>
-keystore <jre_location\lib\security\cacerts>
-alias "<cert_name>"
It will ask for a password. Type the password as changeit
它会要求输入密码。输入密码为changeit
Type Password : changeit
finally it will ask need to add {yes/no} :
最后它会要求添加 {yes/no} :
type yes.
输入是。
Note: Don't give blank space in location path
注意:位置路径中不要留空格
回答by BalajiShanmugam
sudo keytool -import -file /Users/balaji-pt2176/Desktop/Apple\ Worldwide\ Developer\ Relations\ Certification\ Authority.cer -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/security/cacerts
in mac
在 mac
回答by apocalysque
There's a better tool for the job.
有一个更好的工具来完成这项工作。
When you run (run as administrator in windows in order to save changes to system, sudo in linux, etc.) the application (it has installers for win/mac/linux) there's a built-in function to edit the system's cacerts file:
当您运行(在 Windows 中以管理员身份运行以保存对系统的更改,在 linux 中以 sudo 等方式运行)应用程序(它具有适用于 win/mac/linux 的安装程序)时,有一个内置函数来编辑系统的 cacerts 文件:
File -> Open Special -> Open CA Certificates
文件 -> 打开特殊 -> 打开 CA 证书
EITHERyou already have the certificate file and you can go to:
要么你已经有了证书文件,你可以去:
Tools -> Import Trusted Certificate
工具 -> 导入可信证书
ORyou need to download the certificate from the server; go to:
或者您需要从服务器下载证书;去:
Examine -> Examine SSL
检查 -> 检查 SSL
From there type in the hostname and click ok. It will pop up a window showing the certificate details. At the bottom of that window there's an "Import" button that will allow you to directly import it into the cacerts.
从那里输入主机名并单击确定。它将弹出一个显示证书详细信息的窗口。在该窗口的底部有一个“导入”按钮,可让您直接将其导入 cacerts。
Make sure you save and close cacerts, and restart your eclipse/application for the settings to take effect.
确保保存并关闭 cacerts,然后重新启动 eclipse/应用程序以使设置生效。
回答by k.a.
If you have default Java setup and have provided Java classpath, then you must be using Java Truststore for SSL certificates.
如果您有默认的 Java 设置并提供了 Java 类路径,那么您必须使用 Java Truststore 来获取 SSL 证书。
For this you can follow below steps to import certificates into Trust store:
为此,您可以按照以下步骤将证书导入信任库:
- Navigate to the JRE\bin folder of your Java setup Ideally the path should be:
- 导航到 Java 设置的 JRE\bin 文件夹 理想情况下,路径应为:
user\Java\jre1.8.0_221\bin
用户\Java\jre1.8.0_221\bin
- You will be able to find Keytool in the bin folder(which will be used to run the commands):
- 您将能够在 bin 文件夹中找到 Keytool(将用于运行命令):
- Now once you are on this path, open the path in your CMD prompt:
- 现在,一旦您位于此路径上,请在 CMD 提示符中打开该路径:
- Now you will be able to find default Trust store of Java at below path: Path-
- 现在您将能够在以下路径中找到 Java 的默认信任存储:路径-
user\Java\jre1.8.0_221\bin
用户\Java\jre1.8.0_221\bin
Path to Java default Trust store
Now you can run below command to see contents of this Trust store:
keytool -list -v -keystore "C:\Program Files\Java\jre1.8.0_221\lib\security\cacerts"
现在您可以运行以下命令来查看此信任存储的内容:
keytool -list -v -keystore "C:\Program Files\Java\jre1.8.0_221\lib\security\cacerts"
Note: If your path to Trust store has spaces in it, then you need to use double quotes for the path. Else you can provide path like below:
注意:如果您的 Trust store 路径中有空格,那么您需要对路径使用双引号。否则,您可以提供如下路径:
keytool -list -v -keystore C:\Temp\Java\jre1.8.0_221\lib\security\cacerts
Now just provide password to Trust Store(Default password is: changeit): Accessing Trust store using Keytool
现在只需向 Trust Store 提供密码(默认密码为:changeit): 使用 Keytool 访问信任存储
You can now as per your need add any certificate to the Trust store:
JRE_HOME/bin/keytool -import -trustcacerts -alias certAlias -file certFile -keystore trustStoreFile
您现在可以根据需要将任何证书添加到信任存储:
JRE_HOME/bin/keytool -import -trustcacerts -alias certAlias -file certFile -keystore trustStoreFile