title: What kind of padding should AES use?
body: <p>I have implemented the AES encryption (homework), but I stumble upon the problem of padding the messages.</p>
  
  <p>If my messages are arrays of bytes as such:</p>
  
  <pre><code>public byte[] encrypt(byte[] message) {
      int size = (int) Math.ceil(message.length / 16.0);
      byte[] result = new byte[size * 16];
      for (int i = 0; i &lt; size; i++) {
          if ((i+1) * 16 &gt; message.length){
              //padding here????
          } else {
              byte[] block = Arrays.copyOfRange(message, i * 16, (i + 1) * 16);
              byte[] encryptedBlock = encryptBlock(block);                
              System.arraycopy(encryptedBlock, 0, result, i*16, 16);
          }
      }
      return result;
  }
  </code></pre>
  
  <p>How can I pad such a message?</p>
  
  <p>I cannot use Zero Padding because the each byte could be zero, and it might affect such a message with trailing zeros.</p>
  
  <p>I cannot find any reference to how is this done not even <a href="http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf" rel="noreferrer">here</a> (the paper describing the AES encryption)</p>