decryptSync method

List<int> decryptSync(
  1. SecretBox secretBox, {
  2. required SecretKeyData secretKey,
  3. List<int> aad = const <int>[],
  4. int keyStreamIndex = 0,
  5. Uint8List? possibleBuffer,
})

Implementation

List<int> decryptSync(
  SecretBox secretBox, {
  required SecretKeyData secretKey,
  List<int> aad = const <int>[],
  int keyStreamIndex = 0,
  Uint8List? possibleBuffer,
}) {
  checkParameters(
    length: secretBox.cipherText.length,
    secretKey: secretKey,
    nonceLength: secretBox.nonce.length,
    aadLength: aad.length,
    keyStreamIndex: keyStreamIndex,
  );
  final state = newState();
  state.initializeSync(
    isEncrypting: false,
    secretKey: secretKey,
    nonce: secretBox.nonce,
    aad: aad,
    keyStreamIndex: keyStreamIndex,
  );
  final clearText = state.convertSync(
    secretBox.cipherText,
    possibleBuffer: possibleBuffer,
  );
  if (secretBox.mac != state.mac) {
    throw SecretBoxAuthenticationError();
  }
  return clearText;
}