如何在java中导入证书?
我获得了证书 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在 Java 中执行相同的操作。查看 MSCAPI 提供程序。
You can do the equivalent in Java. Check out the MSCAPI provider.
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
使用 keytool,如 Java 教程解释得很好。
Using the keytool, like the Java tutorial explains so well.