在我的Java應用程序中,我在客戶端使用了Java的keystore工具。我支持Oracle和IBM Java環境。基本上,代碼如下:TrustManagerFactory IBM Java 1.7
嘗試{
KeyStore ks = KeyStore.getInstance("JKS");
MyResources gr = new MyResources(null);
InputStream inpStream = gr.GetResourceAsStream(MYFILE);
if (inpStream == null) {
}
ks.load(inpStream, MYPASSWORD);
TrustManagerFactory Mytmf = null;
try {
Mytmf = TrustManagerFactory.getInstance("SUNX509");
} catch (NoSuchAlgorithmException e) {
Mytmf = TrustManagerFactory.getInstance("IbmX509");
}
Mytmf.init(ks);
} catch (Exception e) {
}
該方案在IBM JRE 1.6和更早版本的正常工作。在版本1.7中,在連接嘗試到服務器時收到以下異常,並在最後失敗:
線程「myThread」中的異常java.lang.NoClassDefFoundError:sun/security/validator/KeyStores >>在sun.security.ssl.X509TrustManagerImpl。(X509TrustManagerImpl.java:80) 09:06:46 >> at sun.security.ssl.TrustManagerFactoryImpl $ SimpleFactory.getInstance(TrustManagerFactoryImpl.java:240) 09:06:46 >> at sun.security.ssl.TrustManagerFactoryImpl.engineInit(TrustManagerFactoryImpl.java:79) 09:06:46 >> at javax.net.ssl.TrustManagerFactory.init(TrustManagerFactory.java:19) 09:06:46 >> at MyTrustMgr.getTrustManager(MyTrustMgr.java:34)
你有什麼想法可以解釋這個問題的原因嗎?
在文檔中,默認算法似乎是IBM和Oracle Java的「PKIX」,我怎樣才能將默認algorthim設置爲「X509」? – bugra
據我所知,PKIX是* only *支持的TrustManagerFactory算法。 SunX509是* KeyManagerFactory *算法。 – EJP