aesSetKeys method

void aesSetKeys(
  1. Uint8List key, [
  2. Uint8List? iv
])

Implementation

void aesSetKeys(Uint8List key, [Uint8List? iv]) {
  if (![16, 24, 32].contains(key.length)) {
    throw AesCryptArgumentError(
        'Invalid key length for AES. Provided ${key.length * 8} bits, expected 128, 192 or 256 bits.');
  } else if (_aesMode != AesMode.ecb && iv == null) {
    throw AesCryptArgumentError(
        'The initialization vector is not specified. It can not be empty when AES mode is not ECB.');
  } else if (iv?.length != 16) {
    throw AesCryptArgumentError(
        'Invalid IV length for AES. The initialization vector must be 128 bits long.');
  }

  _aesKey = Uint8List.fromList(key);
  _aesIV = iv == null ? Uint8List(0) : Uint8List.fromList(iv);

  _Nk = key.length ~/ 4;
  _Nr = _Nk + _Nb + 2;
  _w = Uint32List(_Nb * (_Nr + 1));

  _aesKeyExpansion(_aesKey); // places expanded key in w
}