Bouncycastle: X509CertificateHolder to X509Certificate?

Steffen Heil picture Steffen Heil · Jun 16, 2011 · Viewed 16.4k times · Source

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?

Answer

Steffen Heil picture Steffen Heil · Jan 22, 2012

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

return new JcaX509CertificateConverter().setProvider( "BC" )
  .getCertificate( certificateHolder );

And for attribute certificates:

return new X509V2AttributeCertificate( attributeCertificateHolder.getEncoded() );

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