encryptBlock method
Encrypt block
Parameters:
src: The source block of plaintext to be encrypted, which must have a length of 16 bytes.dst: An optional destination block to store the encrypted ciphertext. If not provided, a new block is created.
Throws:
- ArgumentException if the source or destination block size is not 16 bytes.
- CryptoException if the encryption key is not available, indicating that the instance is not properly initialized.
Implementation
@override
List<int> encryptBlock(List<int> src, [List<int>? dst]) {
final out = dst ?? List<int>.filled(blockSize, 0);
if (src.length != blockSize) {
throw ArgumentException.invalidOperationArguments(
"encryptBlock",
name: "src",
reason: "Invalid source bytes length.",
);
}
if (out.length != blockSize) {
throw ArgumentException.invalidOperationArguments(
"encryptBlock",
name: "dst",
reason: "Invalid destination bytes length.",
);
}
if (_encKey == null) {
throw CryptoException.failed(
"encryptBlock",
reason: "Encryption key is not available.",
);
}
_lib.encryptBlock(_encKey!, src.asBytes, out);
return out;
}