Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:12:33+00:00 2026-06-03T01:12:33+00:00

i am writing an application where i transfer a byte array over a socket

  • 0

i am writing an application where i transfer a byte array over a socket in java.

The generation of byte array at the client end is as follows:

String vote = br.readLine();
// the data that i now encrypt using RSA

          PublicKey pubKey = readKeyFromFilepublic("alicepublic.txt");
          Cipher cvote = Cipher.getInstance("RSA");
          cvote.init(Cipher.ENCRYPT_MODE, pubKey);
          byte[] voted = cvote.doFinal(vote.getBytes());
          System.out.println(voted);
          out.println(voted.length);
          dos.write(voted,0,voted.length); // here i am sending the array to the server

on the server side i write

 String clen = in.readLine(); // read the length 
 byte[] array = new byte[Integer.parseInt(clen)]; // create the array of that length 
 dist.readFully(array); // read the array 

 // i am unable to read the array here at all !

 PrivateKey priKey = readKeyFromFileprivate("aliceprivate.txt");
 Cipher vote = Cipher.getInstance("RSA");
 vote.init(Cipher.DECRYPT_MODE, priKey);
 byte[] voteData = vote.doFinal(array);
 System.out.println(voteData);

// finally print the decrypted array

I have checked the encryption and decryption process by writing to a file it works properly.

i am using DataInput and DataOutput stream at both ends.

Can you please tell me what is wrong with my code !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:12:35+00:00Added an answer on June 3, 2026 at 1:12 am

    Don’t mix reading character data and binary data on the same stream (at least, not with different streams). you didn’t show the type of “in”, but i’m guessing it is a BufferedReader (the key point here being “buffered”). BufferedReader will read more than the next line, so part of your byte[] is sitting in your BufferedReader. use the same DataOutputStream/DataInputStream for all operations on the stream. if you need to write textual data, use writeUTF/readUTF. when you write the length of the byte[], just use writeInt/readInt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a client/server application in Java and I'm using TCP to transfer data
I'm developing a client and a server file transfer application with C++ sockets over
I'm writing a web application that talks over network socket to a server that
I am writing a data transfer application using a servlet and would like to
I'm writing a file transfer application in VC++(Server) using UDP. I came to know
im writing a file transfer application to send and receive a large data like
I'm writing a C# winforms application that will transfer files from an iPhone or
I'm wondering about writing an application in Java which can synchronize files across my
When writing application code, it's generally accepted that premature micro -optimization is evil, and
im writing an application that downloads and installs addons for programs which needs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.