### Question:
CbcEncryptor implements BytesEncryptor { @Override public byte[] encrypt(byte[] input, int outputOffset, byte[] flags) { try { return doEncrypt(input, outputOffset); } catch (Exception e) { throw new CayenneCryptoException("Error on encryption", e); } } CbcEncryptor(Cipher cipher, Key key, byte[] seedIv); @Override byte[] encrypt(byte[] input, int outputOffset, byte[] flags);  }### Answer:
@Test public void testEncrypt_AES() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { byte[] ivBytes = CryptoUnitUtils.hexToBytes("0591849d87c93414f4405d32f4d69220"); byte[] keyBytes = CryptoUnitUtils.hexToBytes("a4cb499fa31a6a228e16b7e4741d4fa3"); Key key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); assertEquals(16, cipher.getBlockSize()); byte[] plain = { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; CbcEncryptor encryptor = new CbcEncryptor(cipher, key, ivBytes); byte[] encrypted = encryptor.encrypt(plain, 0, new byte[1]); assertEquals(16 * 3, encrypted.length); assertArrayEquals(ivBytes, Arrays.copyOfRange(encrypted, 0, 16)); Cipher decCipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); decCipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(ivBytes)); byte[] newPlain = decCipher.doFinal(encrypted, 16, encrypted.length - 16); assertArrayEquals(plain, newPlain); }