title: Change Cipher encryption/decryption mode while retaining IV
body: <p>When interacting with a DESfire EV1 tag, AES-CBC is used for securing communication. After encrypting and sending a message, the response needs to be decrypted using the IV that resulted from the encryption:</p>
  
  <pre><code>Cipher c = Cipher.getInstance("AES/CBC/NoPadding");
  c.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(zeroBytes));
  
  byte[] encrypted_response = transceive(c.doFinal(message));
  
  // TODO: cipher needs to be re-set to DECRYPT_MODE while retaining the IV
  c.init(Cipher.DECRYPT_MODE, ...?);
  
  byte[] response = c.doFinal(encrypted_response);
  </code></pre>
  
  <p>Unfortunately, Cipher.getIV() returns the initial IV (all zeroes), and there seems to be no way to get the IV short of implementing the whole CBC part manually. In <a href="https://stackoverflow.com/questions/7642871/get-updated-iv-from-cipher-after-encrypting-bytes">Get updated IV from Cipher after encrypting bytes</a> a similar question is asked, however only CTR-specific solutions are presented, which do not apply in CBC mode.</p>