Note that there are some explanatory texts on larger screens.

plurals
  1. PODES encryption plain vs. cipher length
    primarykey
    data
    text
    <p>I am using Java to make a toy program that encrypts a message using DES encryption. The message I want to encrypt is:</p> <pre><code>String msg="This is a secret message"; </code></pre> <p>Which I convert to bytes as:</p> <pre><code>byte [] msgBytes=msg.getBytes(); </code></pre> <p>And send it to encrypt function that works as follows:</p> <pre><code>//encryption function public static String encryptMsg(byte [] msgBytes, SecretKey myDesKey) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException { Cipher desCipher; // Create the cipher desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); desCipher.init(Cipher.ENCRYPT_MODE, myDesKey); byte[] textEncrypted = desCipher.doFinal(msgBytes); // converts to base64 for easier display. byte[] base64Cipher = Base64.encode(textEncrypted); return new String(base64Cipher); } //end encryptMsg </code></pre> <p>Then, I display the cipher, the cipher and plaintext lengths and I get:</p> <pre><code>Encrypted Message: FDCU+kgWz25urbQB5HbFtqm0HqWHGlGBHlwwEatFTiI= Original msg length: 24 Encrypted msg length: 44 </code></pre> <p>Can you please clarify to me why the cipher length is 44 while the original message length is 24?</p> <p><strong>EDIT:</strong> Kindly, I need the answer with clarification. The cipher always ends with =. Could this be because of the padding? Can you explain to me why/how the cipher is resulted with this length? And always ends with =? Is my code correct or there is a mistake? I have doubts in the encoding part.</p>
    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.
 

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