convert PEM Certificate or Java Certificate to ASN1 Certificate

1.6k Views Asked by At

I have a certificate in a PEM file.

I want to construct a CMPCertificate from this file. So I have to build an org.bouncycastle.asn1.x509.Certificate in order to call CMPCertificate.getInstance(..).

How could I convert a PEM file or a java.security.cert.Certificate to org.bouncycastle.asn1.x509.Certificate?

1

There are 1 best solutions below

0
On

After verifying the source code (since the documentation is missing on the subject) the getInstance method on CMPCertificate accepts byte[] type.

This code should work:

java.security.cert.X09Certificate cert = generateCertFromPEM(/*...*/);
byte[] encoding = cert.getEncoded();
CMPCertificate cmpCert = CMPCertificate.getInstance(encoding);