Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bouncycastle: X509CertificateHolder to X509Certificate?

In versions prior to r146 it was possible to create X509Certificate objects directly. Now that API is deprecated and the new one only deliveres a X509CertificateHolder object.

I cannot find a way to transform a X509CertificateHolder to X509Certificate.

How can this be done?

like image 674
Steffen Heil Avatar asked Jun 16 '11 10:06

Steffen Heil


2 Answers

I will answer to my own questions, but not delete it, in case someone else got the same problems:

return new JcaX509CertificateConverter().getCertificate(certificateHolder);

And for attribute certificates:

return new X509V2AttributeCertificate(attributeCertificateHolder.getEncoded());

Not nice, as it is encoding and decoding, but it works.

like image 86
Steffen Heil Avatar answered Sep 22 '22 09:09

Steffen Heil


Another option is this one :)

CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(certificateHolder.getEncoded());
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(in);
like image 39
Diego Palomar Avatar answered Sep 24 '22 09:09

Diego Palomar