Java AES Decryption: random chars & message at the end
<p>I have a problem with decrypting a message using AES. At the end when I expect a message, e.g. </p>

<pre><code>ala123
</code></pre>

<p>Instead of that I receive sth like:</p>

<pre><code>...6�b}\7�k�8�vFP�8~%��_zժF��FW��O_e���ó������������ala123
</code></pre>

<p>The message I pass to encryption is built as:</p>

<ul>
<li>cipher key is SHA-256 from AES_TOKEN</li>
<li>cipher IV is some characters, which are then stored in the message (at the beginnig)</li>
<li>decrypted message is wrapped up into Base64</li>
</ul>

<p>The question is why at the end I eventually receive my expected message, but with a lot of rubbish chars at the beggining?</p>

<p>My encryption code is:</p>

<pre><code>private static final String AES_TOKEN = "my_very_secret_token";

// encrypted is base64 string
public String decrypt(String encrypted) throws Exception {
    byte[] decrypted = Base64.getDecoder().decode(encrypted);
    return new String(aesDecrypt(decrypted), "UTF-8");
}

private byte[] aesDecrypt(byte[] message) throws Exception {
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

    byte[] token = MessageDigest.getInstance("SHA-256").digest(AES_TOKEN.getBytes());
    SecretKeySpec secretKey = new SecretKeySpec(token, "AES");

    IvParameterSpec iv = new IvParameterSpec(Arrays.copyOf(message, 16));

    cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
    return cipher.doFinal(message);
}
</code></pre>