java 导入 证书,如何在java中导入证书?

这篇博客介绍了如何使用Java实现类似C#中将.cer证书导入到受信任发布者列表的操作。通过使用Java的KeyStore类和Windows-ROOT密钥存储,可以实现证书的添加和存储。请注意在运行相关代码时需要相应的权限。
摘要由CSDN通过智能技术生成

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

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();

Is there a way to do the same in Java?

Thanks a lot.

解决方案

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

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...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值