Could not generate DH keypair Exception on doing HTTPS POST

Context: I'm working with Jasper Reports version 4.1.2 with JDK 1.7.0_79 set to compile at Java 1.6 on a windows 8 development machine.

Now the actual problem: Somewhere else in the application I'm trying to do a HTTPS post to a server. Unfortunately this is failing because an exception is thrown stating "Could not generate DH Keypair".  At the end of the stacktrace it tells me something about BouncyCastel. 

Caused by: parameter object not a ECParameterSpec at org.bouncycastle.jce.provider.JDKKeyPairGenerator$EC.initialize(Unknown Source) at<init>( ... 135 more

BouncyCastle [BC] seems to be included by iText which probably sets the global java security for the whole application with something like :

Security.addProvider(new BouncyCastleProvider());
When my post is trying to get the responsecode this provider is used and because the server I'm posting to is probably using primesize of more than 1024 bits. ( )

What I tried to do: Http posts are working without any problems however, I prefer to use HTTPS.

Another thing, I can workaround the issue by removing the bcmail-jdk14,bcprov-jdk14,and bctsp-jdk14,jars from the webcontainer and replacing them by the -jdk16 equivalents. This way my https post worked fine :) . However I'm not sure whether this might cause any problems for JasperReports. I was thinking about upgrading to 6.1.0 but I found out that version also uses the old BouncyCastle Provides.

Adding all kinds of stuff to the httpheaders but ofcourse this didn't solve anything.


I am assuming more people are doing trivial stuff such as HTTPS posts combinde with JasperReports so I hope someone else knows how to solve this.

Java code

HttpsURLConnection con = (HttpsURLConnection) newurl.openConnection();
        con.setRequestProperty("User-Agent", "Mozilla/5.0");
        con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
        int responseCode = con.getResponseCode();

Exception Stacktrace

These are the first lines of the first exception java.lang.RuntimeException: Could not generate DH keypair at at at at at at at at at at at

maarten_5's picture
Joined: Jun 11 2015 - 6:07am
Last seen: 7 years 8 months ago

1 Answer:

jjw.roberto's picture
Joined: Feb 13 2017 - 8:44am
Last seen: 3 years 3 weeks ago