setKey method
Re-keys this instance. key must be 16, 24, or 32 bytes, and the
same size this instance was created with.
Implementation
AES setKey(List<int> key, [bool noDecryption = false]) {
if (!allowedKeysLength.contains(key.length)) {
throw CoreErrors.invalidOperationArguments(
"setKey",
reason: "Invalid key bytes length.",
);
}
if (_keyLen != key.length) {
throw CoreErrors.invalidOperationArguments(
"setKey",
name: "key",
reason: "AES instance was initialized with a different key size.",
);
}
_encKey ??= List<int>.filled(key.length + 28, 0, growable: false);
if (noDecryption) {
BinaryOps.tryZero(_decKey);
_decKey = null;
} else {
BinaryOps.tryZero(_decKey);
_decKey ??= List<int>.filled(key.length + 28, 0, growable: false);
}
_lib.expandKey(key, _encKey!, _decKey);
return this;
}