HttpsParameters无法解析为类型

时间:2018-11-06 14:25:32

标签: java ssl https

我想保护我的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");
                  }
                   }
               });`

1 个答案:

答案 0 :(得分:0)

我犯了一个错误,我忘记了将导入内容添加到班级中

import com.sun.net.httpserver.HttpsParameters;