Jury A
Jury A

Reputation: 20062

How to print a certificate's public key length and modulus separately in Java

I found a method called getPublicKey() under the java.security.cert.Certificate class, but this methods returns the length, modulus all in one value as a PublicKey object. Is there any way to get this information separately ??

Upvotes: 0

Views: 2814

Answers (2)

Robert
Robert

Reputation: 42595

In case you are dealing with an RSA based public key the PublicKey object you receive is a RSAPublicKey instance.

Therefore you can cast it to RSAPublicKey and then use it's methods getPublicExponent() and getModulus().

Upvotes: 2

Alex W
Alex W

Reputation: 38193

If you look here (http://docs.oracle.com/javase/1.5.0/docs/api/java/security/cert/package-tree.html) for the documentation for the java.security.cert.* package, you should find the type of objects you are instantiating. If you follow the link to the object you will find all of its available methods. There may be separate methods that return those values, but you'll have to check.

Upvotes: 0

Related Questions