如何以编程方式访问 windows 和 mac 可信证书存储 [英] how to programmatically acces the window and mac trusted certificate store

查看:39
本文介绍了如何以编程方式访问 windows 和 mac 可信证书存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 keytool 实用程序创建自签名 Java 密钥库和证书文件.通过使用 mmc.exe 命令进入证书控制台,我可以将证书添加到 Windows 信任库中.

Create a selfsigned java keystore and certificate file using keytool utility. Am able to add the certificate into windows trust store by going to certificate console by using mmc.exe command.

但是无论如何以编程方式将证书添加到 Windows 信任存储中.MAC系统也需要同样的东西.

But is there anyway to add the certificate into windows trust store programmatically. And also required the same things for MAC system.

感谢您的任何建议.

推荐答案

以下是 Windows/MAC 在其信任存储中添加证书的代码片段.

Below is code snippet for Windows/MAC to add certificate in their trust store.

窗口:

    KeyStore root = KeyStore.getInstance("Windows-ROOT","SunMSCAPI");
    root.load(null,null);
    /* certificate must be DER-encoded */
    FileInputStream in = new FileInputStream("yourcertificate.cer");
    X509Certificate cacert = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(in);                      
    root.setCertificateEntry("certificatealiasname", cacert);

在 windows 中,它成功地将证书添加到信任存储中,但由于没有管理员权限,某些系统无法运行.所以在那些机器上,如果以管理员身份登录或给用户一些管理员权限,它就会工作.

In windows it is successfully adding the certificate in trust store, but some system does not work due to not having admin privileges. So in those machine it will work if logged in as Administrator or give the user some Admin privileges.

MAC:

        KeyStore root = KeyStore.getInstance("KeychainStore", "Apple");
        root.load(null);
        /* certificate must be DER-encoded */
        FileInputStream in = new FileInputStream("yourcertificate.cer");
        X509Certificate cacert = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(in);
        root.setCertificateEntry("certificatealiasname", cacert);
        root.store(null, null);

它能够成功地将证书添加到钥匙串中但不信任该证书.所以需要去KeyChain Access手动信任证书.

It is able to successfully add the certificate in keychain but not trusting the certificate. So need to go to KeyChain Access and manually trust the certificate.

这篇关于如何以编程方式访问 windows 和 mac 可信证书存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆