encryptBlock method

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

Encrypts one 16-byte block, writing into dst if given.

Implementation

@override
BuBytes encryptBlock(List<int> src, [List<int>? dst]) {
  final out = BuBytes.unsafeMutable(dst ?? List<int>.filled(blockSize, 0));
  if (src.length != blockSize) {
    throw CoreErrors.invalidOperationArguments(
      "encryptBlock",
      name: "src",
      reason: "Invalid source bytes length.",
    );
  }
  if (out.length != blockSize) {
    throw CoreErrors.invalidOperationArguments(
      "encryptBlock",
      name: "dst",
      reason: "Invalid destination bytes length.",
    );
  }
  final encKey = _encKey;
  if (encKey == null) {
    throw CoreErrors.cryptoFailed(
      "encryptBlock",
      reason: "Encryption key is not available.",
    );
  }
  _lib.encryptBlock(encKey, src.asBytes, out);

  return out;
}