In the new version of Bouncy Castle library there are changes in PKCS10CertificationRequest
. In previous versions it was possible to get PublicKey
from such request using getPublicKey()
method (see old doc).
Now this method disappered. How can I get PublicKey from with from such request?
There is getSubjectPublicKeyInfo().parsePublicKey()
but it returns ASN1Primitive
.
I see that from SPKAC NetscapeCertRequest
I still can read PublicKey directly by calling getPublicKey()
.
There is a utility class in the main provider package called PublicKeyFactory. The method createKey returns an AsymmetricKeyParameter which you cast to whatever type of public key is appropriate, e.g.
EDIT 1:
In addition, to create a
java.security.PublicKey
a few more steps are needed:RFC 2986 - PKCS #10: Certification Request Syntax
and then, you can see the document of java.security.spec.X509EncodedKeySpec
so you will know the encoding of this public key is X.509. and then change it to X509EncodedKeySpec and generate public key by keyFactory
What about using JcaPKCS10CertificationRequest?
I was looking at the same issue, and this will work too (with the advantage that we don't need to specify the algorithm):
See org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter