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!

Create X.509 encoded key from raw SIM card generated key

843811Apr 17 2007 — edited Apr 20 2007
Hi,

I have a mobile phone with a SIM card that creates an RSA public key. The problem with the SIM card generated key is that it cannot directly be used to create a java.security.PublicKey compatible object using the following snippet:
  KeyFactory keyFactory = KeyFactory.getInstance("RSA");
  PublicKey publicKey =
    keyFactory.generatePublic(new X509EncodedKeySpec(keyBytes));
The KeyFactory.generatePublic() method will throw an exception as it appears to expect keyBytes on the following algorithm-independent format:

SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING
}

The algorithm part of the SubjectPublicKeyInfo is missing in the SIM card generated key. I only receive subjectPublicKey, the raw key bytes.

So my question is: Using the standard Java security API, is there a way to create a SubjectPublicKeyInfo-compliant key using my original SIM card generated key, and adding the algorithm stuff (whatever that will be).

I have found a workaround using the IAIK provider as follows:
  iaik.security.rsa.RSAPublicKey rsaPublicKey =
    iaik.security.rsa.RSAPublicKey.parse(keyBytes);
This object may then be cast to a java.security.PublicKey compatible object.

However, my project is not (officially) using the IAIK provider, so I would prefer to use the standard Java security API with the SunRsaSign or BC provider.

Thanks for any help!

Regards Dagbj�rn
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 18 2007
Added on Apr 17 2007
2 comments
274 views