create an SSLContext instance using a Bouncy Castle provider

后端 未结 3 2116
面向向阳花
面向向阳花 2020-12-09 12:13

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):

The code



        
3条回答
  •  庸人自扰
    2020-12-09 12:39

    Bouncy Castle actually provides a JSSE implementation as of version 1.56. Just make sure to configure it with a higher priority at the application startup:

    Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
    

    or, as alternative, in global /lib/security/java.security file:

    security.provider.1=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
    ...
    security.provider.6=com.sun.net.ssl.internal.ssl.Provider
    

    You can use it then with the standard API:

    SSLContext context = SSLContext.getInstance("TLS");
    

提交回复
热议问题