Java – generate CSR using bouncycastle API

I was new to Java security and stumbled upon this library called bouncy castle But the examples they provide and the examples on the Internet require use –

return new PKCS10CertificationRequest("SHA256withRSA",new X500Principal(
    "CN=Requested Test Certificate"),pair.getPublic(),null,pair.getPrivate()

But when I use PKCs 10 certification request, it seems to have been deprecated So I started looking at another way to use the certificationrequest class But I'm really confused. The constructor does not take the same parameters, but needs the certificationrequestinfo class. I don't know how to fill in

CertificationRequest request = new CertificationRequest(...);

It would be great if someone could help me figure out how to make CSR so that I could send it to the server for signature

thank you,

Solution

Use the latest version of bouncycastle. Org is recommended bouncycastle. pkcs. Pkcs10certificationrequestbuilder class creates CSR

You can use this code snippet:

KeyPair pair = generateKeyPair();
PKCS10CertificationRequestBuilder p10Builder = new JcaPKCS10CertificationRequestBuilder(
    new X500Principal("CN=Requested Test Certificate"),pair.getPublic());
JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256withRSA");
ContentSigner signer = csBuilder.build(pair.getPrivate());
PKCS10CertificationRequest csr = p10Builder.build(signer);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>