Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are several things going on:</p> <ol> <li><p><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes()" rel="nofollow noreferrer"><code>msg.getBytes()</code></a> returns the bytes representing an encoding of the string using the "platform's default charset" (e.g. could be UTF-8 <em>or</em> UTF-16 <em>or</em> ..): <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#getBytes(java.nio.charset.Charset)" rel="nofollow noreferrer">specify the encoding manually</a> to avoid confusion! In any case, see <code>msgBytes.length</code> to get the <em>true</em> plain text length.</p></li> <li><p><a href="http://en.wikipedia.org/wiki/DES" rel="nofollow noreferrer">DES</a>, being a block cypher, will have output padded along a <a href="http://en.wikipedia.org/wiki/Block_size_(cryptography)" rel="nofollow noreferrer">block size</a> boundary - <em>but</em> this will <em>always</em> be larger than the plain text (refer to <code>msgBytes.length</code>) length when using <a href="http://www.ietf.org/rfc/rfc2898.txt" rel="nofollow noreferrer">PKCS#5</a> because the plain text is always padded with [1,8] bytes. To see what the <em>true</em> encrypted size is, see <code>textEncrypted.length</code>.</p></li> <li><p>The encrypted bytes are encoded using base-64 and this process - which is independent of the encryption - inflates the number of bytes required <a href="https://stackoverflow.com/questions/4715415/base64-what-is-the-worst-possible-increase-in-space-usage">by about 33%</a> (as only 6 bits per character/byte are used). The Java base-64 implementation also <a href="http://en.wikipedia.org/wiki/Base64#Padding" rel="nofollow noreferrer">adds padding</a> which is where the trailing "=" character is introduced.</p></li> </ol> <p>As long as you (or someone else with the correct algorithm and cipher key) can retrieve the initial string - by performing the inverse of each step in reverse order, then it works. If a particular step does not have an inverse/reverse operation or cannot be "undone", then something is wrong; but this also means that <em>every step can be individually tested</em>.</p> <hr> <p>To the numbers!</p> <ol> <li><code>msg.getBytes()</code> returns an ASCII/UTF-8 encoded sequence (if it used UTF-16 or another another "wide" encoding then the numbers below would be too large)</li> <li>Therefore, <code>msgBytes.length</code> is 24</li> <li>And since <code>msgBytes.length</code> mod 8 is 0, the plain text is <em>padded</em> with 8 bytes that have the value of 0x08 (per CKCS#5)</li> <li>Thus, <code>textEncrypted.length</code> is 32 (24 data + 8 padding)</li> <li>Due to base-64 encoding, 32 bytes * 1.33 ~ 43 characters</li> <li>And with base-64 padding (<code>=</code>), the final result is 44 characters!</li> </ol>
 

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