Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > RSA ciphered streams problem

Reply
Thread Tools

RSA ciphered streams problem

 
 
Jakub Stuglik
Guest
Posts: n/a
 
      12-13-2004
Hi. I've got a problem with the RSA ciphered streams. Here is a piece of
code that generates an exception :

KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
System.out.print("Generating the RSA key pair...");
KeyPair kp = gen.generateKeyPair();
System.out.println("done.");
Cipher ci = Cipher.getInstance("RSA");
ci.init(Cipher.ENCRYPT_MODE,kp.getPublic());
Cipher cid = Cipher.getInstance("RSA");
cid.init(Cipher.DECRYPT_MODE,kp.getPrivate());
CipherOutputStream cout = new CipherOutputStream(new
FileOutputStream("rsa.dat"),ci);
ObjectOutputStream oout = new ObjectOutputStream(cout);
oout.writeObject(kp.getPrivate().toString());
oout.flush();
oout.close();
CipherInputStream cin = new CipherInputStream(new
FileInputStream("rsa.dat"),cid);
ObjectInputStream oin = new ObjectInputStream(cin); // Exception here
System.out.println(oin.readObject());
oin.close();

The exception is EOFException and it's not very weird because the file
"rsa.dat" is empty after writing to it!! It happens only if object is "big"
( when I try to write some short String, for example, everything's ok ).
When I tried to write an unciphered output ( without using
CipheredOutputStream ) it went well of course.
My question is : can anybody tell me why it happens? What should I do to
write "big" objects to ciphered output stream using ObjectOutputStream
properly?
Thanks for any requests.

Kuba



 
Reply With Quote
 
 
 
 
klynn47@comcast.net
Guest
Posts: n/a
 
      12-13-2004
Have you tried printing the output to the screen to make sure that
something is being written? The only think I could think might be the
problem is that there wasn't enough time to write the whole object. You
might try two methods that use thread synchronization. That way, if the
write operation and read operation are synchronized, then the read
can't happen until the write is finished.

 
Reply With Quote
 
 
 
 
Jakub Stuglik
Guest
Posts: n/a
 
      12-13-2004
You're right - I tried to put it on the screen and "big" objects aren't
written to the stream - there's nothing on the screen after writing
operation ( I also commented code lines responsible for reading the object
to make sure there's enough time to write the whole object but it wouldn't
help ). Do you maybe have any idea how to deal with such a problem?
Thanks for any suggestions.

Kuba


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RSA Ace Server Authentication Problem RPO83 Cisco 13 01-08-2008 10:11 AM
Ciphered streams problem Jakub Stuglik Java 0 12-12-2004 01:06 PM
PLEASE HELP - Strange problem in RSA class Gandu Java 0 12-01-2004 08:35 PM
Implementing .net RSA on the server *and* JavaScript RSA on the client gg ASP .Net 0 11-18-2004 10:29 PM
Crypt RSA install (Problem with Crypt::Primes) AdrianK Perl 0 07-09-2003 09:32 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57