Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the code you've posted:</p> <pre><code>byte[] keyBytes = "vikoAmrPass12345".getBytes(); </code></pre> <p>That <em>could</em> be the problem. You should never use the platform default encoding if you're expecting to get the same result in multiple places. Always specify the encoding.</p> <p>If you've done this, it's <em>also</em> possible that you've got problems with how you're transporting the encrypted data. If you're ever creating a string from it, you should almost certainly use Base64, e.g. with <a href="http://iharder.net/base64" rel="nofollow">this library</a>. If you're using:</p> <pre><code>// Bad! Do not use! String encryptedText = new String(encryptedData); </code></pre> <p>Then that will basically be losing information, and could well be the cause of the problem.</p> <p>EDIT: Okay, so now we know your receiving code is:</p> <pre><code>ServerSocket ss = new ServetSocket(port); Socket socket = ss.accept(); InputStream in = socket.getInputStream(); byte [] sizeBuffer = new byte[5]; in.read(sizeBuffer); byte [] dataBuffer = new byte[Integer.valueOf(""+new String(sizeBuffer)]; in.read(dataBuffer); </code></pre> <p>Here you have at least three problems:</p> <ul> <li>Your code cannot possibly handle more than 99999 bytes, and it's not clear how you would expect it to handle less than 10000 bytes.</li> <li>You're assuming the default character encoding is consistent across platforms yet again</li> <li>Your code <em>assumes</em> that each time it calls <code>read</code>, that exact amount of information will be read. There's a good chance it won't, particularly for network streams. You should be using the return value of <code>read</code> to see how much has <em>actually</em> been read. You either need to loop round until you've read all the data required (or run out of data in the stream), or use a higher level API to do the same thing.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload