title: Removing characters from decrypted Base64 string in Java
body: <p>In relation to this question; <a href="https://stackoverflow.com/questions/29447412/java-android-decrypting-msg-with-iv-attached">Java (Android) Decrypting msg with IV attached</a></p>
  
  <p>My message decrypts fine but with the unwanted IV byte data.<br>
  I try to remove the attached IV, yet it does not delete all the characters and some character always remain behind. I'm not sure how I should be calculating the length of the encoded IV to remove the non-required characters.</p>
  
  <pre><code>public String decrypt(String cipherText, byte[] encryptionKey) throws Exception {
      SecretKeySpec key = new SecretKeySpec(encryptionKey, "AES");          
      cipher.init(Cipher.DECRYPT_MODE, key, iV);
      String decrypt = new String(cipher.doFinal( Base64.decode(cipherText, Base64.DEFAULT)));
  
      byte[] decryptData = new byte[decrypt.getBytes().length - iV.getIV().length];
      System.arraycopy(decrypt.getBytes(), iV.getIV().length, decryptData, 0, decrypt.getBytes().length - iV.getIV().length);
  
      Log.d("decrypt = ", decrypt);
  
      decrypt = new String(decryptData, "UTF-8");
  
      return decrypt;
  }   
  </code></pre>