public static byte[] decrypt(byte[] key,byte[] data,Optional<byte[]> optional){
  try {
    ByteBuffer buffer=ByteBuffer.wrap(data);
    buffer.order(ByteOrder.BIG_ENDIAN);
    int version=Byte.toUnsignedInt(buffer.get());
    logger.debug("-- decrypt() - version: {}",version);
    buffer.rewind();
switch (version) {
case 0:
      return doDecrypt(buffer,key,1,8,8,optional);
case 1:
    return doDecrypt(buffer,key,1,12,12,optional);
case 2:
  return doDecrypt(buffer,key,3,12,12,optional);
case 3:
if (buffer.limit() < 4) {
  throw new IllegalArgumentException("cipher text too short for header");
}
int headerLength=4 + Byte.toUnsignedInt(buffer.get(3));
return doDecrypt(buffer,key,headerLength,12,12,optional);
default :
throw new IllegalArgumentException("unsupported version: " + version);
}
}
 catch (BufferUnderflowException ex) {
throw new IllegalArgumentException("decryption exception",ex);
}
}

public static byte [ ] decrypt ( byte [ ] key , byte [ ] data , Optional < byte [ ] > optional ) { try { ByteBuffer buffer = ByteBuffer . wrap ( data ) ; buffer . order ( ByteOrder . BIG_ENDIAN ) ; int version = Byte . toUnsignedInt ( buffer . get ( ) ) ; logger . debug ( "-- decrypt() - version: {}" , version ) ; buffer . rewind ( ) ; switch ( version ) { case 0 : return doDecrypt ( buffer , key , 1 , 8 , 8 , optional ) ; case 1 : return doDecrypt ( buffer , key , 1 , 12 , 12 , optional ) ; case 2 : return doDecrypt ( buffer , key , 3 , 12 , 12 , optional ) ; case 3 : if ( buffer . limit ( ) < 4 ) { throw new IllegalArgumentException ( "cipher text too short for header" ) ; } int headerLength = 4 + Byte . toUnsignedInt ( buffer . get ( 3 ) ) ; return doDecrypt ( buffer , key , headerLength , 12 , 12 , optional ) ; default : throw new IllegalArgumentException ( "unsupported version: " + version ) ; } } catch ( BufferUnderflowException ex ) { throw new IllegalArgumentException ( "decryption exception" , ex ) ; } }
returns the decrypted data .
