processBlock method

  1. @override
int processBlock(
  1. Uint8List inp,
  2. int inpOff,
  3. Uint8List out,
  4. int outOff,
)
override

Process a whole block of data given by inp and starting at offset inpOff.

The resulting cipher text is put in out beginning at position outOff.

This method returns the total bytes processed (which is the same as the block size of the algorithm).

Implementation

@override
int processBlock(Uint8List inp, int inpOff, Uint8List out, int outOff) {
  if (workingKey1 == null || workingKey2 == null || workingKey3 == null) {
    throw ArgumentError('DESede engine not initialised');
  }

  if ((inpOff + BLOCK_SIZE) > inp.length) {
    throw ArgumentError('input buffer too short');
  }

  if ((outOff + BLOCK_SIZE) > out.length) {
    throw ArgumentError('output buffer too short');
  }

  var temp = Uint8List(BLOCK_SIZE);

  if (forEncryption) {
    desFunc(workingKey1!, inp, inpOff, temp, 0);
    desFunc(workingKey2!, temp, 0, temp, 0);
    desFunc(workingKey3!, temp, 0, out, outOff);
  } else {
    desFunc(workingKey3!, inp, inpOff, temp, 0);
    desFunc(workingKey2!, temp, 0, temp, 0);
    desFunc(workingKey1!, temp, 0, out, outOff);
  }

  return BLOCK_SIZE;
}