java.Security.NoSuchAlogirthmException

java.Security.NoSuchAlogirthmException

public static void main(String[] args) throws Exception {
        System.setProperty("javax.net.ssl.keyStore","spacesalt.store");
        System.setProperty("javax.net.ssl.keystorePassword", "123456");

        HttpsURLConnection cons = null;
        URL url = null;

        String host ="https://www.google.com";
        url = new URL(host) ;

        cons = (HttpsURLConnection) url.openConnection() ;
        cons.setReadTimeout(30000);

        BufferedReader reader = new BufferedReader(new InputStreamReader(cons.getInputStream()));
        String line = null;
        StringBuilder data = new StringBuilder() ;
        long startTime = System.currentTimeMillis() ;
        while((line = reader.readLine()) != null) {
            data.append(line +System.lineSeparator());
        }
}

例外情况是 - java.security.NoSuchalgorithmException!我使用名为 spacesalt.store 的密钥工具创建了一个密钥库,并将该 spacesalt.store 文件复制到项目中。我正在使用日食! .真的,我对此一无所知。需要一个虚拟指南来解决它!

可能我重现了你的问题。我已经生成了一个密钥库并执行了您的代码。之后我得到了一个例外 线程 "main" java.net.SocketException 中的异常:

java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: sun.security.ssl.SSLContextImpl$DefaultSSLContext)
    at javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:248)
    at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:255)

我解决了设置密钥库完整路径的问题:

 System.setProperty("javax.net.ssl.keyStore","full_path_to_keyStore_/spacesalt.store");

通过调用 FileInputStream(property_value) 访问密钥库,因此,您也可以将密钥库放在启动应用程序的文件夹中。