简体   繁体   English

BouncyCastle - 从 X509Certificate object 创建商店

[英]BouncyCastle - Create a Store from X509Certificate object

Originally I hoped that the TimestampResponseGenerator would automatically include the public certificate in the response if the request had setCertReq(true) , but now my understanding is that I have to manually add them in the TimestampTokenGenerator using addCertificates(Store certStore) .最初我希望 TimestampResponseGenerator 如果请求具有setCertReq(true)会自动在响应中包含公共证书,但现在我的理解是我必须使用addCertificates(Store certStore)手动将它们添加到TimestampTokenGenerator中。 However, I can only seem to get the certificate into a standard Java certStore , not a BouncyCastle Store , and I can't find a way to convert or create the Store object from scratch.但是,我似乎只能将证书转换为标准 Java certStore ,而不是 BouncyCastle Store ,而且我找不到从头开始转换或创建 Store object 的方法。

What is the easiest way to create a BouncyCastle 1.62+ Store object with an X509Certificate object?使用 X509Certificate object 创建 BouncyCastle 1.62+ 商店object 的最简单方法是什么?

The answer (and bounty) depend on being able to add certificates to the timestamp token in the end.答案(和赏金)取决于最终能否将证书添加到时间戳令牌。 The Store part is where I'm stuck.商店部分是我卡住的地方。

The easiest way would probably be to use the JcaCertStore class.最简单的方法可能是使用JcaCertStore class。 This can easily be initialized with a certificate collection and then be passed to your TimestampTokenGenerator using addCertificates .这可以使用证书集合轻松初始化,然后使用addCertificates传递给您的TimestampTokenGenerator

In this example I did it through a method, since I don't have the exact context you want to place it in, but you can extract the two lines and place them wherever you want of course!在这个例子中,我通过一个方法完成了它,因为我没有你想要放置它的确切上下文,但是你可以提取这两行并将它们放在你想要的任何地方!

public void add(TimeStampTokenGenerator timeStampTokenGenerator, X509Certificate certificate) throws CertificateEncodingException {
    JcaCertStore store = new JcaCertStore(Collections.singleton(certificate));
    timeStampTokenGenerator.addCertificates(store);
}

Javadocs here Javadocs 在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM