简体   繁体   English

Java和SSL - java.security.NoSuchAlgorithmException

[英]Java and SSL - java.security.NoSuchAlgorithmException

I've built a Java program as a front end for a database on a server, and I'm trying to use SSL to encrypt traffic between clients and the server. 我已经构建了一个Java程序作为服务器上数据库的前端,我正在尝试使用SSL来加密客户端和服务器之间的流量。 Here is the command I issued to create the server certificate: 这是我发出的用于创建服务器证书的命令:

keytool -genkey -alias localhost -keyalg RSA -keypass kpass123 -storepass kpass123 -keystore keystore.jks

Here is the relevant code: 这是相关代码:

System.setProperty("javax.net.ssl.keyStore",
                   "G:/Data/Android_Project/keystore.jks");

System.setProperty("javax.net.ssl.keyPassword", "kpass123");

SSLServerSocketFactory factory = 
    (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();

SSLServerSocket accessSocket = 
    (SSLServerSocket)factory.createServerSocket(DB_ACCESS_PORT);

When I try to run this, I catch this: 当我尝试运行它时,我抓住了这个:

java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl) java.security.NoSuchAlgorithmException:构造实现时出错(算法:默认,提供者:SunJSSE,类:com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)

I've also found that the "KeyPairGenerator" service has algorithms DIFFIEHELLMAN, DSA, RSA available to it, while "SSLContext" has algorithms SSL, TLS, SSLV3, DEFAULT, TLSV1. 我还发现“KeyPairGenerator”服务有DIFFIEHELLMAN,DSA,RSA算法,而“SSLContext”有算法SSL,TLS,SSLV3,DEFAULT,TLSV1。

Do I need to find some way to install RSA into the SSLContext service? 我是否需要找到一些方法将RSA安装到SSLContext服务中? Am I even looking at the correct services? 我甚至在看正确的服务吗? Should I not be using RSA? 我不应该使用RSA吗?

I'm new to the whole SSL - Security - Certificates thing, and it just blows me away that each of these different services don't have the same algorithms when they are supposed to be accessing the same certificates. 我是整个SSL - 安全 - 证书的新手,它让我感到震惊的是,当他们应该访问相同的证书时,这些不同的服务中的每一个都没有相同的算法。

Try javax.net.ssl.keyStorePassword instead of javax.net.ssl.keyPassword : the latter isn't mentioned in the JSSE ref guide . 尝试使用javax.net.ssl.keyStorePassword而不是javax.net.ssl.keyPasswordJSSE参考指南中未提及后者。

The algorithms you mention should be there by default using the default security providers. 您提到的算法默认使用默认安全提供程序。 NoSuchAlgorithmException s are often cause by other underlying exceptions (file not found, wrong password, wrong keystore type, ...). NoSuchAlgorithmException通常是由其他基础异常引起的(找不到文件,密码错误,密钥库类型错误,......)。 It's useful to look at the full stack trace. 查看完整堆栈跟踪很有用。

You could also use -Djavax.net.debug=ssl , or at least -Djavax.net.debug=ssl,keymanager , to get more debugging information, if the information in the stack trace isn't sufficient. 如果堆栈跟踪中的信息-Djavax.net.debug=ssl,keymanager ,您还可以使用-Djavax.net.debug=ssl或至少-Djavax.net.debug=ssl,keymanager来获取更多调试信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SSL java.security.NoSuchAlgorithmException - SSL java.security.NoSuchAlgorithmException Java / SSL - Unhandle异常:java.security.NoSuchAlgorithmException - Java/SSL - Unhandle exception:java.security.NoSuchAlgorithmException java.security.NoSuchAlgorithmException:SSL_TLSv2 SSLContext 不可用 - java.security.NoSuchAlgorithmException: SSL_TLSv2 SSLContext not available java.security.NoSuchAlgorithmException: RSA 签名不可用 - java.security.NoSuchAlgorithmException: RSA Signature not available java.security.NoSuchAlgorithmException:为SSLContext配置的类 - java.security.NoSuchAlgorithmException: class configured for SSLContext Tomcat 7 + MyFaces 2.1:java.security.NoSuchAlgorithmException - Tomcat 7 + MyFaces 2.1 : java.security.NoSuchAlgorithmException Java 9使用“java.security.NoSuchAlgorithmException:SHA3-384 MessageDigest不可用” - “java.security.NoSuchAlgorithmException: SHA3-384 MessageDigest not available” with Java 9 junit java.security.NoSuchAlgorithmException:找不到任何支持的提供程序 - junit java.security.NoSuchAlgorithmException: Cannot find any provider supporting java.security.NoSuchAlgorithmException:算法PBKDF2WithHmacSHA1不可用 - java.security.NoSuchAlgorithmException: Algorithm PBKDF2WithHmacSHA1 not available java.security.NoSuchAlgorithmException:未找到签名MD5WITHRSA实现 - java.security.NoSuchAlgorithmException: Signature MD5WITHRSA implementation not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM