使用BouncyCastle API生成CSR

我是Java的安全方面的新手,偶然发现了这个名为bouncycastle的库。 但他们提供的例子和互联网上的例子要求使用 –

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

但是当我使用PKCS10CertificationRequest时,看起来它已被弃用。 所以我开始研究另一种使用CertificationRequest类的方法。 但我真的很困惑,构造函数不采用相同的参数,而是需要CertificationRequestInfo类,我不知道如何填写。

  CertificationRequest request = new CertificationRequest(...); 

如果有人可以帮我弄清楚如何制作CSR以便我可以将其发送到服务器以获得签名,那将是非常棒的。

谢谢,

使用最新版本的BouncyCastle,建议使用org.bouncycastle.pkcs.PKCS10CertificationRequestBuilder类创建CSR。

您可以使用此代码snipppet:

 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);