Hmac constructor

Hmac(
  1. Hash hash,
  2. List<int> key
)

Create an Hmac object from a Hash and a binary key.

The key should be a secret shared between the sender and receiver of the message.

Implementation

Hmac(Hash hash, List<int> key)
    : _hash = hash,
      _key = Uint8List(hash.blockSize) {
  // Hash the key if it's longer than the block size of the hash.
  if (key.length > _hash.blockSize) key = _hash.convert(key).bytes;

  // If [key] is shorter than the block size, the rest of [_key] will be
  // 0-padded.
  _key.setRange(0, key.length, key);
}