@Test public void testDecrypt() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException { CbcDecryptor decryptor = new CbcDecryptor(cipher); byte[] plain = { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; byte[] ivBytes = CryptoUnitUtils.hexToBytes("0591849d87c93414f4405d32f4d69220"); Cipher encCipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); encCipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(ivBytes)); byte[] encrypted = encCipher.doFinal(plain); byte[] encryptedWithIv = new byte[encrypted.length + ivBytes.length]; System.arraycopy(ivBytes, 0, encryptedWithIv, 0, ivBytes.length); System.arraycopy(encrypted, 0, encryptedWithIv, ivBytes.length, encrypted.length); byte[] decrypted = decryptor.decrypt(encryptedWithIv, 0, key); assertArrayEquals(plain, decrypted); }
@Override public byte[] decrypt(byte[] input, int inputOffset, Key key) { try { return doDecrypt(input, inputOffset, key); } catch (Exception e) { throw new CayenneCryptoException("Error on decryption", e); } }
CbcDecryptor implements BytesDecryptor { @Override public byte[] decrypt(byte[] input, int inputOffset, Key key) { try { return doDecrypt(input, inputOffset, key); } catch (Exception e) { throw new CayenneCryptoException("Error on decryption", e); } } }
CbcDecryptor implements BytesDecryptor { @Override public byte[] decrypt(byte[] input, int inputOffset, Key key) { try { return doDecrypt(input, inputOffset, key); } catch (Exception e) { throw new CayenneCryptoException("Error on decryption", e); } } CbcDecryptor(Cipher cipher); }
CbcDecryptor implements BytesDecryptor { @Override public byte[] decrypt(byte[] input, int inputOffset, Key key) { try { return doDecrypt(input, inputOffset, key); } catch (Exception e) { throw new CayenneCryptoException("Error on decryption", e); } } CbcDecryptor(Cipher cipher); @Override byte[] decrypt(byte[] input, int inputOffset, Key key); }
CbcDecryptor implements BytesDecryptor { @Override public byte[] decrypt(byte[] input, int inputOffset, Key key) { try { return doDecrypt(input, inputOffset, key); } catch (Exception e) { throw new CayenneCryptoException("Error on decryption", e); } } CbcDecryptor(Cipher cipher); @Override byte[] decrypt(byte[] input, int inputOffset, Key key);  }