Well you can certainly avoid the long-winded retreiveIvFromByteArray
code:
public static String decrypt(String hexEncoded) throws Exception {
byte[] decodedBytes = hexStringToBytes(hexEncoded);
int ivIndex = decodedBytes.length - 16;
cipher.init(Cipher.DECRYPT_MODE, encryptionKey,
new IvParameterSpec(decodedBytes, ivIndex, 16));
return reconstructedPlainText(cipher.doFinal(decodedBytes, 0, ivIndex));
}
Is that the sort of thing you were thinking of?
Likewise for the appendIvToEncryptedData
you could just create a new byte array of the appropriate length, and use System.arraycopy
twice.