RSAPublic key and RSAprivate key retrieval from key.DER files
Hi, i was using the crptix library ti extract the keys from .der files.however i now want to change the dependency to java and no third party library.
i used the sun.security.derinputstream and sun.security.deroutstream to get the values and retrieve the values
the follwing code retrieves the public keybyte[] decoded = (new sun.misc.BASE64Decoder()).decodeBuffer(stream);
DerInputStream der =new DerInputStream(decoded);
DerValue value = der.getDerValue();
byte[] inner = value.getDataBytes();
DerInputStream der1 =new DerInputStream(inner);
DerValue modulus = der1.getDerValue();
DerValue exponent = der1.getDerValue();
and a similar for private key .can any one suggest a better solution as the sun apis are not proprietary and can be deprecated
Any help is really appreciated
Thanks regards
Siva
[1047 byte] By [
sar_ana] at [2007-11-26 17:04:34]

# 1
I think using a third-party library is better than using the sun.* classes. As you noted, sun doesn't support these API's, doesn't document them, and actively discourages their use. WIth an open source third-party library like bouncycastle (www.bouncycastle.org), you can at least legally obtain the source code and make it your own. Then it's not really third party, is it? The bouncyastle license is very liberal, more so than the GPL.
Message was edited by:
ghstark
# 2
Hi,
Thanks for the reply.
I had used bouncy castle for retrieving the values they are pretty the same as cryptix.My main focus is on using Java alone and their published APis. I want to eliminate the dependency completely on the third party libraries.
Waiting for a breakthrough for this .
basically the DER encoded files are stored as tag-length-value.
The keys are usually in sequence(tag 00x30) and so on.
How can i retrieve the value based on the tags and length.Plus the length of length items is itself variable so its all a lot of hard work.
any help on this is appreciated and welcome with open arms
Cheers
Siva