gpt4 book ai didi

java - HttpsParameters 无法解析为类型

转载 作者:太空宇宙 更新时间:2023-11-03 15:12:17 25 4
gpt4 key购买 nike

我想保护我的 http 请求,我正在使用类似 http://123.456.789.123:1234 的东西,我想保护它。在实现我的代码之后,我使用 java keytool 创建了一个 keystore.csr carets.jks server.cer 和 keystore.jks,但它无法读取 HttpsParameters

String alias = "alias";
char [] storepass = "changeit".toCharArray();
String keystoreName = "c:\\keystore.jks";
FileInputStream in = new FileInputStream(keystoreName);
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(in, storepass);
Certificate cert = keystore.getCertificate(alias);
Log.debug("the certification is here : " + cert);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
char [] keypass = "changeit".toCharArray();
kmf.init(keystore, keypass);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keystore);
HttpsServer server = HttpsServer.create(new InetSocketAddress(port), 0);
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
public void configure(HttpsParameters params) {
try {
SSLContext c = SSLContext.getDefault();
SSLEngine engine = c.createSSLEngine();
params.setNeedClientAuth(false);
params.setCipherSuites(engine.getEnabledCipherSuites());
params.setProtocols(engine.getEnabledProtocols());
SSLParameters defaultSSLParameters=c.getDefaultSSLParameters();
params.setSSLParameters(defaultSSLParameters);
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Failed to create HTTPS server");
}
}
});`

最佳答案

我犯了一个错误,我忘了将导入添加到我的类中

import com.sun.net.httpserver.HttpsParameters;

关于java - HttpsParameters 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53173885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com