Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The encryption / decryption process is largely irrelevant. After all, what comes in should be the same as what comes out. The question is what do the bytes representing the String object look like when written to a file.</p> <p>A quick test confirms that when java writes a string to a stream neither the string nor the stream are null terminated. Consider the following code:</p> <pre><code>import java.io.FileWriter; import java.io.IOException; public SimpleStringIoTest { public static void main (String[] args) throws IOException { String message = "Raw Java String"; FileWriter fileWriter = new FileWriter("javaoutput.bin"); fileWriter.write(message); fileWriter.close(); } } </code></pre> <p>Doing a hexdump of the file that it produces the following.</p> <pre><code>00000000 52 61 77 20 41 61 76 61 20 53 74 72 69 6e 67 Raw Java String </code></pre> <p>Therefore, when you encrypt that you end up with an 15 bytes of encrypted string and blocksize - 15 bytes of encrypted padding. When you decrypt this you get not only the string but also the plain-text padding, and unless you know the length of the plain-text or have an embeded plain-text terminator there is no way to know where the plain-text ends.</p> <p>Using NUL ('\0') as the terminator makes sense, because this is also the terminator that C uses to mark the end of string. The ony possible problem is if NUL can somehow occur in your string already. Given that this would probably cause other issues with C/C++ programs I kind of doubt that, but you could always escape it away if it was a problem.</p> <p>Oh, and I checked changing <code>messages</code> as follows:</p> <pre><code>String message = "Raw Java String\0"; </code></pre> <p>Gives a hex dump of</p> <pre><code>00000000 52 61 77 20 41 61 76 61 20 53 74 72 69 6e 67 00 Raw Java String </code></pre>
    singulars
    1. This table or related slice is empty.
    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