decrypt method
Decrypt the given bytes.
inp
: the total encrypted bytesinpOff
: the byte offset to start decryption atinpLength
: the number of bytes (length) to decryptout
: the buffer to write the decrypted output inoutOff
: 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;
}