@Theory
  public void useHmacParametersAndHmacKey() throws Exception {
    HmacParameters parameters =
        HmacParameters.builder()
            .setKeySizeBytes(42)
            .setTagSizeBytes(13)
            .setHashType(HmacParameters.HashType.SHA1)
            .setVariant(HmacParameters.Variant.CRUNCHY)
            .build();
    KeysetHandle handle =
        KeysetHandle.newBuilder()
            .addEntry(
                KeysetHandle.generateEntryFromParameters(parameters).withFixedId(123).makePrimary())
            .build();

    HmacKey hmacKey = (HmacKey) handle.getAt(0).getKey();
    assertThat(hmacKey.getParameters()).isEqualTo(parameters);
    assertThat(hmacKey.getIdRequirementOrNull()).isEqualTo(123);
    SecretBytes secretBytes = hmacKey.getKeyBytes();
    assertThat(secretBytes.size()).isEqualTo(42);

    Mac mac = handle.getPrimitive(Mac.class);
    byte[] data = "data".getBytes(UTF_8);
    byte[] tag = mac.computeMac(data);
    mac.verifyMac(tag, data);
  }
Unit tests for the Mac package. Uses only the public API.
java_src/src/test/java/com/google/crypto/tink/mac/MacTest.java