java.security.NoSuchProviderException:没有这样的提供者:SunMSCAPI

时间:2011-01-04 15:13:49

标签: java windows security

我有几个程序使用SunMSCAPI来阅读需要SSL证书的网页。我的代码在Windows XP(32位)下运行,但在我全新安装的Windows 7(64位)下无效。这是一段代码:

System.setProperty("javax.net.ssl.keyStoreProvider", "SunMSCAPI");
System.setProperty("javax.net.ssl.keyStoreType", "WINDOWS-MY");
System.setProperty("javax.net.ssl.trustStoreProvider", "SunMSCAPI");
System.setProperty("javax.net.ssl.trustStoreType", "WINDOWS-ROOT"); 
System.setProperty("proxyHost", "proxy");
System.setProperty("proxyPort", "8080");

URL url = new URL(TEST_URL);
try {
    HttpsURLConnection httpsCon = (HttpsURLConnection) url.openConnection();.... 

这是堆栈跟踪:

Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
 at java.security.Provider$Service.newInstance(Unknown Source)
 at sun.security.jca.GetInstance.getInstance(Unknown Source)
 at sun.security.jca.GetInstance.getInstance(Unknown Source)
 at javax.net.ssl.SSLContext.getInstance(Unknown Source)
 at javax.net.ssl.SSLContext.getDefault(Unknown Source)
 at javax.net.ssl.SSLSocketFactory.getDefault(Unknown Source)
 at javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(Unknown Source)
 at javax.net.ssl.HttpsURLConnection.<init>(Unknown Source)
 at sun.net.www.protocol.https.HttpsURLConnectionImpl.<init>(Unknown Source)
 at sun.net.www.protocol.https.Handler.openConnection(Unknown Source)
 at sun.net.www.protocol.https.Handler.openConnection(Unknown Source)
 at java.net.URL.openConnection(Unknown Source)
 at GetData2.SetVallues(GetData2.java:56)  *// HttpsURLConnection httpsCon = (HttpsURLConnection) url.openConnection();* 
 ... 2 more
Caused by: java.security.NoSuchProviderException: no such provider: SunMSCAPI
 at sun.security.jca.GetInstance.getService(Unknown Source)
 at sun.security.jca.GetInstance.getInstance(Unknown Source)
 at java.security.Security.getImpl(Unknown Source)
 at java.security.KeyStore.getInstance(Unknown Source)
 at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.getDefaultKeyManager(Unknown Source)
 at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.<init>(Unknown Source)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at java.lang.Class.newInstance0(Unknown Source)
 at java.lang.Class.newInstance(Unknown Source)
 ... 15 more

我也尝试过关注示例http://muhammadhamed.blogspot.com/2010/04/accessing-ms-certificate-stores-in-java.html,但又收到了此NoSuchProviderException。我的猜测是有一些配置错误,但我不确定它是什么。

这是我的JVM信息:
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)

我希望有人能够帮助我: - )

最好的问候。

1 个答案:

答案 0 :(得分:3)

J2SE Security page仅表示MS CryptoAPI(SunMSCAPI使用)仅在32位Windows上的Java 6下可用。

幸运的是,您仍然可以在Win64上安装32位JVM。