【问题标题】:How can I set the value of TBScertificate::signiture during I generate a X509cert with java?如何在使用 java 生成 X509 证书期间设置 TBScertificate::signature 的值?
【发布时间】:2022-01-05 12:40:10
【问题描述】:

我要生成一个证书并设置这个值:

TBSCertificate::=SEQUENCE{
version           [0]   EXPLICIT Version DEFAULT v1,
serialNumber            CertificateSerialNumber,
signature               AlgorithmIdentifier,***<---this one*** 
issuer                  Name,
validity                Validity,
subject                 Name,
subjectPublicKeyInfo    SubjectPublicKeyInfo,
issuerUniqueID    [1]   IMPLICIT UniqueIdentifier OPTIONAL,
subjectUniqueID   [2]   IMPLICIT UniqueIdentifier OPTIONAL,
extensions        [3]   EXPLICIT Extensions OPTIONAL
}

这是我的代码,目前我只能设置 SerialNumber,IssuerDN,NotBefore,NotAfter,SubjectDN,PublicKey,SignatureAlgorithm,:

public X509Certificate generateCert(String[] info, KeyPair keyPair_root,KeyPair keyPair_user) throws InvalidKeyException, NoSuchProviderException, SecurityException, SignatureException {
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    X509Certificate cert = null;
    certGen.setSerialNumber(new BigInteger(info[8]));
    certGen.setIssuerDN(new X509Name(
            "CN=huahua, OU=hnu, O=university , C=china"));
    certGen.setNotBefore(new Date(Long.parseLong(info[6])));
    certGen.setNotAfter(new Date(Long.parseLong(info[7])));
    certGen.setSubjectDN(new X509Name("C=" + info[0] + ",OU=" + info[1]
            + ",O=" + info[2] + ",C=" + info[3] + ",L=" + info[4] + ",ST="
            + info[3]));
    certGen.setPublicKey(keyPair_user.getPublic());
    certGen.setSignatureAlgorithm("SHA1WithRSA");
    cert = certGen.generateX509Certificate(keyPair_root.getPrivate(), "BC");
    return cert;
}

如果有人可以帮助我,我将不胜感激!我找到了很多解决方案,但没有一个可以帮助我。

【问题讨论】:

  • info[0]info[3] 用于C=(国家/地区)是没有意义的;我打赌第一个应该是CN= (CommonName)。

标签: java certificate x509certificate


【解决方案1】:

TBSCertificate.signature 名字不好,不是签名,只是签名算法标识符。

此值可能由您已在使用的certGen.setSignatureAlgorithm(...) 控制。

【讨论】:

  • 会在证书中显示吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-28
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多