decrypt method

  1. @override
Future<List<int>> decrypt(
  1. SecretBox secretBox, {
  2. required SecretKey secretKey,
  3. List<int> aad = const <int>[],
  4. int keyStreamIndex = 0,
  5. int? chunkSize,
  6. Uint8List? possibleBuffer,
})
override

Decrypts a ciphertext.

Parameter keyStreamIndex allows you to choose offset in the keystream.

For other arguments, see Cipher.decrypt.

Implementation

@override
Future<List<int>> decrypt(
  SecretBox secretBox, {
  required SecretKey secretKey,
  List<int> aad = const <int>[],
  int keyStreamIndex = 0,
  int? chunkSize,
  Uint8List? possibleBuffer,
}) async {
  checkParameters(
    length: secretBox.cipherText.length,
    secretKey: secretKey,
    nonceLength: secretBox.nonce.length,
    aadLength: aad.length,
    keyStreamIndex: keyStreamIndex,
  );
  final state = newState();
  await state.initialize(
    isEncrypting: false,
    secretKey: secretKey,
    nonce: secretBox.nonce,
    aad: aad,
    keyStreamIndex: keyStreamIndex,
  );
  final clearText = await state.convert(
    secretBox.cipherText,
    expectedMac: secretBox.mac,
    possibleBuffer: possibleBuffer,
    chunkSize: chunkSize,
  );
  if (secretBox.mac != state.mac) {
    throw SecretBoxAuthenticationError();
  }
  return clearText;
}