如何在java中导入证书?

发布于 2024-12-02 02:35:11 字数 432 浏览 2 评论 0原文

我获得了证书 .cer,我想要一个脚本将其导入到证书的受信任发布者列表中。

我设法在 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 中做到同样的事情?

多谢。

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.

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

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

发布评论

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

评论(3

疯到世界奔溃 2024-12-09 02:35:11

您可以在 Java 中执行相同的操作。查看 MSCAPI 提供程序。

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

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

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...
平定天下 2024-12-09 02:35:11

java处理证书的方式与Windows处理证书的方式有很大不同。 Windows 为机器帐户、用户帐户和服务帐户的证书提供了预定义的存储,并根据其用途区分证书(例如个人与受信任的 CA)。Java

简单地提供了密钥库的概念 - 您选择的任意文件,证书所在的位置存储。 JDK 有一个用于受信任 CA 的默认密钥库,位于$JAVA_HOME/jre/lib/security/cacerts

要将证书导入密钥库,您可以使用 JDK 附带的密钥工具 - 使用哪个密钥库取决于您的应用程序。

请参见

The way java handles certificates is very different to how Windows handles certificates. Windows provides predefined stores for certificates for the machine account, user accounts and service accounts, and distinguishes certificates based on their purpose (e.g. personal vs trussted CA.)

Java simply provides the concept of the Keystore - an arbitrary file of your choosing where certificates are stored. There is a default keystore used by the JDK for trusted CAs, located at$JAVA_HOME/jre/lib/security/cacerts.

To import the certificate into a keystore, you can use the keytool that is shipped with the JDK - which keystore you use depends upon your application.

See

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