gpt4 book ai didi

java - 生成随机证书

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:03:25 35 4
gpt4 key购买 nike

我正在寻找可以生成随机证书字符串以用于测试目的的实用程序类。知道是否已经实现了一个吗?

最佳答案

添加到 martijno 给出的解决方案中,

无需编写您自己的内容签名器,JCAContentSigner 可用于避免映射到 AlgorithmIdentifier(即 OID)。

JcaContentSignerBuilder 采用定义的算法名称 here .

X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(issuer, serialNumber, startDate, expiryDate, subject, SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
JcaContentSignerBuilder builder = new JcaContentSignerBuilder("SHA256withRSA");
ContentSigner signer = builder.build(keyPair.getPrivate());

byte[] certBytes = certBuilder.build(signer).getEncoded();
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate)certificateFactory.generateCertificate(new ByteArrayInputStream(certBytes));

关于java - 生成随机证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9787467/

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