刚刚安装了OpenJDK,我刚刚安装了Ubuntu:
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode) on Ubuntu 64 bit 10.10
不确定这是否相关,但我是在VMWare Fusion中运行它。
以下一行:
javax.net.SSLContext.getDefault(); // same as getInstance("Default")
throws the following exception:
java.net.SocketException: java.security.NoSuchAlgorithmException: Default SSLContext not available
我的同事和我已经在几台机器上尝试了这一点,所有新安装的Ubuntu,并继续得到这个。我被建议尝试getInstance(“TLSv1”),但这引发了同样的错误。似乎是一些非常重要的工作,所以我认为我们必须做错事。
答案 0 :(得分:6)
圭多的回答指出了我正确的方向。这只是一个问题:
sudo apt-get install libbcprov-java
答案 1 :(得分:2)
然后在您的课程中参考以下示例代码:
static { Security.addProvider( new BouncyCastleProvider() ); } public SSLSocket getSSLSocket() { // Load the Keystore KeyStore ks = KeyStore.getInstance(keystoreType); ks.load(new FileInputStream(this.keyStorePath),this.keyStorePass.toCharArray()); // Get a KeyManager and initialize it KeyManagerFactory kmf = KeyManagerFactory.getInstance("sunx509"); kmf.init(ks, this.keyStorePass.toCharArray()); // Get a TrustManagerFactory and init with KeyStore TrustManagerFactory tmf = TrustManagerFactory.getInstance("sunx509"); tmf.init(ks); // Get the SSLContext to help create SSLSocketFactory SSLContext sslc = SSLContext.getInstance("TLS"); sslc.init(kmf.getKeyManagers(), null, null); // Get SSLSocketFactory and get a SSLSocket SSLSocketFactory sslsf = sslc.getSocketFactory(); SSLSocket socket = (SSLSocket) sslsf.createSocket(host, port); return socket; }