encryptBlock method

  1. @override
List<int> encryptBlock(
  1. List<int> src, [
  2. List<int>? dst
])
override

This method takes a source block of plaintext, encrypts it using the encryption key schedule, and returns the resulting ciphertext. Optionally, you can provide a destination block (dst) to write the encrypted data into. If not provided, a new List

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.
  • StateError if the encryption key is not available, indicating that the instance is not properly initialized.

Returns:

  • The encrypted ciphertext block as a List

Implementation

@override
List<int> encryptBlock(List<int> src, [List<int>? dst]) {
  final out = dst ?? List<int>.filled(blockSize, 0);
  if (src.length != blockSize) {
    throw const ArgumentException("AES: invalid source block size");
  }
  if (out.length != blockSize) {
    throw const ArgumentException("AES: invalid destination block size");
  }

  if (_encKey == null) {
    throw const MessageException("AES: encryption key is not available");
  }
  _lib.encryptBlock(_encKey!, src, out);

  return out;
}