gpt4 book ai didi

Java 中的 SSL 服务器 - javax.net.ssl.SSLException

转载 作者:太空宇宙 更新时间:2023-11-03 13:13:18 27 4
gpt4 key购买 nike

我正在尝试使用 SSL 创建服务器,但我不断收到以下错误:

“服务器中止:javax.net.ssl.SSLException:没有可用的证书或 key 对应于已启用的 SSL 密码套件。”

我不确定我是否正确创建了证书。这是我的代码。我正在将旧的 TCP 服务器转换为 SSL 服务器

// SSL Server

import java.net.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;

public class SSL_Server {


public static void main(String[] args) {
int port = 2018;
ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
ServerSocket ssocket = null;
System.out.println("SSL_Server started");

System.setProperty("javax.net.ssl.keyStore","mySrvKeystore");
System.setProperty("javax.net.ssl.keyStorePassword","123456");

final ExecutorService threadPool = Executors.newCachedThreadPool();

try {
ssocket = ssocketFactory.createServerSocket(port);
InetAddress myIP =InetAddress.getLocalHost();
System.out.println(myIP.getHostAddress());

while(true){
Socket aClient = ssocket.accept();
//create a new thread for every client
threadPool.submit(new SSL_ClientHandler(aClient));
}
}
catch(Exception e) {
System.err.println("Server aborted:" + e);
} finally {
try{
ssocket.close();
} catch (Exception e){
System.err.println("could not close connection properly" + e);
}
}
System.out.println("connection was closed successfully");
}

最佳答案

System.setProperty("javax.net.ssl. keyStore","mySrvKeystore"); System.setProperty("javax.net.ssl. keyStorePassword","123456");

ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault();
ServerSocket ssocket = null;
System.out.println("SSL_Server started");

关于Java 中的 SSL 服务器 - javax.net.ssl.SSLException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9593369/

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