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!

Code Encrypts... but decryption throws a TON of errors...

843811Jan 30 2009 — edited Jan 31 2009
Hey everybody,

So i'm making nice progress on this big project I'm working on and i wanted to incorporate file-data security, so i read a little on the internet and employed some encryption. I had to, however, use this free Base64 Encoder/Decoder, to take the encrypted serialized and sealed object and turn it into a string which could then be stored in a text file. The encryption seems to work fine, (i dont get any errors and the files "look" encrypted) however when i went to load one of these encrypted files today for the part of my program that views them it went crazy on me.

Here's the errors:
============
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281)
at java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(ObjectInputStream.java:3019)
at java.io.ObjectInputStream$BlockDataInputStream.readUTF(ObjectInputStream.java:2820)
at java.io.ObjectInputStream.readUTF(ObjectInputStream.java:1051)
at java.io.ObjectStreamClass.readNonProxy(ObjectStreamClass.java:649)
at java.io.ObjectInputStream.readClassDescriptor(ObjectInputStream.java:809)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1565)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
at dbcsincmanager1.Base64.decodeToObject(Base64.java:1037)
at dbcsincmanager1.Crypto.deserializeAndDecrypt(Crypto.java:59)
at dbcsincmanager1.MainFrame.loadClientFile(MainFrame.java:537)
...It Goes On...

And here's the Bolded Method's Code (From the Free Base64 En/Decoder):
public static Object decodeToObject( String encodedObject )
    {
        // Decode and gunzip if necessary
        byte[] objBytes = decode( encodedObject );
        
        java.io.ByteArrayInputStream  bais = null;
        java.io.ObjectInputStream     ois  = null;
        Object obj = null;
        
        try
        {
            bais = new java.io.ByteArrayInputStream( objBytes );
            ois  = new java.io.ObjectInputStream( bais );
        
            obj = ois.readObject();
        }   // end try
        catch( java.io.IOException e )
        {
            e.printStackTrace();
            obj = null;
        }   // end catch
        catch( java.lang.ClassNotFoundException e )
        {
            e.printStackTrace();
            obj = null;
        }   // end catch
        finally
        {
            try{ bais.close(); } catch( Exception e ){}
            try{ ois.close();  } catch( Exception e ){}
        }   // end finally
        
        return obj;
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 28 2009
Added on Jan 30 2009
5 comments
326 views