如何在java中导入证书? [英] How to import a certificate in java?

查看:695
本文介绍了如何在java中导入证书?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个证书.cer,我想要一个脚本将它导入证书的Trusted Publisher列表。

I got a certificate .cer and I'd like a script to import it in the Trusted Publisher list of certificate.

我设法在C#中做了这件事

I managed to do this thing in C#

X509Certificate2 certificate = new X509Certificate2(filePath.Text, "Telecomitalia1?12524", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
X509Store store = new X509Store(StoreName.TrustedPublisher);
store.Open(OpenFlags.ReadWrite);
store.Add(certificate);
store.Close();

有没有办法在Java中做同样的事情?

Is there a way to do the same in Java?

非常感谢。

推荐答案

你可以用Java做同等的事情。查看 MSCAPI 提供商。

You can do the equivalent in Java. Check out the MSCAPI provider.


提供对MS Window密钥库的直接读写访问。 Windows-MY密钥库包含用户的私钥和关联的证书链。 Windows-ROOT密钥库包含计算机信任的所有根CA证书。

Provides direct read-write access to MS Window's keystores. The Windows-MY keystore contains the user's private keys and the associated certificate chains. The Windows-ROOT keystore contains all root CA certificates trusted by the machine.



KeyStore ks = KeyStore.getInstance("Windows-ROOT");
// Note: When a security manager is installed, 
// the following call requires SecurityPermission 
// "authProvider.SunMSCAPI".
ks.load(null, null);
ks.setCertificateEntry("alias", cert);
ks.store(null, null); //again the permissions here...

这篇关于如何在java中导入证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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