title: What does the return value of Cipher.dofinal(byte[]) mean in Java?
body: <p>I have a <code>Cipher aesEncryptCipher</code> in encrypt mode using AES/CBC/PKCS5Padding.</p>
  
  <p>Why do the following two functions return two different things? What does the return value of <code>encrypt2</code> mean? According to the <a href="http://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html#doFinal%28%29" rel="nofollow">javadoc</a>, it's supposed to return "the new buffer with the result", which I assumed to mean "the encrypted bytes". </p>
  
  <pre><code>public byte[] encrypt(byte[] rawBytes) {
     aesEncryptCipher.doFinal(rawBytes);
     return rawBytes;
  }
  
  public byte[] encrypt2(byte[] rawBytes) {
     return aesEncryptCipher.doFinal(rawBytes);
  }
  </code></pre>
  
  <p>Using some init vector and key, </p>
  
  <pre><code>encrypt("xxx".getBytes("UTF-8"));
  returns [120, 120, 120]
  
  encrypt2("xxx".getBytes("UTF-8"));
  returns [-76, 22, 46, 63, -16, -29, 56, -85, -115, -77, 11, 16, -56, 95, 20, 29]
  </code></pre>