setCipher method

CTR setCipher(
  1. BlockCipher cipher,
  2. List<int>? iv
)

Sets the block cipher and initialization vector (IV) for the Counter (CTR) mode.

Parameters:

  • cipher: The block cipher to be used for encryption.
  • iv: The initialization vector (IV) for the CTR mode.

Throws:

Implementation

CTR setCipher(BlockCipher cipher, List<int>? iv) {
  _cipher = null;

  if (iv != null && iv.length != _counter.length) {
    throw ArgumentException.invalidOperationArguments(
      "setCipher",
      name: "iv",
      reason: "Invalid iv bytes length.",
      expecteLen: _counter.length,
    );
  }
  _cipher = cipher;

  if (iv != null) {
    _counter.setAll(0, iv);
  }
  _bufpos = _buffer.length;
  return this;
}