在 Java 中以编程方式设置主题备用名称
问题描述:
我正在使用类似于此代码的东西.如何使用 sun.security
以编程方式在我的证书中添加设置 主题备用名称?
I am using something similar to this code. How can I add set the Subject Alternative Names in my certificate programmatically using sun.security
?
答
好吧,追踪多个来源有点棘手,但这里是线索(以防将来它可以帮助任何人,因为我在其他时候得到了帮助):
OK, it was a bit tricky to trace several sources but here it is the clue (in case it can help anyone in future as I have been helped other times):
CertificateExtensions ext = new CertificateExtensions();
ext.set(SubjectAlternativeNameExtension.NAME, new SubjectAlternativeNameExtension(....*));
// * a `GeneralNames` object including a `GeneralName` object including (for example) an `IPAddressName` object.
然后将对象ext
传递给证书的构造函数.
And then pass the object ext
to the constructor of the certificate.