The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
October 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

PublicKey refuses to regenerate.

Posted by Syed Miftahur rahman on October 07, 2001 at 6:42 PM

Hi,
Hope you don't mind this mail. I have an interesting problem which might interest you.

We know PublicKey can be encoded into byte-array by using "getEncoded()" method. In my case I found that array size required to store my encoded PublicKey is 444.
Using objectOutputStream's "writebyte(int)" I transferred the byte array to a file in my floppy drive.
I found that I could regenerate the PublicKey by reading back the encoded byte-array using ObjectInputStream's "readByte()" method and then using the following snippets.(where pub is the byte-array i.e
byte[] pub=new byte[444]; containing the encoded bytes)

X509EncodedKeySpec b = new X509EncodedKeySpec(pub);
KeyFactory kf = KeyFactory.getInstance("DSA");
PublicKey j = kf.generatePublic(b);

This has been performing nicely without any problems.
Now I have burned the 444 bytes into an EEPROM. Though the exact data bytes are read back by the program from the EEPROM, I get the following error message:-

java.security.spec.InvalidKeySpecException: Inappropriate key specification: IOE
xception: DerInputStream.getLength(): lengthTag=95, too big.
at sun.security.provider.DSAKeyFactory.engineGeneratePublic(DSAKeyFactor
y.java:74)
at java.security.KeyFactory.generatePublic(KeyFactory.java:184)
at Advanced_server_frm_eeprom.main(Compiled Code)

Can you give me any suggestions to overcome the problem. Since I have succeeded with Floppy I believe it is possible with EEPROm, just another memory element. It must be just a simple problem which I fail to see and may be, an expert will spot.

Thanking you.
With regards.
Syed Miftahur Rahman.(India).





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us