init method

  1. @override
void init(
  1. bool encrypting,
  2. CipherParameters? params
)
override

Initialise the cipher and, possibly, the initialisation vector (IV). If an IV isn't passed as part of the parameter, the IV will be all zeros. An IV which is too short is handled in FIPS compliant fashion.

@param encrypting if true the cipher is initialised for encryption, if false for decryption. @param params the key and other data required by the cipher. @exception IllegalArgumentException if the params argument is inappropriate.

Implementation

@override
void init(bool encrypting, CipherParameters? params) {
  _encrypting = encrypting;

  if (params is ParametersWithIV) {
    var ivParam = params;
    var iv = ivParam.iv;

    if (iv.length < _iv.length) {
      // prepend the supplied IV with zeros (per FIPS PUB 81)
      var offset = _iv.length - iv.length;
      _iv.fillRange(0, offset, 0);
      _iv.setRange(offset, _iv.length, iv);
    } else {
      _iv.setRange(0, _iv.length, iv);
    }

    reset();

    // if null it's an IV changed only.
    if (ivParam.parameters != null) {
      _underlyingCipher.init(true, ivParam.parameters);
    }
  } else {
    reset();
    _underlyingCipher.init(true, params);
  }
}