Java 中的 MSCAPI 证书选择框; SunMSCAPI?

发布于 2024-10-16 17:05:20 字数 101 浏览 2 评论 0原文

我正在尝试相对较新的 SunMSCAPI 安全提供程序。我想构建一个简单的小程序,提示浏览器弹出证书选择框。我会从那里拿走它。 我用谷歌搜索了这一点,从一种方式到另一种方式。有什么建议吗?

I'm experimenting with the relatively new SunMSCAPI security provider. I want to build a simple applet that prompts the browser to pop up the certificate selection box. I'll take it from there.
I have Googled this up one way and down another. Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何时共饮酒 2024-10-23 17:05:21

我正在(努力)做类似的事情 - 尽管对于一个非网络应用程序..到目前为止,唯一对我有用的解决方案 - 是做一个 JNI 到 C# (使用 MCPP 包装)..

I am working (struggling) on something similar - although for a non web app.. The only solution which has worked for me so far - is to do a JNI to C# (Wrapped using MCPP)..

你怎么这么可爱啊 2024-10-23 17:05:21

您可以使用 SunMSCAPI 提供程序来实例化本地客户端 Windows 密钥库。您可以简单地使用以下代码来完成此操作:

KeyStore keyStore = KeyStore.getInstance("Windows-MY",new SunMSCAPI());
keyStore.load(null, null);

或者,如果您愿意,可以将提供程序添加到安全列表,而不是将其传递给 getInstance() 调用:

SunMSCAPI providerMSCAPI = new SunMSCAPI();
Security.addProvider(providerMSCAPI);
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);

请注意,默认情况下它可能已经添加到安全提供程序Windows 操作系统上的 java 安装列表。

关于您的问题没有太多细节,因此我给您举一个示例,例如显示本地客户端 Windows 密钥库中相关证书的所有别名和主题,以说明此提供程序的使用:

package org.catcert.crypto.keyStoreImpl.windows;

import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;

import sun.security.mscapi.SunMSCAPI;

public class Example {

    public static void main(String args[]) throws Exception {
        KeyStore keyStore = KeyStore.getInstance("Windows-MY",new SunMSCAPI());
        keyStore.load(null, null);

        // copy to avoid concurrent problems with aliases...
        ArrayList<String> aliases = Collections.list(keyStore.aliases());
        for(String alias : aliases){
            System.out.println("keyEntry alias: " + alias);
            X509Certificate cert = (X509Certificate)keyStore.getCertificate(alias);
            System.out.println("Certificate subject: " +  cert.getSubjectDN());

        }
    }
}

请注意,SunMSCAPI 是在 java 上引入的1.6,但是在 java 1.7 上添加了对 64 位版本的支持。

You can use the SunMSCAPI provider to instantiate the local client windows keystore. You can do it simply using this code:

KeyStore keyStore = KeyStore.getInstance("Windows-MY",new SunMSCAPI());
keyStore.load(null, null);

Or if you prefer you can add the provider to security list instead of passing it to the getInstance() call:

SunMSCAPI providerMSCAPI = new SunMSCAPI();
Security.addProvider(providerMSCAPI);
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);

Note that it's probably already added by default to security providers list for java installation on windows OS.

There are not many details on your question so I give you an example to for example show all aliases and subject of the related certificates from the local client windows keystore to illustrate the use of this provider:

package org.catcert.crypto.keyStoreImpl.windows;

import java.security.KeyStore;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;

import sun.security.mscapi.SunMSCAPI;

public class Example {

    public static void main(String args[]) throws Exception {
        KeyStore keyStore = KeyStore.getInstance("Windows-MY",new SunMSCAPI());
        keyStore.load(null, null);

        // copy to avoid concurrent problems with aliases...
        ArrayList<String> aliases = Collections.list(keyStore.aliases());
        for(String alias : aliases){
            System.out.println("keyEntry alias: " + alias);
            X509Certificate cert = (X509Certificate)keyStore.getCertificate(alias);
            System.out.println("Certificate subject: " +  cert.getSubjectDN());

        }
    }
}

Note that SunMSCAPI was introduced on java 1.6, however support for 64 bits version was added on java 1.7.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文