encryptBlock method
List<int>
encryptBlock(
- List<
int> src, [ - List<
int> ? dst, - PaddingAlgorithm? paddingStyle = PaddingAlgorithm.pkcs7
override
Encrypts a single data block using the Electronic Codebook (ECB) mode.
Parameters:
src: The data block to be encrypted.dst: (Optional) The destination for the encrypted block. If not provided, a newList<int>is created.paddingStyle: (Optional) The padding style to be applied before encryption (default is PKCS#7).
Implementation
@override
List<int> encryptBlock(
List<int> src, [
List<int>? dst,
PaddingAlgorithm? paddingStyle = PaddingAlgorithm.pkcs7,
]) {
if (paddingStyle == null) {
if ((src.length % blockSize) != 0) {
throw ArgumentException.invalidOperationArguments(
"encryptBlock",
name: "src",
reason: "Invalid source bytes length.",
);
}
}
List<int> input = src.clone();
if (paddingStyle != null) {
input = BlockCipherPadding.pad(input, blockSize, style: paddingStyle);
}
final out = dst ?? List<int>.filled(input.length, 0);
if (out.length != input.length) {
throw ArgumentException.invalidOperationArguments(
"encryptBlock",
name: "out",
reason: "Incorrect destination length.",
);
}
final numBlocks = input.length ~/ blockSize;
for (var i = 0; i < numBlocks; i++) {
final start = i * blockSize;
final end = (i + 1) * blockSize;
final List<int> block = input.sublist(start, end);
final enc = super.encryptBlock(block);
out.setRange(start, end, enc);
}
return out;
}