我正在尝试POST
致电安全网站:
步骤:
1)转到https://www.mywebsite.com(供参考)
2)将上述网站的密钥库导出到C:\Program Files\Java\jre7\lib\security
。
3)将其导入cacerts,使用keytool作为
添加自签名签名keytool -import -alias my-cert -file c:\cert.crt -keystore %JAVA_HOME%/jre/lib/security/cacerts
完成上述步骤后,我使用了以下程序:
String keystorePathAndName = "C:\\Program Files\\Java\\jre7\\lib\\security\\mykeystore";
String keystoreType = "der";
String keystorePass = "";
Integer port = 8089;
if (System.getProperty("port") != null) {
port = Integer.valueOf(System.getProperty("port"));
}
// Create a server listening on port 8089
Component component = new Component();
Server server = component.getServers().add(Protocol.HTTPS, port);
Series<Parameter> params = server.getContext().getParameters();
params.add("keystorePath", keystorePathAndName);
params.add("keystoreType", keystoreType);
params.add("keystorePassword", keystorePass);
component.getDefaultHost().attach("/Simulator",new UserApplication());
component.start();
错误日志:
Exception in thread "main" java.security.KeyStoreException: der not found
at java.security.KeyStore.getInstance(KeyStore.java:616)
at org.restlet.engine.ssl.DefaultSslContextFactory.createSslContext(DefaultSslContextFactory.java:299)
at org.restlet.engine.connector.HttpsServerHelper.start(HttpsServerHelper.java:92)
at org.restlet.Server.start(Server.java:579)
at org.restlet.Component.startServers(Component.java:642)
at org.restlet.Component.start(Component.java:567)
at com.user.app.userapp.main.AppServer.main(AppServer.java:78)
Caused by: java.security.NoSuchAlgorithmException: der KeyStore not available
at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
at java.security.Security.getImpl(Security.java:695)
at java.security.KeyStore.getInstance(KeyStore.java:613)
... 6 more
更新
在回答Lolo的回答时,我在尝试保存密钥库时没有获得PKCS12
或JKS
格式。
答案 0 :(得分:2)
答案在异常消息中:&#34;未找到&#34;在调用KeyStore.getInstance()
时意味着der
不是密钥存储区的已知格式。您应尝试使用其中一种已知格式,例如JKS
(Oracle&#39; JVM的默认值)或PKCS12
。有关密钥库格式的更多详细信息,请参阅此other post。
修改强>
如屏幕截图所示,您要保存的文件是证书文件。假设您随后使用Oracle的keytool
&#39;&#39; JKS
&#39;将其导入信任库。如果您没有指定信任库格式,则应在代码中使用Oracle JVM的默认格式der
,而不是String keystoreType = "JKS";
:
{{1}}