问题描述
我坚持创建SSLContext(我想用它来实例化SSLEngine以通过java-nio处理加密传输):
I'm stuck at the creation of an SSLContext (which I want to use to instantiate an SSLEngine to handle encrypted transport via the java-nio):
代码
String protocol = "TLSv1.2";
Provider provider = new BouncyCastleProvider();
Security.addProvider(provider);
sslContext = SSLContext.getInstance(protocol,provider.getName());
抛出以下异常:
Exception in thread "main" java.lang.RuntimeException: java.security.NoSuchAlgorithmException: no such algorithm: SSL for provider BC
at org.bitmash.network.tcp.ssl.SslTransferFactory.<init>(SslTransferFactory.java:43)
at org.bitmash.network.http.HttpsServer.<init>(HttpsServer.java:19)
我附加了Bouncy Castle目前的提供程序包'bcprov-jdk15on-150.jar'(我从)到应用程序类路径以及它的bootclasspath(通过VM-Option -Xbootclasspath / p),但都没有解决问题。我还尝试了协议
(即'SSL'和'TLSv1')的不同值,但没有任何影响。
I attached Bouncy Castle's current provider package 'bcprov-jdk15on-150.jar' (which I got from here) to the applications classpath as well as to its bootclasspath (via VM-Option -Xbootclasspath/p), but neither solved the problem. I also tried different values for protocol
(i. e. 'SSL' and 'TLSv1') without any effect.
,我发现有类似问题的人。但与他们相比,我的目标是(并且我正在使用)Java 7(或更高版本),但我仍然遇到这个问题。是这样 - 一般 - 甚至可以这样使用Bouncy Castle,或者我是否必须使用各自的API重写我的协议而不是oracle的(这就是我现在正在做的方式)?
Also, I found people with similar problems here and here. But in contrast to them, I'm targeting (and I'm using) Java 7 (or greater), but I still have this problem. Is it -in general- even feasible to use Bouncy Castle this way, or do I have to rewrite my protocol using their respective API instead of oracle's NIO via SSLEngine (which is the way I'm doing it right now)?
非常感谢你们的帮助。
推荐答案
我知道这是一个古老的问题,但我需要一个答案(所以我创建一个):
I know this is kind of an old question, but I needed an answer (so I am creating one):
- [是否可以]使用Bouncy Castle创建SSLContext实例提供者[?]
- 否
为什么不呢?
调试这行代码:
Provider [] providers = Security.getProviders();
- 默认的SunJSSE 1.7版实现以下SSLContext值:
- the default SunJSSE version 1.7 implements the following SSLContext values:
- 使用bcprov-jdk15on-152.jar并向Security添加一个新的BouncyCastleProvider(),可以观察到没有可用的SSLContext值。
这应该是有道理的,因为Bouncy Castle是一个实现,而不是实施。
This should make sense since Bouncy Castle is a JCE implementation, not a JSSE implementation.
这篇关于使用Bouncy Castle提供程序创建SSLContext实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- the default SunJSSE version 1.7 implements the following SSLContext values: