java – 使用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);

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...