Java 使用 BouncyCastle API 生成 CSR
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20532912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generating the CSR using BouncyCastle API
提问by Fox
I am new to the security side of Java and stumbled across this library called bouncycastle. But the examples that they provide and the ones out on internet ask to use --
我是 Java 安全方面的新手,偶然发现了这个名为 bouncycastle 的库。但是他们提供的示例以及互联网上的示例要求使用-
return new PKCS10CertificationRequest("SHA256withRSA", new X500Principal(
"CN=Requested Test Certificate"), pair.getPublic(), null, pair.getPrivate()
But when I use PKCS10CertificationRequest, it looks like it is deprecated. So I started looking at another method where I use CertificationRequest class. But I am really confused, the constructor does not take the same parameters instead it takes CertificationRequestInfo class which I am not sure how to fill up.
但是当我使用 PKCS10CertificationRequest 时,它似乎已被弃用。所以我开始研究另一种使用 CertificationRequest 类的方法。但我真的很困惑,构造函数不采用相同的参数,而是采用 CertificationRequestInfo 类,我不确定如何填写。
CertificationRequest request = new CertificationRequest(...);
It would be awesome if someone could help me figure out how to make a CSR so that I can send it to the server for getting it signed.
如果有人能帮我弄清楚如何制作 CSR 以便我可以将其发送到服务器进行签名,那就太棒了。
Thanks,
谢谢,
采纳答案by Jcs
With the recent versions of BouncyCastle it is recommended to create the CSR using the org.bouncycastle.pkcs.PKCS10CertificationRequestBuilder
class.
对于 BouncyCastle 的最新版本,建议使用org.bouncycastle.pkcs.PKCS10CertificationRequestBuilder
该类创建 CSR 。
You can use this code 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);