title: Android - Removing padded bits in decryption
body: <p>I'm working on a security application using my own customized cryptography method, and having a problem on message decryption.</p>
  
  <p>According to the theory, the input has to be padded to meet the required bit to execute the encryption. But the padded bits stays even after the decryption.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>input (before padding) : q
  input (after padding)  : 113 0 0 0 0 0 0 0 (in Bytes)
  </code></pre>
  
  <p>Then I execute some code:</p>
  
  <pre><code>bytes[] a = encrypt(input);
  bytes[] b = decrypt(a);
  
  String output = "";
  output = new String(b, "UTF-8");
  </code></pre>
  
  <p>The output on System.out.println is below:</p>
  
  <pre><code>b      : 113 0 0 0 0 0 0 0
  output : q[][][][][][][]
  </code></pre>
  
  <p>I have no idea how to remove the padded bits. I'm currently using the function below:</p>
  
  <pre><code>public String processOutput(String dtxt){
      String result = "";
      int l = dtxt.length();
      for(int i=0;i&lt;l-16;i++) result = result + dtxt.charAt(i);
      for(int i=l-16;i&lt;l;i++){
          if((long)dtxt.charAt(i)!=0){
              result = result + dtxt.charAt(i);
          }
      } return result;
  }
  </code></pre>
  
  <p>But this function will only works if I put the output to a String. What if the output is a file (let's say an image file)? How to remove the padded bits after decryption? Please help.</p>