setCipher method
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:
- ArgumentException if the IV length is not equal to the block size of the cipher.
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;
}