decrypt method

  1. @override
Future<int> decrypt(
  1. Uint8List inp,
  2. int inpOff,
  3. int inpLength,
  4. Uint8List out,
  5. int outOff,
)
override

Decrypt the given bytes.

  • inp: the total encrypted bytes
  • inpOff: the byte offset to start decryption at
  • inpLength: the number of bytes (length) to decrypt
  • out: the buffer to write the decrypted output in
  • outOff: the byte offset to write the decrypted output to

returns the length of the new decrypted output

Implementation

@override
Future<int> decrypt(Uint8List inp, int inpOff, int inpLength, Uint8List out,
    int outOff) async {
  final bytes = inp.view(inpOff, inpLength);

  /// preparing the [SecretBox] with the range from the [inpOff] in the [inp]
  final secretBox =
      SecretBox.fromConcatenation(bytes, nonceLength: 16, macLength: 0);

  /// decrypting
  final result =
      await _algorithm.decrypt(secretBox, secretKey: await secretKey.future);

  /// save the clear text in the [out]
  out.setRange(outOff, outOff + result.length, result);

  /// return the clear text length as new offset
  return result.length;
}