I am testing a simple method which works fine for images with the HTTP protocol, but fails for HTTPS images ONLY in eclipse. I tested in other IDEs such as DrJava and jCreator but they work fine in them. The method is as follows.
When called as follows, an exception is thrown
boolean verify = verifyImage("https://www.eff.org/files/HTTPS_Everywhere_new_logo.jpg");
System.out.println("Verify result is : " + verify);
The exception details are as follows.
javax.net.ssl.SSLKeyException: RSA premaster secret error
java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
The method is as follows
public static boolean verifyImage(String src)
{
HttpURLConnection urlConnection = null;
try {
URL url = new URL(src);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("HEAD");
urlConnection.connect();
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
return true;
} else {
return false;
}
} catch (Exception e) {
System.out.println("Exception");
return false;
}
}
Any help to resolve the issue would be highly appreciated.
P.S: I tried using javax.net.ssl.HttpsURLConnection which results in the same exception.
This is possibly the same cause as SunTlsRsaPremasterSecret KeyGenerator not available.
Try removing all of the Installed JREs from Eclipse and refinding them.