title: File decryption: IllegalBlockSizeException: last block incomplete in decryption
body: <p>I know that similar questions have been asked, but I can't fix my problem with any of them.</p>
  
  <p>I have an encrypted file which has been created with the following Unix command:</p>
  
  <pre><code>tar cf FILES | gzip | openssl enc -k PASSWORD -aes-256-cbc -e &gt; OUTPUT.tar.gz.enc 
  </code></pre>
  
  <p>I can successfully decrypt the file with the associated command. </p>
  
  <p>I have to decrypt this file in a Java process. I used the code presented in <a href="https://stackoverflow.com/questions/11783062/how-to-decrypt-an-encrypted-file-in-java-with-openssl-with-aes">this SO answer</a>.</p>
  
  <p>I am using the same <a href="http://www.openssl.org/docs/crypto/EVP_BytesToKey.html" rel="nofollow noreferrer"><code>EVP_BytesToKey</code></a> function but s slightly different <code>main</code>  function.</p>
  
  <p>This is how I load the encrypted file: </p>
  
  <pre><code>byte[] headerSaltAndCipherText = IOUtils.toByteArray(new
  InputStreamReader(new FileInputStream(f)));
  </code></pre>
  
  <p>In the example code, it seems that the data is encoded in base64. However, when I read my file, it is not (I can see in clear the "Salted__" header)</p>
  
  <p>I created the <code>easCBC</code> object this way:</p>
  
  <pre><code>Cipher aesCBC = Cipher.getInstance("AES/CBC/PKCS5Padding", "BC");
  </code></pre>
  
  <p>And I added <code>Security.addProvider(new BouncyCastleProvider());</code> at the top of the <code>main</code> function. I started to use BouncyCastle as I was stuck but it didn't change a thing. </p>
  
  <p>I also tried with <code>PKCS7Padding</code> and <code>NoPadding</code> but no luck. </p>
  
  <p>The common issues that I found where about the wrong padding behing used or the encrypted data not being encoded/loaded properly. </p>
  
  <p>As I am not doing exactly as in the example, I guess that the answer is the second solution: I tried loading the file as in the example but I have this exception <code>java.nio.charset.MalformedInputException: Input length = 1</code> and anyway, I can't use features from the JDK 1.7.</p>
  
  <p>What am I doing wrong?</p>