decrypt method

Uint8List decrypt(
  1. BlockCipher cipher,
  2. dynamic input, {
  3. required Uint8List iv,
  4. Padder? padder,
})

Implementation

Uint8List decrypt(BlockCipher cipher, /* String | Uint8List */ input,
    {required Uint8List iv, Padder? padder}) {
  Uint8List inp;
  if (input is String) {
    inp = base64Decode(input);
  } else {
    inp = input;
  }

  final state = CTRState(cipher, iv);
  var out = Uint8List(inp.length);

  for (int i = 0; i < inp.length; i++) {
    final ebyte = state.nextByte;
    out[i] = inp[i] ^ ebyte;
    // Debug print('Decrypt: inp: ${inp[i]}, ebyte: ${ebyte}, out: ${out[i]}');
  }

  if (padder != null) {
    out = Uint8List.fromList(padder.unpad(cipher.blockSize, out).toList());
  }

  return out;
}