java.Security.NoSuchAlgorithmException

标签 java exception keytool

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());
        }
}

异常(exception)是 - java.security.NoSuchalgorithmException !我已经使用名为 spacesalt.store 的 keytool 创建了一个 keystore ,并将该 spacesalt.store 文件复制到项目中。我正在使用 eclipse ! 。确实,我对此一无所知。需要一个虚拟指南来解决它!

最佳答案

也许我重现了你的问题。我已经生成了一个 keystore 并执行了您的代码。之后我得到了一个异常(exception) 线程“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)

我解决了设置 keystore 的完整路径的问题:

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

对 keystore 的访问是通过调用 FileInputStream(property_value) 来完成的,因此,您还可以将 keystore 放在启动应用程序的文件夹中。

关于java.Security.NoSuchAlgorithmException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523763/

相关文章:

java - 检查 JFrame 是否打开

android - Ionic apk 签名错误

java - Keytool EC KeyPairGenerator 不可用

java - 当输入只有整数和小数点部分时检查 double 值

java安全套接字无需身份验证?

java - Eclipse: "println(__LINE__);"——是否存在这样的预处理器宏来以编程方式获取代码的行号?

java - 如何使用 JMockit 模拟 Date 类的默认构造函数?

java - CellType 无法解析为变量 setCellType 错误 Apache POI - Java

exception - 如何在 R6RS Scheme 中抛出和处理异常

language-agnostic - 处理所有异常的正确时机