/** * Calculates the counter and iv, resets the cipher. * * @param position the given position in the data. * @throws IOException if an I/O error occurs. */ protected void resetCipher(long position) throws IOException { final long counter = getCounter(position); CtrCryptoInputStream.calculateIV(initIV, counter, iv); try { cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); } catch (InvalidKeyException e) { throw new IOException(e); } catch (InvalidAlgorithmParameterException e) { throw new IOException(e); } cipherReset = false; }