黑马程序员技术交流社区

标题: SSL问题已解决 [打印本页]

作者: 黑马罗坚    时间: 2012-6-14 20:24
标题: SSL问题已解决
本帖最后由 nailsoul 于 2012-6-15 01:59 编辑

private static void openSSLserver() {
  try {
   String userHome=System.getProperty("user.home");
   System.out.println(userHome);
   System.setProperty("javax.net.ssl.keyStore", userHome+"/.keystore");   javax.net.ssl.keyStore k应该是小写
   System.setProperty("javax.net.ssl.keyStorePassword","123456");
   SSLServerSocket ssl=(SSLServerSocket)SSLServerSocketFactory.getDefault().createServerSocket(9999);
   while(true){
    final Socket s=ssl.accept();
    System.out.println(s.getInetAddress().getHostAddress()+"connecting SSLSERVER");
    new Thread(){
     @Override
     public void run(){
      InputStream in=null;
      OutputStream out=null;
      try {
       in=s.getInputStream();
       out=s.getOutputStream();
       byte[] results=new byte[1024];
       int len=in.read(results);
       System.out.println(new String(results,0,len));
       out.write("Welcome to SSLServer".getBytes());
       in.close();
       out.close();
       s.close();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
     }
    }.start();
   }
   
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
}

为什么老是报没有找到证书呢? 我用keytool -genkeypair -alias 127.0.0.1 创建了证书柜啊 密码设置的123456
javax.net.ssl.SSLException: No available certificate or key corresponds to the SSL cipher suites which are enabled.
at com.sun.net.ssl.internal.ssl.SSLServerSocketImpl.checkEnabledSuites(SSLServerSocketImpl.java:307)
at com.sun.net.ssl.internal.ssl.SSLServerSocketImpl.accept(SSLServerSocketImpl.java:253)
at Security.MySSHServerSocket.openSSLserver(MySSHServerSocket.java:26)
at Security.MySSHServerSocket.main(MySSHServerSocket.java:16)





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2