gpt4 book ai didi

java - 如何在 Java 中生成多域 (UCC) 证书?

转载 作者:搜寻专家 更新时间:2023-10-31 20:06:01 28 4
gpt4 key购买 nike

目前我正在使用 BouncyCastle库生成证书。像这样:

X509V3CertificateGenerator certGenerator = new X509V3CertificateGenerator();
certGenerator.setIssuerDN( rootCertificate.getSubjectX500Principal() );
certGenerator.setSignatureAlgorithm( "SHA1withRSA" );
certGenerator.setSerialNumber( serial );
certGenerator.setNotBefore( notBefore );
certGenerator.setNotAfter( notAfter );
certGenerator.setPublicKey( rootCertificate.getPublicKey() );

Hashtable<DERObjectIdentifier, String> attrs = new Hashtable<DERObjectIdentifier, String>();
Vector<DERObjectIdentifier> order = new Vector<DERObjectIdentifier>();

attrs.put( X509Principal.C, "RU" );
// other attrs.put() calls here

order.addElement( X509Principal.C );
// other order.addElement() calls here

certGenerator.setSubjectDN( new X509Principal( order, attrs ) );
certGenerator.addExtension( X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure( rootCertificate ) );
certGenerator.addExtension( X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure( newKeyPair.getPublic() ) );

return certGenerator.generate( rootPrivateKey, "BC" );

我可以在生成的证书中添加 SubjectAltNames 字段吗?

最佳答案

要完成任务,请在 certGenerator.generate() 调用之前插入以下内容:

ASN1EncodableVector alternativeNames = new ASN1EncodableVector();
for( String domainName : domainNames )
{
alternativeNames.add( new GeneralName( GeneralName.dNSName, domainName ) );
}
certGenerator.addExtension( X509Extensions.SubjectAlternativeName, false, new GeneralNames( new DERSequence( alternativeNames ) ) );

(双V提供答案)

关于java - 如何在 Java 中生成多域 (UCC) 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6911719/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com