Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert PublicKey to RSAPublicKey?

843811Apr 5 2007 — edited Apr 6 2007
Hello.

I have a RSAPublicKey's exponent and modulus stored into a database as strings. I collect them and then i'm reconstructing the public key.
                 
RawRSAKey rawKey = RawRSAKey.getInstance(rs.getString(1),rs.getString(2));
RSAPublicKeySpec publicSpec = new RSAPublicKeySpec(rawKey.getModulus(), rawKey.getExponent());

KeyFactory keyFactory = null;
      try {
    keyFactory = KeyFactory.getInstance("RSA");
    PublicKey PubKeyT = keyFactory.generatePublic(publicSpec);
As you can see, i now have my public key in the PubKeyT variable.

Then i have to take modulus and exponent again from the publickey i just reconstructed.

But:
BigInteger e = publicKeyT.getPublicExponent();
is not working because (i think) publicKeyT is a PublicKey and not a RSAPublicKey. Is there a way to convert PublicKey to RSAPublicKey or reconstruct my key directly to an RSAPublicKey.

Thank you in advantage.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 4 2007
Added on Apr 5 2007
4 comments
676 views